Search in sources :

Example 11 with RootContext

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);
    }
}
Also used : RootContext(org.forgerock.services.context.RootContext) CreateRequest(org.forgerock.json.resource.CreateRequest) Requests.newCreateRequest(org.forgerock.json.resource.Requests.newCreateRequest) Connection(org.forgerock.json.resource.Connection) Resources.newInternalConnection(org.forgerock.json.resource.Resources.newInternalConnection) ServiceUnavailableException(org.forgerock.json.resource.ServiceUnavailableException)

Example 12 with RootContext

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());
        }
    });
}
Also used : RootContext(org.forgerock.services.context.RootContext) RealmContext(org.forgerock.openam.rest.RealmContext) AdminSubjectContext(org.forgerock.openam.rest.resource.AdminSubjectContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) QueryRequest(org.forgerock.json.resource.QueryRequest) AdminSubjectContext(org.forgerock.openam.rest.resource.AdminSubjectContext) ArrayList(java.util.ArrayList) JsonPointer(org.forgerock.json.JsonPointer) AsyncFunction(org.forgerock.util.AsyncFunction) RootContext(org.forgerock.services.context.RootContext) Promise(org.forgerock.util.promise.Promise) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) List(java.util.List) ArrayList(java.util.ArrayList) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) DenyOverride(com.sun.identity.entitlement.DenyOverride) DeleteRequest(org.forgerock.json.resource.DeleteRequest)

Example 13 with RootContext

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)));
}
Also used : RootContext(org.forgerock.services.context.RootContext) RootContext(org.forgerock.services.context.RootContext) ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) RequestHandler(org.forgerock.json.resource.RequestHandler) QueryRequest(org.forgerock.json.resource.QueryRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) UpdateRequest(org.forgerock.json.resource.UpdateRequest) CreateRequest(org.forgerock.json.resource.CreateRequest) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) PatchRequest(org.forgerock.json.resource.PatchRequest) DeleteRequest(org.forgerock.json.resource.DeleteRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 14 with RootContext

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;
}
Also used : RootContext(org.forgerock.services.context.RootContext) RealmContext(org.forgerock.openam.rest.RealmContext)

Example 15 with RootContext

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);
}
Also used : RootContext(org.forgerock.services.context.RootContext) Test(org.testng.annotations.Test)

Aggregations

RootContext (org.forgerock.services.context.RootContext)24 Test (org.testng.annotations.Test)16 Context (org.forgerock.services.context.Context)7 Request (org.forgerock.http.protocol.Request)5 RealmContext (org.forgerock.openam.rest.RealmContext)5 SessionContext (org.forgerock.http.session.SessionContext)4 AttributesContext (org.forgerock.services.context.AttributesContext)4 Connection (org.forgerock.json.resource.Connection)3 CreateRequest (org.forgerock.json.resource.CreateRequest)3 SSOTokenID (com.iplanet.sso.SSOTokenID)2 Response (org.forgerock.http.protocol.Response)2 ActionRequest (org.forgerock.json.resource.ActionRequest)2 DeleteRequest (org.forgerock.json.resource.DeleteRequest)2 QueryRequest (org.forgerock.json.resource.QueryRequest)2 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)2 ReadRequest (org.forgerock.json.resource.ReadRequest)2 Requests.newCreateRequest (org.forgerock.json.resource.Requests.newCreateRequest)2 ResourceException (org.forgerock.json.resource.ResourceException)2 Resources.newInternalConnection (org.forgerock.json.resource.Resources.newInternalConnection)2 AdminSubjectContext (org.forgerock.openam.rest.resource.AdminSubjectContext)2