use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class AuthIdHelper method getSigningKey.
/**
* Retrieves the secret key to use to sign and verify the JWT.
*
* @param orgName The organisation name for the realm being authenticated against.
* @return The signing key.
*/
private SecretKey getSigningKey(String orgName) throws RestAuthException {
SSOToken token = coreServicesWrapper.getAdminToken();
try {
ServiceConfigManager scm = coreServicesWrapper.getServiceConfigManager(AUTH_SERVICE_NAME, token);
ServiceConfig orgConfig = scm.getOrganizationConfig(orgName, null);
byte[] key = Base64.decode(CollectionHelper.getMapAttr(orgConfig.getAttributes(), SHARED_SECRET_ATTR));
return new SecretKeySpec(key, "RAW");
} catch (SMSException | SSOException | NullPointerException e) {
throw new RestAuthException(ResourceException.INTERNAL_ERROR, e);
}
}
use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class ConfiguredSocialAuthServices method filterConfigs.
@Override
protected Set<String> filterConfigs(Set<String> namedConfigs, ServiceConfig parentConfig, String realm, SSOToken adminToken) {
AMAuthenticationManager authMgr;
try {
authMgr = new AMAuthenticationManager(adminToken, realm);
} catch (AMConfigurationException e) {
debug.warning("Could not load authentication manager for realm: " + realm, e);
return Collections.EMPTY_SET;
}
Set<String> configs = new TreeSet<String>();
for (String config : namedConfigs) {
try {
ServiceConfig authConfig = parentConfig.getSubConfig(config);
Set<String> chainConfig = (Set<String>) authConfig.getAttributes().get(AMAuthConfigUtils.ATTR_NAME);
AppConfigurationEntry[] chain = AMAuthConfigUtils.parseValues(chainConfig.iterator().next());
for (int i = 0; i < chain.length; i++) {
if (getType(authMgr, chain[i]).equals(OAUTH2_TYPE)) {
// There's an OAuth2 module in the chain, so this could be a social authn chain
configs.add(config);
}
}
} catch (SMSException e) {
if (debug.messageEnabled()) {
debug.message("Not using auth chain as couldn't get config: " + config, e);
}
} catch (SSOException e) {
if (debug.warningEnabled()) {
debug.warning("Invalid SSO Token when trying to get config for " + config, e);
}
}
}
return configs;
}
use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class DirectoryServicesImpl method isExternalGetAttributesEnabled.
/**
* Method to check if the CallBack plugins are enabled for reading external
* attributes.
*/
protected static boolean isExternalGetAttributesEnabled(String orgDN) {
// Obtain the ServiceConfig
Set attrVal;
SSOToken token = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
try {
// Get the org config
ServiceConfig sc = AMServiceUtils.getOrgConfig(token, orgDN, ADMINISTRATION_SERVICE);
if (sc != null) {
Map attributes = sc.getAttributes();
attrVal = (Set) attributes.get(EXTERNAL_ATTRIBUTES_FETCH_ENABLED_ATTR);
} else {
attrVal = getDefaultGlobalConfig(token, EXTERNAL_ATTRIBUTES_FETCH_ENABLED_ATTR);
}
} catch (Exception ee) {
attrVal = getDefaultGlobalConfig(token, EXTERNAL_ATTRIBUTES_FETCH_ENABLED_ATTR);
}
boolean enabled = false;
if (attrVal != null && !attrVal.isEmpty()) {
String val = (String) attrVal.iterator().next();
enabled = (val.equalsIgnoreCase("true"));
}
if (debug.messageEnabled()) {
debug.message("DirectoryServicesImpl." + "isExternalGetAttributeEnabled() = " + enabled);
}
return enabled;
}
use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class AMAuthenticationManager method createAuthenticationInstance.
/**
* Creates an <code>AMAuthenticationInstance</code> instance with the
* specified parameters.
*
* @param name Name of the authentication module instance.
* @param type Type of the authentication module instance.
* @param attributes A Map of parameters for this module instance.
* @return <code>AMAuthenticationInstance</code> object is newly created.
* @throws AMConfigurationException if error occurred during the
* authentication creation.
*/
public AMAuthenticationInstance createAuthenticationInstance(String name, String type, Map attributes) throws AMConfigurationException {
if (name.indexOf(' ') != -1) {
throw new AMConfigurationException(BUNDLE_NAME, "invalidAuthenticationInstanceName", null);
}
Set moduleTypes = getAuthenticationTypes();
if (!moduleTypes.contains(type)) {
throw new AMConfigurationException(BUNDLE_NAME, "wrongType", new Object[] { type });
}
AMAuthenticationInstance instance = getAuthenticationInstance(name);
if (instance != null) {
if (instance.getServiceConfig() != null) {
throw new AMConfigurationException(BUNDLE_NAME, "authInstanceExist", new Object[] { name });
} else {
throw new AMConfigurationException(BUNDLE_NAME, "authInstanceIsGlobal", new Object[] { name });
}
}
String serviceName = getServiceName(type);
ServiceSchema schema = null;
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
schema = ssm.getSchema(SchemaType.GLOBAL);
} catch (SSOException e) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("Token doesn't have access to service: " + token + " -> " + serviceName);
}
} catch (SMSException e) {
// normal exception for service without global configuration.
// no need to log anything.
}
try {
OrganizationConfigManager ocm = new OrganizationConfigManager(token, realm);
// Check if service is assigned
if (!ocm.getAssignedServices().contains(serviceName)) {
ocm.assignService(serviceName, null);
}
ServiceConfig orgConfig = ocm.getServiceConfig(serviceName);
if (orgConfig == null) {
orgConfig = ocm.addServiceConfig(serviceName, null);
}
ServiceConfig subConfig = orgConfig;
if (!name.equals(type)) {
orgConfig.addSubConfig(name, ISAuthConstants.SERVER_SUBSCHEMA, 0, attributes);
subConfig = orgConfig.getSubConfig(name);
} else {
// if the module instance name equals to its type, set the
// the attributes in its organization config, not sub config.
subConfig.setAttributes(attributes);
}
//AMAuthLevelManager listeners are in place, so let's reinitialize to be on the safe side.
if (!SystemProperties.isServerMode()) {
buildModuleInstanceForService(realm, serviceName);
}
return new AMAuthenticationInstance(name, type, subConfig, schema);
} catch (Exception e) {
throw new AMConfigurationException(e);
}
}
use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class GetSubConfiguration method printGlobalSubConfig.
private void printGlobalSubConfig(String serviceName, String subConfigName) throws CLIException {
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String[] params = { subConfigName, serviceName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_SUB_CONFIGURATION", params);
try {
ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminSSOToken);
ServiceConfig sc = scm.getGlobalConfig(null);
printSubConfig(sc, subConfigName);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_SUB_CONFIGURATION", params);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-sub-configuration-succeed"), (Object[]) params));
} catch (SSOException e) {
String[] args = { subConfigName, serviceName, e.getMessage() };
debugError("GetSubConfiguration.printGlobalSubConfig", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SUB_CONFIGURATION", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { subConfigName, serviceName, e.getMessage() };
debugError("GetSubConfiguration.printGlobalSubConfig", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SUB_CONFIGURATION", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations