use of org.forgerock.openam.uma.extensions.PermissionRequestFilter in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method setup.
@BeforeMethod
@SuppressWarnings("unchecked")
public void setup() throws ServerException, InvalidGrantException, NotFoundException {
resourceSetStore = mock(ResourceSetStore.class);
OAuth2RequestFactory<?, Request> requestFactory = mock(OAuth2RequestFactory.class);
umaTokenStore = mock(UmaTokenStore.class);
OAuth2ProviderSettingsFactory providerSettingFactory = mock(OAuth2ProviderSettingsFactory.class);
OAuth2ProviderSettings providerSettings = mock(OAuth2ProviderSettings.class);
given(providerSettingFactory.get(Matchers.<OAuth2Request>anyObject())).willReturn(providerSettings);
given(providerSettings.getResourceSetStore()).willReturn(resourceSetStore);
UmaProviderSettingsFactory umaProviderSettingsFactory = mock(UmaProviderSettingsFactory.class);
UmaProviderSettings umaProviderSettings = mock(UmaProviderSettings.class);
given(umaProviderSettingsFactory.get(any(Request.class))).willReturn(umaProviderSettings);
given(umaProviderSettings.getUmaTokenStore()).willReturn(umaTokenStore);
ExtensionFilterManager extensionFilterManager = mock(ExtensionFilterManager.class);
permissionRequestFilter = mock(PermissionRequestFilter.class);
given(extensionFilterManager.getFilters(PermissionRequestFilter.class)).willReturn(Collections.singleton(permissionRequestFilter));
UmaExceptionHandler exceptionHandler = mock(UmaExceptionHandler.class);
endpoint = spy(new PermissionRequestEndpoint(providerSettingFactory, requestFactory, umaProviderSettingsFactory, extensionFilterManager, exceptionHandler, jacksonRepresentationFactory));
response = mock(Response.class);
endpoint.setResponse(response);
Request request = mock(Request.class);
given(endpoint.getRequest()).willReturn(request);
AccessToken accessToken = mock(AccessToken.class);
given(accessToken.getClientId()).willReturn("CLIENT_ID");
given(accessToken.getResourceOwnerId()).willReturn("RESOURCE_OWNER_ID");
OAuth2Request oAuth2Request = mock(OAuth2Request.class);
given(requestFactory.create(request)).willReturn(oAuth2Request);
given(oAuth2Request.getToken(AccessToken.class)).willReturn(accessToken);
}
use of org.forgerock.openam.uma.extensions.PermissionRequestFilter in project OpenAM by OpenRock.
the class PermissionRequestEndpoint method registerPermissionRequest.
/**
* Registers the permission that the client requires for it to be able to access a protected resource.
*
* @param entity The permission request JSON body.
* @return A JSON object containing the permission ticket.
* @throws UmaException If the JSON request body is invalid or the requested resource set does not exist.
*/
@Post
public Representation registerPermissionRequest(JsonRepresentation entity) throws UmaException, NotFoundException, ServerException {
JsonValue permissionRequest = json(toMap(entity));
String resourceSetId = getResourceSetId(permissionRequest);
OAuth2Request oAuth2Request = requestFactory.create(getRequest());
String clientId = getClientId(oAuth2Request);
OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(oAuth2Request);
String resourceOwnerId = getResourceOwnerId(oAuth2Request);
ResourceSetDescription resourceSetDescription = getResourceSet(resourceSetId, resourceOwnerId, providerSettings);
Set<String> scopes = validateScopes(permissionRequest, resourceSetDescription);
for (PermissionRequestFilter filter : extensionFilterManager.getFilters(PermissionRequestFilter.class)) {
filter.onPermissionRequest(resourceSetDescription, scopes, clientId);
}
String ticket = umaProviderSettingsFactory.get(getRequest()).getUmaTokenStore().createPermissionTicket(resourceSetId, scopes, clientId).getId();
return setResponse(201, Collections.<String, Object>singletonMap("ticket", ticket));
}
Aggregations