Search in sources :

Example 36 with AuthorizationRequest

use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.

the class DefaultAuthorizationRequestFactoryTests method testCreateAuthorizationRequest.

@Test
public void testCreateAuthorizationRequest() {
    AuthorizationRequest request = factory.createAuthorizationRequest(Collections.singletonMap("client_id", "foo"));
    assertEquals("foo", request.getClientId());
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) Test(org.junit.Test)

Example 37 with AuthorizationRequest

use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.

the class DefaultAuthorizationRequestFactoryTests method testCreateAuthorizationRequestWhenUserNotPermitted.

@Test
public void testCreateAuthorizationRequestWhenUserNotPermitted() {
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("user", "N/A", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_BAR")));
    factory.setCheckUserScopes(true);
    client.setScope(Collections.singleton("foo"));
    AuthorizationRequest request = factory.createAuthorizationRequest(Collections.singletonMap("client_id", "foo"));
    assertEquals("foo", request.getClientId());
    assertEquals("[]", request.getScope().toString());
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 38 with AuthorizationRequest

use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.

the class DefaultAuthorizationRequestFactoryTests method testCreateAuthorizationRequestWithUserRoles.

@Test
public void testCreateAuthorizationRequestWithUserRoles() {
    factory.setCheckUserScopes(true);
    AuthorizationRequest request = factory.createAuthorizationRequest(Collections.singletonMap("client_id", "foo"));
    assertEquals("foo", request.getClientId());
    assertEquals("[bar]", request.getScope().toString());
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) Test(org.junit.Test)

Example 39 with AuthorizationRequest

use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.

the class DefaultAuthorizationRequestFactoryTests method testSecretErased.

@Test
public void testSecretErased() {
    factory.setCheckUserScopes(true);
    Map<String, String> params = new HashMap<String, String>(Collections.singletonMap("client_id", "foo"));
    params.put("client_secret", "shhh");
    AuthorizationRequest auth = factory.createAuthorizationRequest(params);
    OAuth2Request request = factory.createTokenRequest(auth, "client_credentials").createOAuth2Request(client);
    assertNull(request.getRequestParameters().get("client_secret"));
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 40 with AuthorizationRequest

use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.

the class DefaultAuthorizationRequestFactoryTests method testCreateAuthorizationRequestWithDefaultScopes.

@Test
public void testCreateAuthorizationRequestWithDefaultScopes() {
    AuthorizationRequest request = factory.createAuthorizationRequest(Collections.singletonMap("client_id", "foo"));
    assertEquals("[bar]", request.getScope().toString());
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) Test(org.junit.Test)

Aggregations

OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)101 Test (org.junit.jupiter.api.Test)87 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)69 Test (org.junit.Test)58 Authentication (org.springframework.security.core.Authentication)58 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)52 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)51 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)48 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)42 HashMap (java.util.HashMap)36 OAuth2AuthorizationResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse)21 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)19 OAuth2AuthorizationExchange (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationExchange)19 ModelAndView (org.springframework.web.servlet.ModelAndView)18 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)16 HashSet (java.util.HashSet)15 OAuth2AccessTokenResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse)15 RedirectView (org.springframework.web.servlet.view.RedirectView)14 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)13 LinkedHashMap (java.util.LinkedHashMap)12