ForgerockRestGuiceModule.java revision 70a82a3cf851abe9162f9cac5fc3342d7f956cd0
/*
* Copyright 2014-2015 ForgeRock AS.
*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*/
/**
* Guice Module for configuring bindings for the AuthenticationRestService classes.
*/
public class ForgerockRestGuiceModule extends AbstractModule {
/**
* {@inheritDoc}
*/
protected void configure() {
public SignatureUtil get() {
return SignatureUtil.getInstance();
}
});
// PolicyResource configuration
.to(EntitlementsExceptionMappingHandler.class);
.asEagerSingleton();
// Error code overrides for particular request types. Maps NOT FOUND errors on Create requests to BAD REQUESTs.
.asEagerSingleton();
})
.asEagerSingleton();
.asEagerSingleton();
// Scripting configuration
.to(ScriptExceptionMappingHandler.class);
install(new FactoryModuleBuilder()
.build(SmsRequestHandlerFactory.class));
install(new FactoryModuleBuilder()
.build(SmsCollectionProviderFactory.class));
install(new FactoryModuleBuilder()
.build(SmsSingletonProviderFactory.class));
install(new FactoryModuleBuilder()
.build(SmsGlobalSingletonProviderFactory.class));
}
return new PromisedRequestHandlerImpl(router);
}
}
@Named("OAuth2Router")
return restEndpoints.getOAuth2ServiceRouter();
}
@Named("UsersResource")
return new IdentityResourceV1(IdentityResourceV1.USER_TYPE, mailServerLoader, identityResourceUtils,
}
@Named("GroupsResource")
return new IdentityResourceV1(IdentityResourceV1.GROUP_TYPE, mailServerLoader, identityResourceUtils,
}
public RestLog getRestLog() {
return new RestLog();
}
@Named("AgentsResource")
return new IdentityResourceV1(IdentityResourceV1.AGENT_TYPE, mailServerLoader, identityResourceUtils,
}
@Named("UsersResource")
return new IdentityResourceV2(IdentityResourceV2.USER_TYPE, mailServerLoader, identityResourceUtils,
}
@Named("GroupsResource")
return new IdentityResourceV2(IdentityResourceV2.GROUP_TYPE, mailServerLoader, identityResourceUtils,
}
@Named("AgentsResource")
return new IdentityResourceV2(IdentityResourceV2.AGENT_TYPE, mailServerLoader, identityResourceUtils,
}
}
boolean coreTokenResourceEnabled = SystemProperties.getAsBoolean(Constants.CORE_TOKEN_RESOURCE_ENABLED);
}
return new EntitlementsResourceErrorMappingProvider().get();
}
return definitions;
}
@Named("ServerAttributeSyntax")
syntaxProperties.load(getClass().getClassLoader().getResourceAsStream("validserverconfig.properties"));
return syntaxProperties;
}
@Named("ServerAttributeTitles")
return titleProperties;
}
/**
* Provides the mapping between entitlements exceptions and CREST resource exceptions, based on the entitlements
* error code. Anything not explicitly mapped here will be treated as an internal server error.
*/
private static class EntitlementsResourceErrorMappingProvider implements Provider<Map<Integer, Integer>> {
handlers.put(EntitlementException.INVALID_PROPERTY_VALUE_UNKNOWN_VALUE, ResourceException.BAD_REQUEST);
handlers.put(EntitlementException.IP_CONDITION_CONFIGURATION_REQUIRED, ResourceException.BAD_REQUEST);
handlers.put(EntitlementException.POLICY_DEFINES_INVALID_RESOURCE_TYPE, ResourceException.BAD_REQUEST);
return handlers;
}
}
private static class EntitlementsResourceDebugMappingProvider implements Provider<Map<Integer, Integer>> {
return handlers;
}
}
/**
* Defines all allowed query attributes in queries against the policy endpoint.
*/
private static class PolicyQueryAttributesMapProvider implements Provider<Map<String, QueryAttribute>> {
attributes.put("applicationName", new QueryAttribute(STRING, Privilege.APPLICATION_SEARCH_ATTRIBUTE));
attributes.put("creationDate", new QueryAttribute(TIMESTAMP, Privilege.CREATION_DATE_SEARCH_ATTRIBUTE));
attributes.put("lastModifiedBy", new QueryAttribute(STRING, Privilege.LAST_MODIFIED_BY_SEARCH_ATTRIBUTE));
attributes.put("lastModifiedDate", new QueryAttribute(TIMESTAMP, Privilege.LAST_MODIFIED_DATE_SEARCH_ATTRIBUTE));
attributes.put("resourceTypeUuid", new QueryAttribute(STRING, Privilege.RESOURCE_TYPE_UUID_SEARCH_ATTRIBUTE));
return attributes;
}
}
/**
* Defines all allowed query attributes in queries against the application endpoint.
*/
private static class ApplicationQueryAttributesMapProvider implements Provider<Map<String, QueryAttribute>> {
attributes.put("description", new QueryAttribute(STRING, Application.DESCRIPTION_SEARCH_ATTRIBUTE));
attributes.put("creationDate", new QueryAttribute(TIMESTAMP, Application.CREATION_DATE_SEARCH_ATTRIBUTE));
attributes.put("lastModifiedBy", new QueryAttribute(STRING, Application.LAST_MODIFIED_BY_SEARCH_ATTRIBUTE));
attributes.put("lastModifiedDate", new QueryAttribute(TIMESTAMP, Application.LAST_MODIFIED_DATE_SEARCH_ATTRIBUTE));
return attributes;
}
}
}