use of org.springframework.security.core.Authentication in project spring-security-oauth by spring-projects.
the class OAuth2SecurityExpressionMethodsTests method testInsufficientScope.
@Test(expected = AccessDeniedException.class)
public void testInsufficientScope() 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");
root.throwOnError(hasAnyScope);
}
use of org.springframework.security.core.Authentication 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.core.Authentication 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.core.Authentication 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.core.Authentication 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)));
}
Aggregations