Search in sources :

Example 56 with Application

use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.

the class EntitlementUtils method createApplication.

/**
     * Constructs an {@link Application} object based on the provided information.
     *
     * @param applicationType The application's type.
     * @param name The name of the application.
     * @param data The configuration settings for the application.
     * @return An {@link Application} object corresponding to the provided details.
     * @throws InstantiationException If the class settings cannot be instantiated.
     * @throws IllegalAccessException If the class settings cannot be instantiated.
     * @throws EntitlementException If the application class cannot be instantiated.
     */
public static Application createApplication(ApplicationType applicationType, String name, Map<String, Set<String>> data) throws InstantiationException, IllegalAccessException, EntitlementException {
    Application app = ApplicationManager.newApplication(name, applicationType);
    final Set<String> resourceTypeUuids = data.get(CONFIG_RESOURCE_TYPE_UUIDS);
    if (resourceTypeUuids != null) {
        app.addAllResourceTypeUuids(resourceTypeUuids);
    }
    String description = getAttribute(data, CONFIG_DESCRIPTION);
    if (description != null) {
        app.setDescription(description);
    }
    String entitlementCombiner = getAttribute(data, CONFIG_ENTITLEMENT_COMBINER);
    Class combiner = getEntitlementCombiner(entitlementCombiner);
    app.setEntitlementCombiner(combiner);
    Set<String> conditionClassNames = data.get(CONFIG_CONDITIONS);
    if (conditionClassNames != null) {
        app.setConditions(conditionClassNames);
    }
    Set<String> subjectClassNames = data.get(CONFIG_SUBJECTS);
    if (subjectClassNames != null) {
        app.setSubjects(subjectClassNames);
    }
    String saveIndexImpl = getAttribute(data, CONFIG_SAVE_INDEX_IMPL);
    Class saveIndex = ApplicationTypeManager.getSaveIndex(saveIndexImpl);
    if (saveIndex != null) {
        app.setSaveIndex(saveIndex);
    }
    String searchIndexImpl = getAttribute(data, CONFIG_SEARCH_INDEX_IMPL);
    Class searchIndex = ApplicationTypeManager.getSearchIndex(searchIndexImpl);
    if (searchIndex != null) {
        app.setSearchIndex(searchIndex);
    }
    String resourceComp = getAttribute(data, CONFIG_RESOURCE_COMP_IMPL);
    Class resComp = ApplicationTypeManager.getResourceComparator(resourceComp);
    if (resComp != null) {
        app.setResourceComparator(resComp);
    }
    Set<String> attributeNames = data.get(ATTR_NAME_SUBJECT_ATTR_NAMES);
    if (attributeNames != null) {
        app.setAttributeNames(attributeNames);
    }
    final Set<String> meta = data.get(ATTR_NAME_META);
    if (meta != null) {
        app.setMetaData(data.get(ATTR_NAME_META));
    }
    return app;
}
Also used : Application(com.sun.identity.entitlement.Application)

Example 57 with Application

use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.

the class OpenSSOApplicationPrivilegeManager method getAllResourceNamesInAllAppls.

