Search in sources :

Example 1 with ApplicationTypeWrapper

use of org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper 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 2 with ApplicationTypeWrapper

use of org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper 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 3 with ApplicationTypeWrapper

use of org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper in project OpenAM by OpenRock.

the class ApplicationTypesResourceTest method setUp.

@BeforeMethod
public void setUp() {
    typeManager = mock(ApplicationTypeManagerWrapper.class);
    testResource = new ApplicationTypesResource(typeManager, mock(Debug.class));
    mockApplicationTypeManager = mock(ApplicationTypeManagerWrapper.class);
    mockDebug = mock(Debug.class);
    testResource = new ApplicationTypesResource(mockApplicationTypeManager, mockDebug) {

        @Override
        protected List<ResourceResponse> getResourceResponses(List<ApplicationTypeWrapper> types) {
            return null;
        }
    };
}
Also used : ApplicationTypeWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper) ApplicationTypeManagerWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeManagerWrapper) List(java.util.List) ApplicationTypesResource(org.forgerock.openam.entitlement.rest.ApplicationTypesResource) Debug(com.sun.identity.shared.debug.Debug) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ApplicationTypeWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper)3 ApplicationType (com.sun.identity.entitlement.ApplicationType)2 Subject (javax.security.auth.Subject)2 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)2 ResourceResponse (org.forgerock.json.resource.ResourceResponse)2 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)2 Debug (com.sun.identity.shared.debug.Debug)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 NotFoundException (org.forgerock.json.resource.NotFoundException)1 ApplicationTypesResource (org.forgerock.openam.entitlement.rest.ApplicationTypesResource)1 ApplicationTypeManagerWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeManagerWrapper)1 BeforeMethod (org.testng.annotations.BeforeMethod)1