Make OAuth2User extends OAuth2AuthenticatedPrincipal
Fixes gh-7378
This commit is contained in:
parent
aa533c2565
commit
91bf1c782a
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -48,6 +48,7 @@ import static org.springframework.security.oauth2.core.TestOAuth2AccessTokens.no
|
|||
* Tests for {@link CustomUserTypesOAuth2UserService}.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
public class CustomUserTypesOAuth2UserServiceTests {
|
||||
private ClientRegistration.Builder clientRegistrationBuilder;
|
||||
|
@ -134,10 +135,10 @@ public class CustomUserTypesOAuth2UserServiceTests {
|
|||
|
||||
assertThat(user.getName()).isEqualTo("first last");
|
||||
assertThat(user.getAttributes().size()).isEqualTo(4);
|
||||
assertThat(user.getAttributes().get("id")).isEqualTo("12345");
|
||||
assertThat(user.getAttributes().get("name")).isEqualTo("first last");
|
||||
assertThat(user.getAttributes().get("login")).isEqualTo("user1");
|
||||
assertThat(user.getAttributes().get("email")).isEqualTo("user1@example.com");
|
||||
assertThat((String) user.getAttribute("id")).isEqualTo("12345");
|
||||
assertThat((String) user.getAttribute("name")).isEqualTo("first last");
|
||||
assertThat((String) user.getAttribute("login")).isEqualTo("user1");
|
||||
assertThat((String) user.getAttribute("email")).isEqualTo("user1@example.com");
|
||||
|
||||
assertThat(user.getAuthorities().size()).isEqualTo(1);
|
||||
assertThat(user.getAuthorities().iterator().next().getAuthority()).isEqualTo("ROLE_USER");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -61,6 +61,7 @@ import static org.springframework.security.oauth2.core.TestOAuth2AccessTokens.sc
|
|||
* Tests for {@link DefaultOAuth2UserService}.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
public class DefaultOAuth2UserServiceTests {
|
||||
private ClientRegistration.Builder clientRegistrationBuilder;
|
||||
|
@ -146,12 +147,12 @@ public class DefaultOAuth2UserServiceTests {
|
|||
|
||||
assertThat(user.getName()).isEqualTo("user1");
|
||||
assertThat(user.getAttributes().size()).isEqualTo(6);
|
||||
assertThat(user.getAttributes().get("user-name")).isEqualTo("user1");
|
||||
assertThat(user.getAttributes().get("first-name")).isEqualTo("first");
|
||||
assertThat(user.getAttributes().get("last-name")).isEqualTo("last");
|
||||
assertThat(user.getAttributes().get("middle-name")).isEqualTo("middle");
|
||||
assertThat(user.getAttributes().get("address")).isEqualTo("address");
|
||||
assertThat(user.getAttributes().get("email")).isEqualTo("user1@example.com");
|
||||
assertThat((String) user.getAttribute("user-name")).isEqualTo("user1");
|
||||
assertThat((String) user.getAttribute("first-name")).isEqualTo("first");
|
||||
assertThat((String) user.getAttribute("last-name")).isEqualTo("last");
|
||||
assertThat((String) user.getAttribute("middle-name")).isEqualTo("middle");
|
||||
assertThat((String) user.getAttribute("address")).isEqualTo("address");
|
||||
assertThat((String) user.getAttribute("email")).isEqualTo("user1@example.com");
|
||||
|
||||
assertThat(user.getAuthorities().size()).isEqualTo(1);
|
||||
assertThat(user.getAuthorities().iterator().next()).isInstanceOf(OAuth2UserAuthority.class);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -61,6 +61,7 @@ import static org.springframework.security.oauth2.core.TestOAuth2AccessTokens.sc
|
|||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author Eddú Meléndez
|
||||
* @since 5.1
|
||||
*/
|
||||
public class DefaultReactiveOAuth2UserServiceTests {
|
||||
|
@ -137,12 +138,12 @@ public class DefaultReactiveOAuth2UserServiceTests {
|
|||
|
||||
assertThat(user.getName()).isEqualTo("user1");
|
||||
assertThat(user.getAttributes().size()).isEqualTo(6);
|
||||
assertThat(user.getAttributes().get("id")).isEqualTo("user1");
|
||||
assertThat(user.getAttributes().get("first-name")).isEqualTo("first");
|
||||
assertThat(user.getAttributes().get("last-name")).isEqualTo("last");
|
||||
assertThat(user.getAttributes().get("middle-name")).isEqualTo("middle");
|
||||
assertThat(user.getAttributes().get("address")).isEqualTo("address");
|
||||
assertThat(user.getAttributes().get("email")).isEqualTo("user1@example.com");
|
||||
assertThat((String) user.getAttribute("id")).isEqualTo("user1");
|
||||
assertThat((String) user.getAttribute("first-name")).isEqualTo("first");
|
||||
assertThat((String) user.getAttribute("last-name")).isEqualTo("last");
|
||||
assertThat((String) user.getAttribute("middle-name")).isEqualTo("middle");
|
||||
assertThat((String) user.getAttribute("address")).isEqualTo("address");
|
||||
assertThat((String) user.getAttribute("email")).isEqualTo("user1@example.com");
|
||||
|
||||
assertThat(user.getAuthorities().size()).isEqualTo(1);
|
||||
assertThat(user.getAuthorities().iterator().next()).isInstanceOf(OAuth2UserAuthority.class);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -42,6 +42,7 @@ import java.util.LinkedHashSet;
|
|||
* and returning it from {@link #getName()}.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @author Eddú Meléndez
|
||||
* @see OAuth2User
|
||||
* @since 5.0
|
||||
*/
|
||||
|
@ -72,7 +73,7 @@ public class DefaultOAuth2User implements OAuth2User, Serializable {
|
|||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getAttributes().get(this.nameAttributeKey).toString();
|
||||
return this.getAttribute(this.nameAttributeKey).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -15,12 +15,8 @@
|
|||
*/
|
||||
package org.springframework.security.oauth2.core.user;
|
||||
|
||||
import org.springframework.security.core.AuthenticatedPrincipal;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
|
||||
|
||||
/**
|
||||
* A representation of a user {@code Principal}
|
||||
|
@ -37,29 +33,16 @@ import java.util.Map;
|
|||
* Please consult the provider's API documentation for the set of supported user attribute names.
|
||||
*
|
||||
* <p>
|
||||
* Implementation instances of this interface represent an {@link AuthenticatedPrincipal}
|
||||
* Implementation instances of this interface represent an {@link OAuth2AuthenticatedPrincipal}
|
||||
* which is associated to an {@link Authentication} object
|
||||
* and may be accessed via {@link Authentication#getPrincipal()}.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @author Eddú Meléndez
|
||||
* @since 5.0
|
||||
* @see DefaultOAuth2User
|
||||
* @see AuthenticatedPrincipal
|
||||
* @see OAuth2AuthenticatedPrincipal
|
||||
*/
|
||||
public interface OAuth2User extends AuthenticatedPrincipal {
|
||||
|
||||
/**
|
||||
* Returns the authorities granted to the user.
|
||||
*
|
||||
* @return a {@code Collection} of {@link GrantedAuthority}(s)
|
||||
*/
|
||||
Collection<? extends GrantedAuthority> getAuthorities();
|
||||
|
||||
/**
|
||||
* Returns the attributes about the user.
|
||||
*
|
||||
* @return a {@code Map} of attributes about the user
|
||||
*/
|
||||
Map<String, Object> getAttributes();
|
||||
public interface OAuth2User extends OAuth2AuthenticatedPrincipal {
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue