89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington/*
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * The contents of this file are subject to the terms of the Common Development and
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * Distribution License (the License). You may not use this file except in compliance with the
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * License.
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington *
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * specific language governing permission and limitations under the License.
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington *
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * When distributing Covered Software, include this CDDL Header Notice in each file and include
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * Header, with the fields enclosed by brackets [] replaced by your own identifying
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * information: "Portions copyright [year] [name of copyright owner]".
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington *
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * Copyright 2015 ForgeRock AS.
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington */
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonpackage org.forgerock.openam.entitlement.guice;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport static org.forgerock.openam.entitlement.rest.query.AttributeType.STRING;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport static org.forgerock.openam.entitlement.rest.query.AttributeType.TIMESTAMP;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.google.inject.AbstractModule;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.google.inject.Key;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.google.inject.Provider;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.google.inject.TypeLiteral;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.google.inject.name.Names;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.sun.identity.entitlement.Application;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.sun.identity.entitlement.EntitlementException;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.sun.identity.entitlement.Privilege;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.sun.identity.entitlement.PrivilegeManager;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.sun.identity.entitlement.opensso.PolicyPrivilegeManager;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport com.sun.identity.shared.debug.Debug;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.guice.core.GuiceModule;
555ab9bea4ac634fe25ee052a856f03a2b751439Andrew Forrestimport org.forgerock.json.resource.CollectionResourceProvider;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.json.resource.RequestType;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.json.resource.ResourceException;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.entitlement.rest.ApplicationsResource;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.entitlement.rest.EntitlementEvaluatorFactory;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.entitlement.rest.JsonPolicyParser;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.entitlement.rest.PolicyEvaluatorFactory;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.entitlement.rest.PolicyParser;
555ab9bea4ac634fe25ee052a856f03a2b751439Andrew Forrestimport org.forgerock.openam.entitlement.rest.PolicyResource;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.entitlement.rest.PolicyStoreProvider;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.entitlement.rest.PrivilegePolicyStoreProvider;
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrestimport org.forgerock.openam.entitlement.rest.XacmlRouterProvider;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.entitlement.rest.query.QueryAttribute;
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrestimport org.forgerock.openam.entitlement.service.DefaultPrivilegeManagerFactory;
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrestimport org.forgerock.openam.entitlement.service.PrivilegeManagerFactory;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.forgerock.openam.errors.ExceptionMappingHandler;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonimport org.restlet.routing.Router;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrestimport javax.inject.Singleton;
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrestimport java.util.Collections;
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrestimport java.util.EnumMap;
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrestimport java.util.HashMap;
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrestimport java.util.Map;
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrest
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington/**
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * Guice module for binding entitlement REST endpoints.
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington *
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * @since 13.0.0
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington */
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington@GuiceModule
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunningtonpublic class EntitlementRestGuiceModule extends AbstractModule {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington @Override
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington protected void configure() {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(Key.get(Router.class, Names.named("XacmlRouter"))).toProvider(XacmlRouterProvider.class)
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .in(Singleton.class);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington // PolicyResource configuration
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(PrivilegeManager.class).to(PolicyPrivilegeManager.class);
0fe99aaa2652cb97bbd71876ea28074e6241c3c0Andrew Forrest bind(PrivilegeManagerFactory.class).to(DefaultPrivilegeManagerFactory.class);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(new TypeLiteral<ExceptionMappingHandler<EntitlementException, ResourceException>>() {})
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .to(EntitlementsExceptionMappingHandler.class);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(PolicyParser.class).to(JsonPolicyParser.class);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(PolicyStoreProvider.class).to(PrivilegePolicyStoreProvider.class);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(new TypeLiteral<Map<Integer, Integer>>() {})
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .annotatedWith(Names.named(EntitlementsExceptionMappingHandler.RESOURCE_ERROR_MAPPING))
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .toProvider(EntitlementsResourceErrorMappingProvider.class)
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .asEagerSingleton();
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington // Error code overrides for particular request types. Maps NOT FOUND errors on Create requests to BAD REQUESTs.
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington final Map<RequestType, Map<Integer, Integer>> errorCodeOverrides =
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington new EnumMap<RequestType, Map<Integer, Integer>>(RequestType.class);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington errorCodeOverrides.put(RequestType.CREATE,
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington Collections.singletonMap(ResourceException.NOT_FOUND, ResourceException.BAD_REQUEST));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(new TypeLiteral<Map<RequestType, Map<Integer, Integer>>>() {})
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .annotatedWith(Names.named(EntitlementsExceptionMappingHandler.REQUEST_TYPE_ERROR_OVERRIDES))
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .toInstance(errorCodeOverrides);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(new TypeLiteral<Map<Integer, Integer>>() {})
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .annotatedWith(Names.named(EntitlementsExceptionMappingHandler.DEBUG_TYPE_OVERRIDES))
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .toProvider(EntitlementsResourceDebugMappingProvider.class)
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .asEagerSingleton();
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(new TypeLiteral<Map<String, QueryAttribute>>() {})
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .annotatedWith(Names.named(PrivilegePolicyStoreProvider.POLICY_QUERY_ATTRIBUTES))
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .toProvider(PolicyQueryAttributesMapProvider.class)
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .asEagerSingleton();
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(PolicyEvaluatorFactory.class).to(EntitlementEvaluatorFactory.class).in(Singleton.class);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington bind(new TypeLiteral<Map<String, QueryAttribute>>() {})
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .annotatedWith(Names.named(ApplicationsResource.APPLICATION_QUERY_ATTRIBUTES))
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .toProvider(ApplicationQueryAttributesMapProvider.class)
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington .asEagerSingleton();
555ab9bea4ac634fe25ee052a856f03a2b751439Andrew Forrest
555ab9bea4ac634fe25ee052a856f03a2b751439Andrew Forrest bind(CollectionResourceProvider.class).annotatedWith(Names.named("PolicyResource")).to(PolicyResource.class);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington /**
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * Provides the mapping between entitlements exceptions and CREST resource exceptions, based on the entitlements
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * error code. Anything not explicitly mapped here will be treated as an internal server error.
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington */
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington private static class EntitlementsResourceErrorMappingProvider implements Provider<Map<Integer, Integer>> {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington @Override
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington public Map<Integer, Integer> get() {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington final Map<Integer, Integer> handlers = new HashMap<Integer, Integer>();
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.EMPTY_PRIVILEGE_NAME, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.NULL_ENTITLEMENT, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.UNSUPPORTED_OPERATION, ResourceException.NOT_SUPPORTED);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_XML, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_WSDL_LOCATION, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.MISSING_PRIVILEGE_JSON, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.SESSION_HAS_EXPIRED, ResourceException.FORBIDDEN);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_JSON, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.MISSING_PRIVILEGE_NAME, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.NO_SUCH_POLICY, ResourceException.NOT_FOUND);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.APPLICATION_ALREADY_EXISTS, ResourceException.CONFLICT);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.NO_SUCH_REFERRAL_PRIVILEGE, ResourceException.NOT_FOUND);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INCONSISTENT_WILDCARDS, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_PORT, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.MALFORMED_URL, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_RESOURCE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.NO_SUCH_APPLICATION, ResourceException.NOT_FOUND);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.NOT_FOUND, ResourceException.NOT_FOUND);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.PERMISSION_DENIED, ResourceException.FORBIDDEN);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.SUBJECT_REQUIRED, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_SEARCH_FILTER, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_PROPERTY_VALUE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.START_DATE_AFTER_END_DATE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.MISSING_RESOURCE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.JSON_PARSE_ERROR, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.AUTHENTICATION_ERROR, ResourceException.FORBIDDEN);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_VALUE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.POLICY_NAME_MISMATCH, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.APP_RETRIEVAL_ERROR, ResourceException.NOT_FOUND);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.UNKNOWN_POLICY_CLASS, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.POLICY_CLASS_CAST_EXCEPTION, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.POLICY_CLASS_NOT_INSTANTIABLE,ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.POLICY_CLASS_NOT_ACCESSIBLE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_PROPERTY_VALUE_UNKNOWN_VALUE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.POLICY_ALREADY_EXISTS, ResourceException.CONFLICT);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.END_IP_BEFORE_START_IP, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.IP_CONDITION_CONFIGURATION_REQUIRED, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.PAIR_PROPERTY_NOT_DEFINED, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.APP_NOT_CREATED_POLICIES_EXIST, ResourceException.CONFLICT);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_APP_TYPE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_APP_REALM, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.PROPERTY_CONTAINS_BLANK_VALUE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.APPLICATION_NAME_MISMATCH, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_CLASS, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS, ResourceException.CONFLICT);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.NO_SUCH_RESOURCE_TYPE, ResourceException.NOT_FOUND);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.RESOURCE_TYPE_IN_USE, ResourceException.CONFLICT);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.MISSING_RESOURCE_TYPE_NAME, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.RESOURCE_TYPE_REFERENCED, ResourceException.CONFLICT);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.INVALID_RESOURCE_TYPE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.POLICY_DEFINES_INVALID_RESOURCE_TYPE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.MISSING_RESOURCE_TYPE, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.CONDITION_EVALUATION_FAILED, ResourceException.INTERNAL_ERROR);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.RESOURCE_TYPE_ID_MISMATCH, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.NO_RESOURCE_TYPE_EXPECTED, ResourceException.BAD_REQUEST);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington return handlers;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington public static Map<Integer, Integer> getEntitlementsErrorHandlers() {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington return new EntitlementsResourceErrorMappingProvider().get();
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington private static class EntitlementsResourceDebugMappingProvider implements Provider<Map<Integer, Integer>> {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington @Override
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington public Map<Integer, Integer> get() {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington final Map<Integer, Integer> handlers = new HashMap<Integer, Integer>();
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington handlers.put(EntitlementException.NO_SUCH_POLICY, Debug.MESSAGE);
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington return handlers;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington /**
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * Defines all allowed query attributes in queries against the policy endpoint.
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington */
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington private static class PolicyQueryAttributesMapProvider implements Provider<Map<String, QueryAttribute>> {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington @Override
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington public Map<String, QueryAttribute> get() {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington final Map<String, QueryAttribute> attributes = new HashMap<String, QueryAttribute>();
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("name", new QueryAttribute(STRING, Privilege.NAME_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("description", new QueryAttribute(STRING, Privilege.DESCRIPTION_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("applicationName", new QueryAttribute(STRING, Privilege.APPLICATION_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("createdBy", new QueryAttribute(STRING, Privilege.CREATED_BY_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("creationDate", new QueryAttribute(TIMESTAMP, Privilege.CREATION_DATE_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("lastModifiedBy", new QueryAttribute(STRING, Privilege.LAST_MODIFIED_BY_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("lastModifiedDate", new QueryAttribute(TIMESTAMP, Privilege.LAST_MODIFIED_DATE_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("resourceTypeUuid", new QueryAttribute(STRING, Privilege.RESOURCE_TYPE_UUID_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington return attributes;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington /**
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington * Defines all allowed query attributes in queries against the application endpoint.
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington */
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington private static class ApplicationQueryAttributesMapProvider implements Provider<Map<String, QueryAttribute>> {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington @Override
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington public Map<String, QueryAttribute> get() {
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington final Map<String, QueryAttribute> attributes = new HashMap<String, QueryAttribute>();
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("name", new QueryAttribute(STRING, Application.NAME_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("description", new QueryAttribute(STRING, Application.DESCRIPTION_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("createdBy", new QueryAttribute(STRING, Application.CREATED_BY_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("creationDate", new QueryAttribute(TIMESTAMP, Application.CREATION_DATE_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("lastModifiedBy", new QueryAttribute(STRING, Application.LAST_MODIFIED_BY_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington attributes.put("lastModifiedDate", new QueryAttribute(TIMESTAMP, Application.LAST_MODIFIED_DATE_SEARCH_ATTRIBUTE));
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington return attributes;
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington }
89c76a8c99f25ef6d24c3642f95dde19c5fd4d05Phill Cunnington}