Search in sources :

Example 61 with OAuth2AuthorizationRequest

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

the class HttpSessionOAuth2AuthorizationRequestRepositoryTests method saveAuthorizationRequestWhenExistingSessionAndDistributedSessionThenSaved.

@Test
public void saveAuthorizationRequestWhenExistingSessionAndDistributedSessionThenSaved() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(new MockDistributedHttpSession());
    OAuth2AuthorizationRequest authorizationRequest1 = createAuthorizationRequest().build();
    this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest1, request, new MockHttpServletResponse());
    OAuth2AuthorizationRequest authorizationRequest2 = createAuthorizationRequest().build();
    this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest2, request, new MockHttpServletResponse());
    request.addParameter(OAuth2ParameterNames.STATE, authorizationRequest2.getState());
    OAuth2AuthorizationRequest loadedAuthorizationRequest = this.authorizationRequestRepository.loadAuthorizationRequest(request);
    assertThat(loadedAuthorizationRequest).isEqualTo(authorizationRequest2);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OAuth2AuthorizationRequest(org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 62 with OAuth2AuthorizationRequest

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

the class HttpSessionOAuth2AuthorizationRequestRepositoryTests method saveAuthorizationRequestWhenHttpServletResponseIsNullThenThrowIllegalArgumentException.

@Test
public void saveAuthorizationRequestWhenHttpServletResponseIsNullThenThrowIllegalArgumentException() {
    OAuth2AuthorizationRequest authorizationRequest = createAuthorizationRequest().build();
    assertThatIllegalArgumentException().isThrownBy(() -> this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest, new MockHttpServletRequest(), null));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OAuth2AuthorizationRequest(org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest) Test(org.junit.jupiter.api.Test)

Example 63 with OAuth2AuthorizationRequest

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

the class HttpSessionOAuth2AuthorizationRequestRepositoryTests method saveAuthorizationRequestWhenStateNullThenThrowIllegalArgumentException.

@Test
public void saveAuthorizationRequestWhenStateNullThenThrowIllegalArgumentException() {
    OAuth2AuthorizationRequest authorizationRequest = createAuthorizationRequest().state(null).build();
    assertThatIllegalArgumentException().isThrownBy(() -> this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest, new MockHttpServletRequest(), new MockHttpServletResponse()));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OAuth2AuthorizationRequest(org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 64 with OAuth2AuthorizationRequest

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

the class HttpSessionOAuth2AuthorizationRequestRepositoryTests method removeAuthorizationRequestWhenNotSavedThenNotRemoved.

@Test
public void removeAuthorizationRequestWhenNotSavedThenNotRemoved() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(OAuth2ParameterNames.STATE, "state-1234");
    MockHttpServletResponse response = new MockHttpServletResponse();
    OAuth2AuthorizationRequest removedAuthorizationRequest = this.authorizationRequestRepository.removeAuthorizationRequest(request, response);
    assertThat(removedAuthorizationRequest).isNull();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OAuth2AuthorizationRequest(org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 65 with OAuth2AuthorizationRequest

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

the class HttpSessionOAuth2AuthorizationRequestRepositoryTests method saveAuthorizationRequestWhenNoExistingSessionAndDistributedSessionThenSaved.

@Test
public void saveAuthorizationRequestWhenNoExistingSessionAndDistributedSessionThenSaved() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(new MockDistributedHttpSession());
    OAuth2AuthorizationRequest authorizationRequest = createAuthorizationRequest().build();
    this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest, request, new MockHttpServletResponse());
    request.addParameter(OAuth2ParameterNames.STATE, authorizationRequest.getState());
    OAuth2AuthorizationRequest loadedAuthorizationRequest = this.authorizationRequestRepository.loadAuthorizationRequest(request);
    assertThat(loadedAuthorizationRequest).isEqualTo(authorizationRequest);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OAuth2AuthorizationRequest(org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)137 Test (org.junit.jupiter.api.Test)112 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)52 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)49 HashMap (java.util.HashMap)26 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)25 OAuth2AuthorizationResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse)24 OAuth2AuthorizationExchange (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationExchange)22 Authentication (org.springframework.security.core.Authentication)19 MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)18 OAuth2AccessTokenResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse)17 ServerWebExchange (org.springframework.web.server.ServerWebExchange)13 OAuth2ParameterNames (org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames)12 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)11 OAuth2Error (org.springframework.security.oauth2.core.OAuth2Error)11 BeforeEach (org.junit.jupiter.api.BeforeEach)10 HttpRequestResponseHolder (org.springframework.security.web.context.HttpRequestResponseHolder)10 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)10 Map (java.util.Map)9 Mono (reactor.core.publisher.Mono)9