use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class UmaEmailService method getMailServer.
private MailServer getMailServer(String realm) throws MessagingException {
try {
ServiceConfigManager mailmgr = new ServiceConfigManager(AccessController.doPrivileged(AdminTokenAction.getInstance()), MailServerImpl.SERVICE_NAME, MailServerImpl.SERVICE_VERSION);
ServiceConfig mailscm = mailmgr.getOrganizationConfig(realm, null);
if (!mailscm.exists()) {
throw new MessagingException("EmailService is not configured for realm, " + realm);
}
Map<String, Set<String>> mailattrs = mailscm.getAttributes();
String mailServerClass = mailattrs.get("forgerockMailServerImplClassName").iterator().next();
return Class.forName(mailServerClass).asSubclass(MailServer.class).getDeclaredConstructor(String.class).newInstance(realm);
} catch (IllegalAccessException | SSOException | InstantiationException | ClassNotFoundException | InvocationTargetException | NoSuchMethodException | SMSException e) {
throw new MessagingException("Failed to load mail server", e);
}
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class AMAuthConfigUtils method removeNamedConfig.
/**
* Removes an authentication configuration defined in
* <code>iPlanetAMAuthConfiguration</code> service. This method will be
* used by console to manage configurations for different services.
*
* @param configName Name of the authentication configuration.
* @param orgName Organization DN.
* @param token Single Sign On token.
* @throws SMSException if failed to delete the configuration because
* of SM Exception.
* @throws SSOException if single sign on token is not valid.
* @throws AMConfigurationException if <code>configName</code> is null
* or not defined .
*/
public static void removeNamedConfig(String configName, String orgName, SSOToken token) throws SMSException, SSOException, AMConfigurationException {
if (debug.messageEnabled()) {
debug.message("removeNamedConfig name=" + configName + ",org=" + orgName);
}
// Check if name is valid
if (configName == null) {
throw new AMConfigurationException(bundleName, "null-name");
}
// Get service config for named config node
ServiceConfigManager scm = new ServiceConfigManager(SERVICE_NAME, token);
ServiceConfig oConfig = scm.getOrganizationConfig(orgName, null);
if (oConfig == null) {
// service not registered
throw new AMConfigurationException(bundleName, "service-not-registered");
}
ServiceConfig namedConfig = oConfig.getSubConfig(NAMED_CONFIGURATION);
if (namedConfig == null) {
// named configuration not exists
throw new AMConfigurationException(bundleName, "named-config-not-defined");
}
// get the config
ServiceConfig pConfig = namedConfig.getSubConfig(configName);
if (pConfig == null) {
// configuration does not exist
throw new AMConfigurationException(bundleName, "config-not-exists");
}
// do the removal of config
namedConfig.removeSubConfig(configName);
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class AMAuthConfigUtils method getAllNamedConfig.
/**
* Returns all the authentication configurations defined in
* <code>iPlanetAMAuthConfiguration</code> service. This method will be
* used by console to manage configurations for different services.
*
* @param orgName Organization DN.
* @param token Single Sign On token.
* @return Set which contains all the configuration names
* @throws SMSException if failed to get configurations because
* of SM Exception.
* @throws SSOException if single sign on token is not valid.
*/
public static Set getAllNamedConfig(String orgName, SSOToken token) throws SMSException, SSOException {
if ((orgName != null) && (orgName.length() != 0)) {
orgName = orgName.toLowerCase();
}
if (debug.messageEnabled()) {
debug.message("getAllNamedConfig org=" + orgName);
}
// Get the named config node
ServiceConfigManager scm = new ServiceConfigManager(token, SERVICE_NAME, SERVICE_VERSION);
ServiceConfig oConfig = scm.getOrganizationConfig(orgName, null);
if (oConfig == null) {
// service not registered
return Collections.EMPTY_SET;
}
ServiceConfig namedConfig = oConfig.getSubConfig(NAMED_CONFIGURATION);
if (namedConfig == null) {
// named configuration not exists
return Collections.EMPTY_SET;
}
// get all sub config names
return namedConfig.getSubConfigNames("*");
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class EntitiesModelImpl method repoExists.
public boolean repoExists(String realmName) {
try {
ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, getUserSSOToken());
ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realmName, null);
if (cfg == null) {
return false;
}
Set names = cfg.getSubConfigNames();
if (names == null || names.isEmpty()) {
return false;
}
return true;
} catch (SMSException e) {
String strError = getErrorString(e);
String[] paramsEx = { realmName, strError };
logEvent("SMS_EXCEPTION_GET_ID_REPO_NAMES", paramsEx);
return false;
} catch (SSOException e) {
String strError = getErrorString(e);
String[] paramsEx = { realmName, strError };
logEvent("SSO_EXCEPTION_GET_ID_REPO_NAMES", paramsEx);
return false;
}
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class AMServiceUtils method getOrgConfig.
/**
* Get organization config for the service
*
* @param token
* SSOToken
* @param orgDN
* DN of the org or org unit
* @param serviceName
* Service Name
* @return ServiceConfig of the organization for the service
*/
public static ServiceConfig getOrgConfig(SSOToken token, String orgDN, String serviceName) throws SSOException, AMException {
try {
ServiceConfigManager scm = new ServiceConfigManager(serviceName, token);
ServiceConfig sc = scm.getOrganizationConfig(orgDN, null);
DN theOrgDN = DN.valueOf(orgDN);
if (theOrgDN.equals(DN.valueOf(SMSEntry.getAMSdkBaseDN())) && sc != null) {
Map avPair = sc.getAttributes();
Set subConfigs = sc.getSubConfigNames();
if (avPair.isEmpty() && (subConfigs == null || subConfigs.isEmpty())) {
return null;
}
}
return sc;
} catch (ServiceNotFoundException ex) {
Object[] args = { serviceName };
String locale = AMCommonUtils.getUserLocale(token);
throw new AMException(AMSDKBundle.getString("481", args, locale), "481", args);
} catch (ServiceAlreadyExistsException ex) {
Object[] args = { serviceName };
String locale = AMCommonUtils.getUserLocale(token);
throw new AMException(AMSDKBundle.getString("479", args, locale), "479", args);
} catch (SMSException ex) {
Object[] args = { serviceName };
String locale = AMCommonUtils.getUserLocale(token);
throw new AMException(AMSDKBundle.getString("482", args, locale), "482", args);
}
}
Aggregations