use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class AuditEventPublisherImpl method publishForRealm.
private void publishForRealm(String realm, String topic, AuditEvent auditEvent) throws ResourceException {
AMAuditService auditService = auditServiceProvider.getAuditService(realm);
Connection connection = newInternalConnection(auditService);
CreateRequest request = newCreateRequest(topic, auditEvent.getValue());
try {
connection.create(new RootContext(), request);
} catch (ServiceUnavailableException e) {
debug.message("Audit Service for realm {} is unavailable. Trying the default Audit Service.", realm, e);
publishToDefault(topic, auditEvent);
}
}
use of org.forgerock.services.context.RootContext 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());
}
});
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class UmaEnabledFilterTest method setup.
@BeforeMethod
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
context = ClientContext.newInternalClientContext(new RealmContext(new RootContext()));
requestHandler = mock(RequestHandler.class);
when(requestHandler.handleAction(any(Context.class), any(ActionRequest.class))).thenReturn(promise(newActionResponse(null)));
when(requestHandler.handleCreate(any(Context.class), any(CreateRequest.class))).thenReturn(promise(newResourceResponse(null, null, null)));
when(requestHandler.handleDelete(any(Context.class), any(DeleteRequest.class))).thenReturn(promise(newResourceResponse(null, null, null)));
when(requestHandler.handlePatch(any(Context.class), any(PatchRequest.class))).thenReturn(promise(newResourceResponse(null, null, null)));
when(requestHandler.handleQuery(any(Context.class), any(QueryRequest.class), any(QueryResourceHandler.class))).thenReturn(promise(newQueryResponse()));
when(requestHandler.handleRead(any(Context.class), any(ReadRequest.class))).thenReturn(promise(newResourceResponse(null, null, null)));
when(requestHandler.handleUpdate(any(Context.class), any(UpdateRequest.class))).thenReturn(promise(newResourceResponse(null, null, null)));
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class ResourceSetServiceTest method createContext.
private Context createContext() {
RealmContext realmContext = new RealmContext(new RootContext());
realmContext.setDnsAlias("/", "REALM");
return realmContext;
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class RealmContextTest method getResolvedRealmShouldReturnCorrectRealm.
@Test(dataProvider = "realmData")
public void getResolvedRealmShouldReturnCorrectRealm(Pair<String, String> dnsRealm, Pair<String, String> uriRealm1, Pair<String, String> uriRealm2, String queryParameterRealm, String expectedRealm) {
//Given
RealmContext context = new RealmContext(new RootContext());
if (dnsRealm != null) {
context.setDnsAlias(dnsRealm.getFirst(), dnsRealm.getSecond());
}
if (uriRealm1 != null) {
context.setSubRealm(uriRealm1.getFirst(), uriRealm1.getSecond());
}
if (uriRealm2 != null) {
context.setSubRealm(uriRealm2.getFirst(), uriRealm2.getSecond());
}
if (queryParameterRealm != null) {
context.setOverrideRealm(queryParameterRealm);
}
//When
String resolvedRealm = context.getResolvedRealm();
//Then
assertThat(resolvedRealm).isEqualTo(expectedRealm);
}
Aggregations