private Map<String, Set<String>> getAllResourceNamesInAllAppls() throws EntitlementException {
    Map<String, Set<String>> map = new HashMap<String, Set<String>>();
    Set<Application> appls = ApplicationManager.getApplications(PrivilegeManager.superAdminSubject, realm);
    for (Application app : appls) {
        map.put(app.getName(), getAllBaseResource(app));
    }
    return map;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Application(com.sun.identity.entitlement.Application)

Example 58 with Application

use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.

the class ApplicationsResource method updateInstance.

/**
     * Updates an existing {@link Application}.
     * The resourceId is the name of the application to update.
     * The new Application may alter this name, but doing so will mean the original
     * resourceId will no longer reference the new Application.
     *
     * @param context {@inheritDoc}
     * @param resourceId {@inheritDoc}
     * @param request {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String resourceId, UpdateRequest request) {
    final Subject mySubject = getContextSubject(context);
    if (mySubject == null) {
        debug.error("ApplicationsResource :: UPDATE : Unknown Subject");
        return new BadRequestException().asPromise();
    }
    final String principalName = PrincipalRestUtils.getPrincipalNameFromSubject(mySubject);
    final ApplicationWrapper wrapp;
    final Application oldApplication;
    try {
        wrapp = createApplicationWrapper(request.getContent(), mySubject);
        if (wrapp.getName() == null) {
            wrapp.setName(resourceId);
        }
        oldApplication = appManager.getApplication(mySubject, getRealm(context), resourceId);
        if (oldApplication == null) {
            throw new EntitlementException(EntitlementException.NOT_FOUND, new String[] { resourceId });
        }
        if (//return conflict
        !resourceId.equals(wrapp.getName()) && appManager.getApplication(mySubject, getRealm(context), wrapp.getName()) != null) {
            throw new EntitlementException(EntitlementException.APPLICATION_ALREADY_EXISTS);
        }
        appManager.updateApplication(oldApplication, wrapp.getApplication(), mySubject, getRealm(context));
        ResourceResponse resource = newResourceResponse(wrapp.getName(), Long.toString(wrapp.getApplication().getLastModifiedDate()), wrapp.toJsonValue());
        return newResultPromise(resource);
    } catch (EntitlementException e) {
        if (debug.errorEnabled()) {
            debug.error("ApplicationsResource :: UPDATE by " + principalName + ": Error performing update operation.", e);
        }
        return exceptionMappingHandler.handleError(context, request, e).asPromise();
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper) ResourceResponse(org.forgerock.json.resource.ResourceResponse) BadRequestException(org.forgerock.json.resource.BadRequestException) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject)

Example 59 with Application

use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.

the class ApplicationsResource method deleteInstance.

/**
     * Deletes an {@link Application} as per the {@link DeleteRequest}.
     *
     * @param context {@inheritDoc}
     * @param resourceId {@inheritDoc}
     * @param request {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String resourceId, DeleteRequest request) {
    //auth
    final Subject callingSubject = getContextSubject(context);
    if (callingSubject == null) {
        debug.error("ApplicationsResource :: DELETE : Unknown Subject");
        return new BadRequestException().asPromise();
    }
    final String realm = getRealm(context);
    final String principalName = PrincipalRestUtils.getPrincipalNameFromSubject(callingSubject);
    try {
        Application oldApp = appManager.getApplication(callingSubject, realm, resourceId);
        if (oldApp == null) {
            throw new EntitlementException(EntitlementException.NO_SUCH_APPLICATION, new String[] { resourceId });
        }
        appManager.deleteApplication(callingSubject, realm, resourceId);
        ResourceResponse resource = newResourceResponse(resourceId, "0", JsonValue.json(JsonValue.object()));
        return newResultPromise(resource);
    } catch (EntitlementException e) {
        if (debug.errorEnabled()) {
            debug.error("ApplicationsResource :: DELETE by " + principalName + ": Application failed to delete the resource specified. ", e);
        }
        return exceptionMappingHandler.handleError(context, request, e).asPromise();
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceResponse(org.forgerock.json.resource.ResourceResponse) BadRequestException(org.forgerock.json.resource.BadRequestException) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject)

Example 60 with Application

use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.

the class ApplicationsResource method readInstance.

/**
     * Reads an instance of an application.
     *
     * @param context {@inheritDoc}
     * @param resourceId {@inheritDoc}
     * @param request {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId, ReadRequest request) {
    final Subject mySubject = getContextSubject(context);
    if (mySubject == null) {
        debug.error("ApplicationsResource :: READ : Unknown Subject");
        return new BadRequestException().asPromise();
    }
    final String realm = getRealm(context);
    final String principalName = PrincipalRestUtils.getPrincipalNameFromSubject(mySubject);
    try {
        final Application app = appManager.getApplication(mySubject, realm, resourceId);
        if (app == null) {
            throw new EntitlementException(EntitlementException.APP_RETRIEVAL_ERROR, new String[] { realm });
        }
        final ApplicationWrapper wrapp = createApplicationWrapper(app, appTypeManagerWrapper);
        ResourceResponse resource = newResourceResponse(resourceId, Long.toString(app.getLastModifiedDate()), wrapp.toJsonValue());
        return newResultPromise(resource);
    } catch (EntitlementException e) {
        if (debug.errorEnabled()) {
            debug.error("ApplicationsResource :: READ by " + principalName + ": Application failed to retrieve the resource specified.", e);
        }
        return exceptionMappingHandler.handleError(context, request, e).asPromise();
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper) ResourceResponse(org.forgerock.json.resource.ResourceResponse) BadRequestException(org.forgerock.json.resource.BadRequestException) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject)

Aggregations

Application (com.sun.identity.entitlement.Application)65 EntitlementException (com.sun.identity.entitlement.EntitlementException)37 Subject (javax.security.auth.Subject)29 ResourceResponse (org.forgerock.json.resource.ResourceResponse)22 Test (org.testng.annotations.Test)22 HashSet (java.util.HashSet)20 JsonValue (org.forgerock.json.JsonValue)18 Set (java.util.Set)16 ResourceException (org.forgerock.json.resource.ResourceException)16 RealmContext (org.forgerock.openam.rest.RealmContext)16 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)16 HashMap (java.util.HashMap)15 ClientContext (org.forgerock.services.context.ClientContext)13 Context (org.forgerock.services.context.Context)13 Matchers.anyString (org.mockito.Matchers.anyString)13 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)10 UpdateRequest (org.forgerock.json.resource.UpdateRequest)9 ApplicationWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper)9 Map (java.util.Map)8 BadRequestException (org.forgerock.json.resource.BadRequestException)7