use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class EntitlementService method createApplicationCollectionConfig.
private ServiceConfig createApplicationCollectionConfig(String realm) throws SMSException, SSOException {
ServiceConfig sc = null;
SSOToken token = SubjectUtils.getSSOToken(getAdminSubject());
ServiceConfigManager mgr = new ServiceConfigManager(SERVICE_NAME, token);
ServiceConfig orgConfig = mgr.getOrganizationConfig(realm, null);
if (orgConfig != null) {
sc = orgConfig.getSubConfig(EntitlementUtils.REGISTERED_APPLICATIONS);
}
if (sc == null) {
orgConfig.addSubConfig(EntitlementUtils.REGISTERED_APPLICATIONS, SCHEMA_APPLICATIONS, 0, Collections.EMPTY_MAP);
sc = orgConfig.getSubConfig(EntitlementUtils.REGISTERED_APPLICATIONS);
}
return sc;
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class AMSetupServlet method updateEmbeddedIdRepo.
/**
* Update Embedded Idrepo instance with new embedded opends isntance.
*/
private static void updateEmbeddedIdRepo(String orgName, String configName, String entry) throws SMSException, SSOException {
SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
ServiceConfigManager scm = new ServiceConfigManager(token, IdConstants.REPO_SERVICE, "1.0");
ServiceConfig sc = scm.getOrganizationConfig(orgName, null);
if (sc != null) {
ServiceConfig subConfig = sc.getSubConfig(configName);
if (subConfig != null) {
Map<String, Object> configMap = subConfig.getAttributes();
Set<String> vals = (Set<String>) configMap.get("sun-idrepo-ldapv3-config-ldap-server");
vals.add(entry);
HashMap<String, Set<String>> mp = new HashMap<String, Set<String>>(2);
mp.put("sun-idrepo-ldapv3-config-ldap-server", vals);
subConfig.setAttributes(mp);
}
}
}
use of com.sun.identity.sm.ServiceConfigManager 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.ServiceConfigManager in project OpenAM by OpenRock.
the class ScriptEngineConfigurator method registerServiceListener.
/**
* Registers this configurator with the {@link com.sun.identity.sm.ServiceConfigManager} to receive updates
* when the script configuration changes.
*
* @throws IllegalStateException if the configuration listener cannot be registered.
*/
public void registerServiceListener() {
if (!initialised) {
try {
String listenerId = new ServiceConfigManager(SERVICE_NAME, getAdminToken()).addListener(this);
if (listenerId == null) {
throw new SMSException("Unable to register service config listener");
}
logger.info("Registered service config listener: {}", listenerId);
updateConfig(POLICY_CONDITION);
updateConfig(AUTHENTICATION_SERVER_SIDE);
updateConfig(OIDC_CLAIMS);
initialised = true;
} catch (SSOException | SMSException e) {
logger.error("Unable to create ServiceConfigManager", e);
throw new IllegalStateException(e);
}
}
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class UmaSettingsImpl method addServiceListener.
private void addServiceListener() {
try {
final SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
final ServiceConfigManager serviceConfigManager = new ServiceConfigManager(token, SERVICE_NAME, SERVICE_VERSION);
if (serviceConfigManager.addListener(new UmaProviderSettingsChangeListener()) == null) {
logger.error("Could not add listener to ServiceConfigManager instance. UMA provider service " + "changes will not be dynamically updated for realm " + realm);
}
} catch (Exception e) {
String message = "Unable to construct ServiceConfigManager: " + e;
logger.error(message, e);
throw OAuthProblemException.OAuthError.SERVER_ERROR.handle(null, message);
}
}
Aggregations