Search in sources :

Example 6 with ApplicationType

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

the class ApplicationTypesResource method readInstance.

/**
     * Reads the details of a single instance of an {@link ApplicationType} - the instance
     * referred to by the passed-in resourceId.
     *
     * The user's {@link SecurityContext} must indicate they are a user with administrator-level access.
     *
     * @param context {@inheritDoc}
     * @param resourceId {@inheritDoc}
     * @param request {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId, ReadRequest request) {
    //auth
    final Subject mySubject = getContextSubject(context);
    if (mySubject == null) {
        debug.error("ApplicationsTypesResource :: READ : Unknown Subject");
        return new InternalServerErrorException().asPromise();
    }
    final String principalName = PrincipalRestUtils.getPrincipalNameFromSubject(mySubject);
    final ApplicationType applType = typeManager.getApplicationType(mySubject, resourceId);
    final ApplicationTypeWrapper wrap = new ApplicationTypeWrapper(applType);
    if (applType == null) {
        if (debug.errorEnabled()) {
            debug.error("ApplicationTypesResource :: READ by " + principalName + ": Requested application type short name not found: " + resourceId);
        }
        return new NotFoundException().asPromise();
    }
    try {
        final ResourceResponse resource = newResourceResponse(resourceId, String.valueOf(System.currentTimeMillis()), JsonValue.json(wrap.toJsonValue()));
        return newResultPromise(resource);
    } catch (IOException e) {
        if (debug.errorEnabled()) {
            debug.error("ApplicationTypesResource :: READ by " + principalName + ": Could not jsonify class associated with defined Type: " + resourceId, e);
        }
        return new InternalServerErrorException().asPromise();
    }
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) ApplicationTypeWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotFoundException(org.forgerock.json.resource.NotFoundException) IOException(java.io.IOException) Subject(javax.security.auth.Subject)

Example 7 with ApplicationType

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

the class ApplicationTypesResource method queryCollection.

/**
     * Reads the details of all {@link ApplicationType}s in the system.
     *
     * The user's {@link SecurityContext} must indicate they are a user with administrator-level access.
     *
     * @param context {@inheritDoc}
     * @param request {@inheritDoc}
     * @param handler {@inheritDoc}
     */
@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
    //auth
    final Subject mySubject = getContextSubject(context);
    if (mySubject == null) {
        debug.error("ApplicationsTypesResource :: QUERY : Unknown Subject");
        return new InternalServerErrorException().asPromise();
    }
    final String principalName = PrincipalRestUtils.getPrincipalNameFromSubject(mySubject);
    //select
    final Set<String> appTypeNames = typeManager.getApplicationTypeNames(mySubject);
    List<ApplicationTypeWrapper> appTypes = new LinkedList<>();
    for (String appTypeName : appTypeNames) {
        final ApplicationType type = typeManager.getApplicationType(mySubject, appTypeName);
        final ApplicationTypeWrapper wrap = new ApplicationTypeWrapper(type);
        if (type != null) {
            appTypes.add(wrap);
        } else {
            if (debug.warningEnabled()) {
                debug.warning("ApplicationTypesResource :: QUERY by " + principalName + ": ApplicationType was not found: " + appTypeName);
            }
        }
    }
    final List<ResourceResponse> applicationsList = getResourceResponses(appTypes);
    QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
    return QueryResponsePresentation.perform(handler, request, applicationsList);
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) ApplicationTypeWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) Subject(javax.security.auth.Subject) LinkedList(java.util.LinkedList)

Example 8 with ApplicationType

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

the class UpgradeEntitlementSubConfigsStep method addMissingActions.

/**
     * Adds the missing actions to their corresponding application type's.
     *
     * @throws UpgradeException If there was an error while updating the application type.
     */
private void addMissingActions() throws UpgradeException {
    for (final Map.Entry<String, Map<String, Boolean>> entry : missingActions.entrySet()) {
        final String name = entry.getKey();
        final Map<String, Boolean> actions = entry.getValue();
        try {
            UpgradeProgress.reportStart(AUDIT_MODIFIED_TYPE_START, name);
            if (DEBUG.messageEnabled()) {
                DEBUG.message("Modifying application type " + name + " ; adding actions: " + actions);
            }
            final ApplicationType type = getType(name);
            type.getActions().putAll(actions);
            entitlementService.storeApplicationType(type);
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
        } catch (EntitlementException ee) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException(ee);
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ApplicationType(com.sun.identity.entitlement.ApplicationType) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashMap(java.util.HashMap) Map(java.util.Map) EntitlementUtils.resourceTypeFromMap(org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap)

Example 9 with ApplicationType

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

the class UpgradeEntitlementSubConfigsStep method captureMissingActions.

/**
     * Compares the provided subconfig element's action list against what is currently present in the existing
     * application type definition and captures the missing entries.
     *
     * @param name The name of the subconfig's element we're interested in
     * @param subConfig The new application type's XML representation.
     */
private void captureMissingActions(final String name, final Node subConfig) {
    ApplicationType applicationType = getType(name);
    if (applicationType != null) {
        Map<String, Boolean> existingActions = applicationType.getActions();
        Map<String, Boolean> newActions = getActions(parseAttributeValuePairTags(subConfig));
        if (!existingActions.equals(newActions)) {
            newActions.keySet().removeAll(existingActions.keySet());
            missingActions.put(name, newActions);
        }
    }
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType)

Example 10 with ApplicationType

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

the class ApplicationTypesResourceTest method shouldReadInstanceCorrectly.

@Test
public void shouldReadInstanceCorrectly() throws IllegalAccessException, InstantiationException, ExecutionException, InterruptedException {
    //given
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject subject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(subject);
    ReadRequest request = mock(ReadRequest.class);
    ApplicationType mockApplicationType = new ApplicationType("test", null, null, null, null);
    given(mockApplicationTypeManager.getApplicationType(subject, "test")).willReturn(mockApplicationType);
    //when
    Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
    //then
    assertTrue(result.get().getId().equals("test"));
}
Also used : Context(org.forgerock.services.context.Context) ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ApplicationType(com.sun.identity.entitlement.ApplicationType) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Aggregations

ApplicationType (com.sun.identity.entitlement.ApplicationType)20 EntitlementException (com.sun.identity.entitlement.EntitlementException)6 Set (java.util.Set)6 Application (com.sun.identity.entitlement.Application)5 HashSet (java.util.HashSet)5 Subject (javax.security.auth.Subject)5 CLIException (com.sun.identity.cli.CLIException)3 List (java.util.List)3 ResourceResponse (org.forgerock.json.resource.ResourceResponse)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)2 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)2 ApplicationTypeWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper)2 EntitlementUtils.resourceTypeFromMap (org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap)2 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)2 Test (org.testng.annotations.Test)2 Node (org.w3c.dom.Node)2 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1