Search in sources :

Example 6 with HttpSessionOAuth2AuthorizationRequestRepository

use of org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizationRequestRepository 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)

Aggregations

Test (org.junit.jupiter.api.Test)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)4 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)3 HashMap (java.util.HashMap)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MockHttpSession (org.springframework.mock.web.MockHttpSession)2 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)2 InMemoryOAuth2AuthorizedClientService (org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService)2 InMemoryClientRegistrationRepository (org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository)2 HttpSessionOAuth2AuthorizationRequestRepository (org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizationRequestRepository)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)1 AuthenticationDetailsSource (org.springframework.security.authentication.AuthenticationDetailsSource)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1 OAuth2AuthorizedClient (org.springframework.security.oauth2.client.OAuth2AuthorizedClient)1 RegisteredOAuth2AuthorizedClient (org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient)1 AuthenticationFailureHandler (org.springframework.security.web.authentication.AuthenticationFailureHandler)1