use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class OAuth2SecurityExpressionMethodsTests method testScopesWithException.
@Test(expected = AccessDeniedException.class)
public void testScopesWithException() throws Exception {
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
Authentication userAuthentication = null;
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
OAuth2SecurityExpressionMethods root = new OAuth2SecurityExpressionMethods(oAuth2Authentication);
boolean hasAnyScope = root.hasAnyScope("foo");
assertFalse(root.throwOnError(hasAnyScope));
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class OAuth2SecurityExpressionMethodsTests method testSufficientScope.
@Test
public void testSufficientScope() throws Exception {
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
Authentication userAuthentication = null;
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
assertTrue(new OAuth2SecurityExpressionMethods(oAuth2Authentication).hasAnyScope("read"));
assertTrue(new OAuth2SecurityExpressionMethods(oAuth2Authentication).throwOnError(true));
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class OAuth2SecurityExpressionMethodsTests method testScopesFalse.
@Test
public void testScopesFalse() throws Exception {
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
Authentication userAuthentication = null;
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
OAuth2SecurityExpressionMethods root = new OAuth2SecurityExpressionMethods(oAuth2Authentication);
assertFalse(root.hasAnyScope("write"));
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class OAuth2WebSecurityExpressionHandlerTests method testScopes.
@Test
public void testScopes() throws Exception {
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
Authentication userAuthentication = null;
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
FilterInvocation invocation = new FilterInvocation("/foo", "GET");
Expression expression = handler.getExpressionParser().parseExpression("#oauth2.hasAnyScope('read')");
assertTrue((Boolean) expression.getValue(handler.createEvaluationContext(oAuth2Authentication, invocation)));
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project spring-security-oauth by spring-projects.
the class OAuth2WebSecurityExpressionHandlerTests method testOauthClient.
@Test
public void testOauthClient() throws Exception {
AuthorizationRequest request = new AuthorizationRequest("foo", Collections.singleton("read"));
request.setResourceIdsAndAuthoritiesFromClientDetails(new BaseClientDetails("foo", "", "", "client_credentials", "ROLE_CLIENT"));
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request(request.getRequestParameters(), request.getClientId(), request.getAuthorities(), request.isApproved(), request.getScope(), request.getResourceIds(), request.getRedirectUri(), request.getResponseTypes(), request.getExtensions());
Authentication userAuthentication = null;
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
FilterInvocation invocation = new FilterInvocation("/foo", "GET");
Expression expression = handler.getExpressionParser().parseExpression("#oauth2.clientHasAnyRole('ROLE_CLIENT')");
assertTrue((Boolean) expression.getValue(handler.createEvaluationContext(oAuth2Authentication, invocation)));
}
Aggregations