Search in sources :

Example 6 with InMemoryClientRegistrationRepository

use of org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository in project spring-security by spring-projects.

the class OAuth2AuthorizationCodeGrantFilterTests method setup.

@BeforeEach
public void setup() {
    this.registration1 = TestClientRegistrations.clientRegistration().build();
    this.clientRegistrationRepository = new InMemoryClientRegistrationRepository(this.registration1);
    this.authorizedClientService = new InMemoryOAuth2AuthorizedClientService(this.clientRegistrationRepository);
    this.authorizedClientRepository = new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(this.authorizedClientService);
    this.authorizationRequestRepository = new HttpSessionOAuth2AuthorizationRequestRepository();
    this.authenticationManager = mock(AuthenticationManager.class);
    this.filter = spy(new OAuth2AuthorizationCodeGrantFilter(this.clientRegistrationRepository, this.authorizedClientRepository, this.authenticationManager));
    this.filter.setAuthorizationRequestRepository(this.authorizationRequestRepository);
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(this.principalName1, "password");
    authentication.setAuthenticated(true);
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) InMemoryOAuth2AuthorizedClientService(org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService) InMemoryClientRegistrationRepository(org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository) SecurityContext(org.springframework.security.core.context.SecurityContext) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with InMemoryClientRegistrationRepository

use of org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository in project spring-security by spring-projects.

the class DefaultOAuth2AuthorizationRequestResolverTests method setUp.

@BeforeEach
public void setUp() {
    this.registration1 = TestClientRegistrations.clientRegistration().build();
    this.registration2 = TestClientRegistrations.clientRegistration2().build();
    this.fineRedirectUriTemplateRegistration = fineRedirectUriTemplateClientRegistration().build();
    // @formatter:off
    this.pkceRegistration = TestClientRegistrations.clientRegistration().registrationId("pkce-client-registration-id").clientId("pkce-client-id").clientAuthenticationMethod(ClientAuthenticationMethod.NONE).clientSecret(null).build();
    this.oidcRegistration = TestClientRegistrations.clientRegistration().registrationId("oidc-registration-id").scope(OidcScopes.OPENID).build();
    // @formatter:on
    this.clientRegistrationRepository = new InMemoryClientRegistrationRepository(this.registration1, this.registration2, this.fineRedirectUriTemplateRegistration, this.pkceRegistration, this.oidcRegistration);
    this.resolver = new DefaultOAuth2AuthorizationRequestResolver(this.clientRegistrationRepository, this.authorizationRequestBaseUri);
}
Also used : InMemoryClientRegistrationRepository(org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with InMemoryClientRegistrationRepository

use of org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository in project spring-security by spring-projects.

the class OidcClientInitiatedLogoutSuccessHandlerTests method logoutWhenClientRegistrationHasNoEndSessionEndpointThenDefaults.

@Test
public void logoutWhenClientRegistrationHasNoEndSessionEndpointThenDefaults() throws Exception {
    ClientRegistration registration = TestClientRegistrations.clientRegistration().build();
    ClientRegistrationRepository repository = new InMemoryClientRegistrationRepository(registration);
    OidcClientInitiatedLogoutSuccessHandler handler = new OidcClientInitiatedLogoutSuccessHandler(repository);
    OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(), AuthorityUtils.NO_AUTHORITIES, registration.getRegistrationId());
    this.request.setUserPrincipal(token);
    handler.setDefaultTargetUrl("https://default");
    handler.onLogoutSuccess(this.request, this.response, token);
    assertThat(this.response.getRedirectedUrl()).isEqualTo("https://default");
}
Also used : ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) OAuth2AuthenticationToken(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken) InMemoryClientRegistrationRepository(org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository) ClientRegistrationRepository(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository) InMemoryClientRegistrationRepository(org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository) Test(org.junit.jupiter.api.Test)

Aggregations

InMemoryClientRegistrationRepository (org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 InMemoryOAuth2AuthorizedClientService (org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService)3 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)2 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 SecurityContext (org.springframework.security.core.context.SecurityContext)2 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)2 RequestCache (org.springframework.security.web.savedrequest.RequestCache)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 IOException (java.io.IOException)1 CertificateException (java.security.cert.CertificateException)1 Base64Exception (org.apache.cxf.common.util.Base64Exception)1 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)1 PKCSException (org.bouncycastle.pkcs.PKCSException)1 Test (org.junit.jupiter.api.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 AuthenticationDetailsSource (org.springframework.security.authentication.AuthenticationDetailsSource)1 Authentication (org.springframework.security.core.Authentication)1