use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class OAuth2MethodSecurityExpressionHandlerTests method testScopesInsufficient.
@Test(expected = AccessDeniedException.class)
public void testScopesInsufficient() throws Exception {
AuthorizationRequest request = new AuthorizationRequest("foo", Collections.singleton("read"));
request.setResourceIdsAndAuthoritiesFromClientDetails(new BaseClientDetails("foo", "bar", "", "client_credentials", "ROLE_CLIENT"));
OAuth2Request clientAuthentication = request.createOAuth2Request();
Authentication userAuthentication = new UsernamePasswordAuthenticationToken("user", "pass", AuthorityUtils.createAuthorityList("ROLE_USER"));
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(), "testOauthClient"));
EvaluationContext context = handler.createEvaluationContext(oAuth2Authentication, invocation);
Expression expression = handler.getExpressionParser().parseExpression("#oauth2.hasAnyScope('write')");
expression.getValue(context);
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class OAuth2MethodSecurityExpressionHandlerTests method testReEvaluationWithDifferentRoot.
@Test
public void testReEvaluationWithDifferentRoot() throws Exception {
Expression expression = handler.getExpressionParser().parseExpression("#oauth2.isClient()");
MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(), "testNonOauthClient"));
Authentication clientAuthentication = new UsernamePasswordAuthenticationToken("foo", "bar");
EvaluationContext context = handler.createEvaluationContext(clientAuthentication, invocation);
assertFalse((Boolean) expression.getValue(context));
OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("foo", true, Collections.singleton("read"));
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(storedOAuth2Request, null);
EvaluationContext anotherContext = handler.createEvaluationContext(oAuth2Authentication, invocation);
assertTrue((Boolean) expression.getValue(anotherContext));
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class OAuth2SecurityExpressionMethodsTests method testOAuthUser.
@Test
public void testOAuthUser() throws Exception {
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", true, Collections.singleton("read"));
Authentication userAuthentication = new UsernamePasswordAuthenticationToken("foo", "bar", Collections.singleton(new SimpleGrantedAuthority("ROLE_USER")));
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
assertTrue(new OAuth2SecurityExpressionMethods(oAuth2Authentication).isUser());
assertFalse(new OAuth2SecurityExpressionMethods(new OAuth2Authentication(clientAuthentication, null)).isUser());
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class DefaultAuthorizationRequestFactoryTests method testPasswordErased.
@Test
public void testPasswordErased() {
factory.setCheckUserScopes(true);
Map<String, String> params = new HashMap<String, String>(Collections.singletonMap("client_id", "foo"));
params.put("password", "shhh");
AuthorizationRequest auth = factory.createAuthorizationRequest(params);
OAuth2Request request = factory.createTokenRequest(auth, "password").createOAuth2Request(client);
assertNull(request.getRequestParameters().get("password"));
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class DefaultAuthorizationRequestFactoryTests method testCreateTokenThenOAuth2RequestWithGrantType.
@Test
public void testCreateTokenThenOAuth2RequestWithGrantType() {
factory.setCheckUserScopes(true);
AuthorizationRequest auth = factory.createAuthorizationRequest(Collections.singletonMap("client_id", "foo"));
OAuth2Request request = factory.createTokenRequest(auth, "password").createOAuth2Request(client);
assertEquals("password", request.getGrantType());
assertEquals("[bar]", request.getResourceIds().toString());
}
Aggregations