use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.
the class DefaultUserApprovalHandlerTests method testBasicApproval.
@Test
public void testBasicApproval() {
AuthorizationRequest request = new AuthorizationRequest(new HashMap<String, String>(), null, null, null, null, null, false, null, null, null);
// This is enough to be explicitly approved
request.setApproved(true);
assertTrue(handler.isApproved(request, new TestAuthentication("marissa", true)));
}
use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.
the class TokenApprovalStoreTests method addApprovals.
@Override
protected boolean addApprovals(Collection<Approval> approvals) {
Map<String, Map<String, Set<String>>> clientIds = new HashMap<String, Map<String, Set<String>>>();
for (Approval approval : approvals) {
String clientId = approval.getClientId();
if (!clientIds.containsKey(clientId)) {
clientIds.put(clientId, new HashMap<String, Set<String>>());
}
String userId = approval.getUserId();
Map<String, Set<String>> users = clientIds.get(clientId);
if (!users.containsKey(userId)) {
users.put(userId, new HashSet<String>());
}
Set<String> scopes = users.get(userId);
scopes.add(approval.getScope());
}
for (String clientId : clientIds.keySet()) {
Map<String, Set<String>> users = clientIds.get(clientId);
for (String userId : users.keySet()) {
Authentication user = new UsernamePasswordAuthenticationToken(userId, "N/A", AuthorityUtils.commaSeparatedStringToAuthorityList("USER"));
AuthorizationRequest authorizationRequest = new AuthorizationRequest();
authorizationRequest.setClientId(clientId);
Set<String> scopes = users.get(userId);
authorizationRequest.setScope(scopes);
OAuth2Request request = authorizationRequest.createOAuth2Request();
OAuth2Authentication authentication = new OAuth2Authentication(request, user);
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(UUID.randomUUID().toString());
token.setScope(scopes);
tokenStore.storeAccessToken(token, authentication);
}
}
return super.addApprovals(approvals);
}
use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.
the class TokenStoreUserApprovalHandlerTests method testBasicApproval.
@Test
public void testBasicApproval() {
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put(OAuth2Utils.USER_OAUTH_APPROVAL, "true");
AuthorizationRequest request = new AuthorizationRequest(parameters, null, null, null, null, null, false, null, null, null);
// This is enough to be explicitly approved
request.setApproved(true);
assertTrue(handler.isApproved(request, new TestAuthentication("marissa", true)));
}
use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.
the class TokenStoreUserApprovalHandlerTests method testMemorizedApproval.
@Test
public void testMemorizedApproval() {
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put(OAuth2Utils.USER_OAUTH_APPROVAL, "false");
parameters.put("client_id", "foo");
AuthorizationRequest authorizationRequest = new AuthorizationRequest(parameters, null, "foo", null, null, null, false, null, null, null);
authorizationRequest.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
OAuth2Request storedOAuth2Request = requestFactory.createOAuth2Request(authorizationRequest);
tokenServices.createAccessToken(new OAuth2Authentication(storedOAuth2Request, userAuthentication));
authorizationRequest = handler.checkForPreApproval(authorizationRequest, userAuthentication);
assertTrue(handler.isApproved(authorizationRequest, userAuthentication));
}
use of org.springframework.security.oauth2.provider.AuthorizationRequest in project spring-security-oauth by spring-projects.
the class ApprovalStoreUserApprovalHandlerTests method testApprovalLongExpiry.
@Test
public void testApprovalLongExpiry() throws Exception {
handler.setApprovalExpiryInSeconds(365 * 24 * 60 * 60);
AuthorizationRequest authorizationRequest = new AuthorizationRequest("client", Arrays.asList("read"));
authorizationRequest.setApprovalParameters(Collections.singletonMap("scope.read", "approved"));
AuthorizationRequest result = handler.updateAfterApproval(authorizationRequest, userAuthentication);
assertTrue(handler.isApproved(result, userAuthentication));
}
Aggregations