use of org.restlet.Request in project OpenAM by OpenRock.
the class AuthorizationRequestEndpoint method requestAuthorization.
@Post
public Representation requestAuthorization(JsonRepresentation entity) throws BadRequestException, UmaException, EntitlementException, ServerException, NotFoundException {
UmaProviderSettings umaProviderSettings = umaProviderSettingsFactory.get(this.getRequest());
final OAuth2Request oauth2Request = requestFactory.create(getRequest());
OAuth2ProviderSettings oauth2ProviderSettings = oauth2ProviderSettingsFactory.get(oauth2Request);
OAuth2Uris oAuth2Uris = oAuth2UrisFactory.get(oauth2Request);
final UmaTokenStore umaTokenStore = umaProviderSettings.getUmaTokenStore();
String realm = oauth2Request.getParameter("realm");
JsonValue requestBody = json(toMap(entity));
PermissionTicket permissionTicket = getPermissionTicket(umaTokenStore, requestBody);
validatePermissionTicketHolder(umaTokenStore, permissionTicket);
final String resourceSetId = permissionTicket.getResourceSetId();
final Request request = getRequest();
final String resourceOwnerId = getResourceOwnerId(oauth2ProviderSettings, resourceSetId);
AMIdentity resourceOwner = createIdentity(resourceOwnerId, realm);
String requestingPartyId = null;
try {
requestingPartyId = getRequestingPartyId(umaProviderSettings, oAuth2Uris, requestBody);
} finally {
auditLogger.log(resourceSetId, resourceOwner, UmaAuditType.REQUEST, request, requestingPartyId == null ? getAuthorisationApiToken().getResourceOwnerId() : requestingPartyId);
}
if (isEntitled(umaProviderSettings, oauth2ProviderSettings, permissionTicket, requestingPartyId)) {
getResponse().setStatus(new Status(200));
auditLogger.log(resourceSetId, resourceOwner, UmaAuditType.GRANTED, request, requestingPartyId);
return createJsonRpt(umaTokenStore, permissionTicket);
} else {
try {
if (verifyPendingRequestDoesNotAlreadyExist(resourceSetId, resourceOwnerId, permissionTicket.getRealm(), requestingPartyId, permissionTicket.getScopes())) {
auditLogger.log(resourceSetId, resourceOwner, UmaAuditType.DENIED, request, requestingPartyId);
throw new UmaException(403, UmaConstants.NOT_AUTHORISED_ERROR_CODE, "The client is not authorised to access the requested resource set");
} else {
pendingRequestsService.createPendingRequest(ServletUtils.getRequest(getRequest()), resourceSetId, auditLogger.getResourceName(resourceSetId, request), resourceOwnerId, requestingPartyId, permissionTicket.getRealm(), permissionTicket.getScopes());
auditLogger.log(resourceSetId, resourceOwner, UmaAuditType.REQUEST_SUBMITTED, request, requestingPartyId);
}
} catch (org.forgerock.openam.sm.datalayer.store.ServerException e) {
logger.error("Failed to create pending request", e);
throw new UmaException(403, UmaConstants.NOT_AUTHORISED_ERROR_CODE, "Failed to create pending request");
}
throw newRequestSubmittedException();
}
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class AuthorizationRequestEndpointTest method setup.
@BeforeMethod
@SuppressWarnings("unchecked")
public void setup() throws ServerException, InvalidGrantException, NotFoundException, EntitlementException, JSONException {
requestFactory = mock(OAuth2RequestFactory.class);
OAuth2Request oAuth2Request = mock(OAuth2Request.class);
given(requestFactory.create(any(Request.class))).willReturn(oAuth2Request);
given(oAuth2Request.getParameter("realm")).willReturn("REALM");
accessToken = mock(AccessToken.class);
oauth2TokenStore = mock(TokenStore.class);
given(oauth2TokenStore.readAccessToken(Matchers.<OAuth2Request>anyObject(), anyString())).willReturn(accessToken);
given(accessToken.getClientId()).willReturn(RS_CLIENT_ID);
given(accessToken.getResourceOwnerId()).willReturn(REQUESTING_PARTY_ID);
umaAuditLogger = mock(UmaAuditLogger.class);
umaTokenStore = mock(UmaTokenStore.class);
rpt = mock(RequestingPartyToken.class);
given(rpt.getId()).willReturn("1");
permissionTicket = mock(PermissionTicket.class);
given(permissionTicket.getExpiryTime()).willReturn(System.currentTimeMillis() + 10000);
given(permissionTicket.getResourceSetId()).willReturn(RS_ID);
given(permissionTicket.getResourceServerClientId()).willReturn(RS_CLIENT_ID);
given(permissionTicket.getRealm()).willReturn("REALM");
given(umaTokenStore.readPermissionTicket(anyString())).willReturn(permissionTicket);
given(umaTokenStore.createRPT(Matchers.<PermissionTicket>anyObject())).willReturn(rpt);
resourceSetStore = mock(ResourceSetStore.class);
ResourceSetDescription resourceSet = new ResourceSetDescription();
resourceSet.setId(RS_DESCRIPTION_ID);
resourceSet.setResourceOwnerId(RESOURCE_OWNER_ID);
given(resourceSetStore.query(QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, RS_ID))).willReturn(Collections.singleton(resourceSet));
umaProviderSettings = mock(UmaProviderSettings.class);
policyEvaluator = mock(Evaluator.class);
given(umaProviderSettings.getPolicyEvaluator(any(Subject.class), eq(RS_CLIENT_ID.toLowerCase()))).willReturn(policyEvaluator);
given(umaProviderSettings.getUmaTokenStore()).willReturn(umaTokenStore);
umaProviderSettingsFactory = mock(UmaProviderSettingsFactory.class);
given(umaProviderSettingsFactory.get(Matchers.<Request>anyObject())).willReturn(umaProviderSettings);
given(umaProviderSettings.getUmaTokenStore()).willReturn(umaTokenStore);
OAuth2ProviderSettingsFactory oauth2ProviderSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
OAuth2ProviderSettings oauth2ProviderSettings = mock(OAuth2ProviderSettings.class);
given(oauth2ProviderSettingsFactory.get(any(OAuth2Request.class))).willReturn(oauth2ProviderSettings);
given(oauth2ProviderSettings.getResourceSetStore()).willReturn(resourceSetStore);
OAuth2UrisFactory<RealmInfo> oauth2UrisFactory = mock(OAuth2UrisFactory.class);
OAuth2Uris oauth2Uris = mock(OAuth2Uris.class);
given(oauth2UrisFactory.get(any(OAuth2Request.class))).willReturn(oauth2Uris);
given(oauth2Uris.getIssuer()).willReturn("ISSUER");
pendingRequestsService = mock(PendingRequestsService.class);
Map<String, ClaimGatherer> claimGatherers = new HashMap<>();
idTokenClaimGatherer = mock(IdTokenClaimGatherer.class);
claimGatherers.put(IdTokenClaimGatherer.FORMAT, idTokenClaimGatherer);
ExtensionFilterManager extensionFilterManager = mock(ExtensionFilterManager.class);
requestAuthorizationFilter = mock(RequestAuthorizationFilter.class);
given(extensionFilterManager.getFilters(RequestAuthorizationFilter.class)).willReturn(Collections.singletonList(requestAuthorizationFilter));
UmaExceptionHandler exceptionHandler = mock(UmaExceptionHandler.class);
endpoint = spy(new AuthorizationRequestEndpoint2(umaProviderSettingsFactory, oauth2TokenStore, requestFactory, oauth2ProviderSettingsFactory, oauth2UrisFactory, umaAuditLogger, pendingRequestsService, claimGatherers, extensionFilterManager, exceptionHandler, jacksonRepresentationFactory));
request = mock(Request.class);
given(endpoint.getRequest()).willReturn(request);
response = mock(Response.class);
endpoint.setResponse(response);
requestBody = mock(JSONObject.class);
given(requestBody.toString()).willReturn("{\"ticket\": \"016f84e8-f9b9-11e0-bd6f-0021cc6004de\"}");
entity = mock(JsonRepresentation.class);
given(entity.getJsonObject()).willReturn(requestBody);
}
use of org.restlet.Request in project lucene-solr by apache.
the class TestRestManager method testResolveResourceIdDecodeUrlEntities.
@Test
public void testResolveResourceIdDecodeUrlEntities() throws Exception {
Request testRequest = new Request();
Reference rootRef = new Reference("http://solr.apache.org/");
testRequest.setRootRef(rootRef);
Reference resourceRef = new Reference("http://solr.apache.org/schema/analysis/synonyms/de/%C3%84ndern");
testRequest.setResourceRef(resourceRef);
String resourceId = RestManager.ManagedEndpoint.resolveResourceId(testRequest);
assertEquals(resourceId, "/schema/analysis/synonyms/de/Ă„ndern");
}
Aggregations