Search in sources :

Example 6 with DefaultOAuth2AuthenticatedPrincipal

use of org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal in project spring-security by spring-projects.

the class BearerTokenAuthenticationTests method toStringWhenAttributesContainsURLThenDoesNotFail.

// gh-6843
@Test
public void toStringWhenAttributesContainsURLThenDoesNotFail() throws Exception {
    JSONObject attributes = new JSONObject(Collections.singletonMap("iss", new URL("https://idp.example.com")));
    OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal(attributes, null);
    BearerTokenAuthentication token = new BearerTokenAuthentication(principal, this.token, null);
    token.toString();
}
Also used : JSONObject(net.minidev.json.JSONObject) OAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal) DefaultOAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal) DefaultOAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultOAuth2AuthenticatedPrincipal

use of org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal in project spring-security by spring-projects.

the class BearerTokenAuthenticationTests method setUp.

@BeforeEach
public void setUp() {
    this.attributesMap.put(OAuth2TokenIntrospectionClaimNames.SUB, this.name);
    this.attributesMap.put(OAuth2TokenIntrospectionClaimNames.CLIENT_ID, "client_id");
    this.attributesMap.put(OAuth2TokenIntrospectionClaimNames.USERNAME, "username");
    this.principal = new DefaultOAuth2AuthenticatedPrincipal(this.attributesMap, null);
}
Also used : DefaultOAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with DefaultOAuth2AuthenticatedPrincipal

use of org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal in project spring-security by spring-projects.

the class BearerTokenAuthenticationTests method getNameWhenConfiguredInConstructorThenReturnsName.

@Test
public void getNameWhenConfiguredInConstructorThenReturnsName() {
    OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal(this.name, this.attributesMap, this.authorities);
    BearerTokenAuthentication authenticated = new BearerTokenAuthentication(principal, this.token, this.authorities);
    assertThat(authenticated.getName()).isEqualTo(this.name);
}
Also used : OAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal) DefaultOAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal) DefaultOAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultOAuth2AuthenticatedPrincipal (org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal)8 OAuth2AuthenticatedPrincipal (org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal)7 Test (org.junit.jupiter.api.Test)5 JSONObject (net.minidev.json.JSONObject)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 OAuth2AccessToken (org.springframework.security.oauth2.core.OAuth2AccessToken)2 URL (java.net.URL)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 AbstractAuthenticationToken (org.springframework.security.authentication.AbstractAuthenticationToken)1