use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class VersionBehaviourConfigListener method updateSettings.
private void updateSettings() {
try {
ServiceConfig serviceConfig = mgr.getGlobalConfig(null);
String versionBehaviour = ServiceConfigUtils.getStringAttribute(serviceConfig, VERSION_BEHAVIOUR_ATTRIBUTE);
defaultVersionBehaviour = DefaultVersionBehaviour.valueOf(versionBehaviour.toUpperCase());
warningEnabled = ServiceConfigUtils.getBooleanAttribute(serviceConfig, WARNING_BEHAVIOUR_ATTRIBUTE);
if (debug.messageEnabled()) {
debug.message("Successfully updated rest version behaviour settings to " + versionBehaviour);
}
} catch (Exception e) {
debug.error("Not able to set version behaviour for rest endpoints", e);
}
}
use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class MailService method sendEmail.
// Mapping to known type
@SuppressWarnings("unchecked")
private JsonValue sendEmail(String realm, JsonValue jsonValue) throws ResourceException {
String to = jsonValue.get("to").asString();
if (isBlank(to)) {
throw new BadRequestException("to field is missing");
}
String mimeType = jsonValue.get("type").asString();
if (isBlank(mimeType)) {
throw new BadRequestException("mime type needs to be specified");
}
String subject = jsonValue.get("subject").asString();
String body = jsonValue.get("body").asString();
Map<String, Set<String>> mailConfigAttributes;
try {
ServiceConfigManager configManager = new ServiceConfigManager(RestUtils.getToken(), MailServerImpl.SERVICE_NAME, MailServerImpl.SERVICE_VERSION);
ServiceConfig mailConfig = configManager.getOrganizationConfig(realm, null);
mailConfigAttributes = mailConfig.getAttributes();
} catch (SMSException | SSOException e) {
throw new InternalServerErrorException("Cannot create the service " + MailServerImpl.SERVICE_NAME, e);
}
if (isEmpty(mailConfigAttributes)) {
throw new InternalServerErrorException("No service mail config found for realm " + realm);
}
MailServer mailServer;
try {
String attr = mailConfigAttributes.get(MAIL_SERVER_CLASS).iterator().next();
mailServer = mailServerLoader.load(attr, realm);
} catch (IllegalStateException e) {
throw new InternalServerErrorException("Failed to create mail server", e);
}
if (isBlank(subject)) {
subject = mailConfigAttributes.get(MAIL_SUBJECT).iterator().next();
}
if (isBlank(body)) {
body = mailConfigAttributes.get(MAIL_BODY).iterator().next();
}
try {
mailServer.sendEmail(to, subject, body, mimeType);
} catch (MessagingException e) {
throw new InternalServerErrorException("Failed to send email", e);
}
return json(object(field("success", "true")));
}
use of com.sun.identity.sm.ServiceConfig 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.ServiceConfig 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.ServiceConfig 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("*");
}
Aggregations