Search in sources :

Example 26 with Builder

use of org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest.Builder in project spring-security by spring-projects.

the class JwtAuthenticationTokenTests method constructorWhenUsingOnlyJwtThenConstructedCorrectly.

@Test
public void constructorWhenUsingOnlyJwtThenConstructedCorrectly() {
    Jwt jwt = builder().claim("claim", "value").build();
    JwtAuthenticationToken token = new JwtAuthenticationToken(jwt);
    assertThat(token.getAuthorities()).isEmpty();
    assertThat(token.getPrincipal()).isEqualTo(jwt);
    assertThat(token.getCredentials()).isEqualTo(jwt);
    assertThat(token.getToken()).isEqualTo(jwt);
    assertThat(token.getTokenAttributes()).isEqualTo(jwt.getClaims());
    assertThat(token.isAuthenticated()).isFalse();
}
Also used : Jwt(org.springframework.security.oauth2.jwt.Jwt) Test(org.junit.jupiter.api.Test)

Example 27 with Builder

use of org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest.Builder in project spring-security by spring-projects.

the class JwtAuthenticationTokenTests method getNameWhenConstructedWithNoSubjectThenReturnsNull.

@Test
public void getNameWhenConstructedWithNoSubjectThenReturnsNull() {
    Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("test");
    Jwt jwt = builder().claim("claim", "value").build();
    assertThat(new JwtAuthenticationToken(jwt, authorities, null).getName()).isNull();
    assertThat(new JwtAuthenticationToken(jwt, authorities).getName()).isNull();
    assertThat(new JwtAuthenticationToken(jwt).getName()).isNull();
}
Also used : Jwt(org.springframework.security.oauth2.jwt.Jwt) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.jupiter.api.Test)

Example 28 with Builder

use of org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest.Builder in project spring-security by spring-projects.

the class JwtAuthenticationTokenTests method constructorWhenUsingCorrectParametersThenConstructedCorrectly.

@Test
public void constructorWhenUsingCorrectParametersThenConstructedCorrectly() {
    Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("test");
    Jwt jwt = builder().claim("claim", "value").build();
    JwtAuthenticationToken token = new JwtAuthenticationToken(jwt, authorities);
    assertThat(token.getAuthorities()).isEqualTo(authorities);
    assertThat(token.getPrincipal()).isEqualTo(jwt);
    assertThat(token.getCredentials()).isEqualTo(jwt);
    assertThat(token.getToken()).isEqualTo(jwt);
    assertThat(token.getTokenAttributes()).isEqualTo(jwt.getClaims());
    assertThat(token.isAuthenticated()).isTrue();
}
Also used : Jwt(org.springframework.security.oauth2.jwt.Jwt) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.jupiter.api.Test)

Example 29 with Builder

use of org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest.Builder in project spring-security by spring-projects.

the class JwtAuthenticationTokenTests method getNameWhenConstructedWithJwtThenReturnsSubject.

@Test
public void getNameWhenConstructedWithJwtThenReturnsSubject() {
    Jwt jwt = builder().subject("Hayden").build();
    JwtAuthenticationToken token = new JwtAuthenticationToken(jwt);
    assertThat(token.getName()).isEqualTo("Hayden");
}
Also used : Jwt(org.springframework.security.oauth2.jwt.Jwt) Test(org.junit.jupiter.api.Test)

Example 30 with Builder

use of org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest.Builder in project spring-security by spring-projects.

the class JwtAuthenticationTokenTests method getNameWhenConstructedWithNameThenReturnsProvidedName.

@Test
public void getNameWhenConstructedWithNameThenReturnsProvidedName() {
    Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("test");
    Jwt jwt = builder().claim("claim", "value").build();
    JwtAuthenticationToken token = new JwtAuthenticationToken(jwt, authorities, "Hayden");
    assertThat(token.getName()).isEqualTo("Hayden");
}
Also used : Jwt(org.springframework.security.oauth2.jwt.Jwt) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)9 Jwt (org.springframework.security.oauth2.jwt.Jwt)8 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)6 GrantedAuthority (org.springframework.security.core.GrantedAuthority)5 Authentication (org.springframework.security.core.Authentication)3 Builder (org.springframework.security.oauth2.client.registration.ClientRegistration.Builder)3 ClientRegistrationException (org.springframework.security.oauth2.provider.ClientRegistrationException)3 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)2 HashMap (java.util.HashMap)2 Base64Exception (org.apache.cxf.common.util.Base64Exception)2 CommonOAuth2Provider (org.springframework.security.config.oauth2.client.CommonOAuth2Provider)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 OAuth2AuthorizeRequest (org.springframework.security.oauth2.client.OAuth2AuthorizeRequest)2 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)2 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)2 DefaultExceptionMessageBuilder (com.epam.ta.reportportal.commons.exception.message.DefaultExceptionMessageBuilder)1 DefaultErrorResolver (com.epam.ta.reportportal.commons.exception.rest.DefaultErrorResolver)1 ReportPortalExceptionResolver (com.epam.ta.reportportal.commons.exception.rest.ReportPortalExceptionResolver)1