Search in sources :

Example 21 with OAuth2Request

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

the class AuthorizationCodeServicesBaseTests method testCreateAuthorizationCode.

@Test
public void testCreateAuthorizationCode() {
    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("id", false);
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(storedOAuth2Request, new TestAuthentication("test2", false));
    String code = getAuthorizationCodeServices().createAuthorizationCode(expectedAuthentication);
    assertNotNull(code);
    OAuth2Authentication actualAuthentication = getAuthorizationCodeServices().consumeAuthorizationCode(code);
    assertEquals(expectedAuthentication, actualAuthentication);
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Test(org.junit.Test)

Example 22 with OAuth2Request

use of org.springframework.security.oauth2.provider.OAuth2Request 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 23 with OAuth2Request

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

the class DefaultAuthorizationRequestFactoryTests method testCreateAuthorizationThenOAuth2RequestWithGrantType.

@Test
public void testCreateAuthorizationThenOAuth2RequestWithGrantType() {
    factory.setCheckUserScopes(true);
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("client_id", "foo");
    parameters.put("response_type", "token");
    OAuth2Request request = factory.createAuthorizationRequest(parameters).createOAuth2Request();
    assertEquals("implicit", request.getGrantType());
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 24 with OAuth2Request

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

the class OAuth2RequestTests method testResourceIdsConstructorAssignment.

// gh-724
@Test
public void testResourceIdsConstructorAssignment() {
    Set<String> resourceIds = new HashSet<String>(Arrays.asList("resourceId-1", "resourceId-2"));
    OAuth2Request request = new OAuth2Request(Collections.<String, String>emptyMap(), "clientId", Collections.<GrantedAuthority>emptyList(), false, Collections.<String>emptySet(), resourceIds, "redirectUri", Collections.<String>emptySet(), Collections.<String, Serializable>emptyMap());
    assertNotSame("resourceIds are the same", resourceIds, request.getResourceIds());
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with OAuth2Request

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

the class OAuth2RequestTests method testImplicitGrantType.

@Test
public void testImplicitGrantType() throws Exception {
    parameters.put("response_type", "token");
    OAuth2Request authorizationRequest = createFromParameters(parameters);
    assertEquals("implicit", authorizationRequest.getGrantType());
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) Test(org.junit.Test)

Aggregations

OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)99 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)77 Authentication (org.springframework.security.core.Authentication)57 Test (org.junit.Test)56 HashMap (java.util.HashMap)21 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)16 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)15 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)14 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)13 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)12 Date (java.util.Date)11 HashSet (java.util.HashSet)11 Expression (org.springframework.expression.Expression)10 DBUnitTest (org.orcid.test.DBUnitTest)8 EvaluationContext (org.springframework.expression.EvaluationContext)8 MethodInvocation (org.aopalliance.intercept.MethodInvocation)7 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)7 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)7 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)7 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)7