use of org.forgerock.openam.rest.resource.AdminSubjectContext in project OpenAM by OpenRock.
the class UmaResourceSetRegistrationHook method createAdminContext.
/**
* Used to create a context for deleting policies. If this is being called, we know that the user has the right
* to delete the policies.
* @param realm The realm to delete the policies in.
* @param resourceOwnerId The owner of the ResourceSet that the policies are for.
* @return The generated context.
*/
private Context createAdminContext(String realm, String resourceOwnerId) {
RealmContext realmContext = new RealmContext(new RootContext());
realmContext.setSubRealm(realm, realm);
SubjectContext subjectContext = new AdminSubjectContext(logger, sessionCache, realmContext);
Map<String, String> templateVariables = new HashMap<>();
templateVariables.put("user", resourceOwnerId);
UriRouterContext routerContext = new UriRouterContext(subjectContext, "", "", templateVariables);
return routerContext;
}
use of org.forgerock.openam.rest.resource.AdminSubjectContext in project OpenAM by OpenRock.
the class UmaPolicyApplicationListener method deletePolicies.
private void deletePolicies(String realm, String resourceServerId) {
RealmContext realmContext = new RealmContext(new RootContext());
realmContext.setDnsAlias("/", realm);
final Context context = new AdminSubjectContext(logger, sessionCache, realmContext);
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.equalTo(new JsonPointer("applicationName"), resourceServerId));
final List<ResourceResponse> resources = new ArrayList<>();
policyResource.handleQuery(context, request, new QueryResourceHandler() {
@Override
public boolean handleResource(ResourceResponse resource) {
resources.add(resource);
return true;
}
}).thenAsync(new AsyncFunction<QueryResponse, List<ResourceResponse>, ResourceException>() {
@Override
public Promise<List<ResourceResponse>, ResourceException> apply(QueryResponse response) {
List<Promise<ResourceResponse, ResourceException>> promises = new ArrayList<>();
for (ResourceResponse policy : resources) {
DeleteRequest deleteRequest = Requests.newDeleteRequest("", policy.getId());
promises.add(policyResource.handleDelete(context, deleteRequest));
}
Promise<List<ResourceResponse>, ResourceException> when = Promises.when(promises);
return when;
}
}).thenOnException(new ExceptionHandler<ResourceException>() {
@Override
public void handleException(ResourceException error) {
logger.error(error.getReason());
}
});
}
Aggregations