use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class ShowDataStore method handleRequest.
/**
* Handles request.
*
* @param rc Request Context.
* @throws CLIException if request cannot be processed.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String name = getStringOptionValue(DatastoreOptions.DATASTORE_NAME);
validateRealm(realm);
String[] params = { realm, name };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_DATASTORE", params);
try {
ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminSSOToken);
ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
if (cfg != null) {
ServiceConfig ss = cfg.getSubConfig(name);
if (ss != null) {
Set passwords = CLIUtil.getPasswordFields(IdConstants.REPO_SERVICE, SchemaType.ORGANIZATION, ss.getSchemaID());
Map attributesValues = ss.getAttributes();
getOutputWriter().printlnMessage(FormatUtils.printAttributeValues("{0}={1}", attributesValues, passwords));
} else {
getOutputWriter().printlnMessage(getResourceString("datastore-show-datastore-not-found"));
}
} else {
getOutputWriter().printlnMessage(getResourceString("datastore-show-datastore-not-found"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_SHOW_DATASTORE", params);
} catch (SMSException e) {
String[] p = { realm, name, e.getMessage() };
debugError("ShowDataStore.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_DATASTORE", p);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] p = { realm, name, e.getMessage() };
debugError("ShowDataStore.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_DATASTORE", p);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class IdentityResourceV2 method sendNotification.
/**
* Sends email notification to end user
* @param to Resource receiving notification
* @param subject Notification subject
* @param message Notification Message
* @param confirmationLink Confirmation Link to be sent
* @throws Exception when message cannot be sent
*/
private void sendNotification(String to, String subject, String message, String realm, String confirmationLink) throws ResourceException {
try {
mailmgr = new ServiceConfigManager(RestUtils.getToken(), MailServerImpl.SERVICE_NAME, MailServerImpl.SERVICE_VERSION);
mailscm = mailmgr.getOrganizationConfig(realm, null);
mailattrs = mailscm.getAttributes();
} catch (SMSException smse) {
if (debug.errorEnabled()) {
debug.error("{} :: Cannot create service {}", SEND_NOTIF_TAG, MailServerImpl.SERVICE_NAME, smse);
}
throw new InternalServerErrorException("Cannot create the service: " + MailServerImpl.SERVICE_NAME, smse);
} catch (SSOException ssoe) {
if (debug.errorEnabled()) {
debug.error("{} :: Invalid SSOToken ", SEND_NOTIF_TAG, ssoe);
}
throw new InternalServerErrorException("Cannot create the service: " + MailServerImpl.SERVICE_NAME, ssoe);
}
if (mailattrs == null || mailattrs.isEmpty()) {
if (debug.errorEnabled()) {
debug.error("{} :: no attrs set {}", SEND_NOTIF_TAG, mailattrs);
}
throw new NotFoundException("No service Config Manager found for realm " + realm);
}
// Get MailServer Implementation class
String attr = mailattrs.get(MAIL_IMPL_CLASS).iterator().next();
MailServer mailServer;
try {
mailServer = mailServerLoader.load(attr, realm);
} catch (IllegalStateException e) {
debug.error("{} :: Failed to load mail server implementation: {}", SEND_NOTIF_TAG, attr, e);
throw new InternalServerErrorException("Failed to load mail server implementation: " + attr, e);
}
try {
// Check if subject has not been included
if (StringUtils.isBlank(subject)) {
// Use default email service subject
subject = mailattrs.get(MAIL_SUBJECT).iterator().next();
}
} catch (Exception e) {
if (debug.warningEnabled()) {
debug.warning("{} no subject found ", SEND_NOTIF_TAG, e);
}
subject = "";
}
try {
// Check if Custom Message has been included
if (StringUtils.isBlank(message)) {
// Use default email service message
message = mailattrs.get(MAIL_MESSAGE).iterator().next();
}
message = message + System.getProperty("line.separator") + confirmationLink;
} catch (Exception e) {
if (debug.warningEnabled()) {
debug.warning("{} no message found", SEND_NOTIF_TAG, e);
}
message = confirmationLink;
}
// Send the emails via the implementation class
try {
mailServer.sendEmail(to, subject, message);
} catch (MessagingException e) {
if (debug.errorEnabled()) {
debug.error("{} Failed to send mail", SEND_NOTIF_TAG, e);
}
throw new InternalServerErrorException("Failed to send mail", e);
}
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class IdentityResourceV1 method sendNotification.
/**
* Sends email notification to end user
* @param to Resource receiving notification
* @param subject Notification subject
* @param message Notification Message
* @param confirmationLink Confirmation Link to be sent
* @throws Exception when message cannot be sent
*/
private void sendNotification(String to, String subject, String message, String realm, String confirmationLink) throws ResourceException {
try {
mailmgr = new ServiceConfigManager(RestUtils.getToken(), MailServerImpl.SERVICE_NAME, MailServerImpl.SERVICE_VERSION);
mailscm = mailmgr.getOrganizationConfig(realm, null);
mailattrs = mailscm.getAttributes();
} catch (SMSException smse) {
if (debug.errorEnabled()) {
debug.error("{} :: Cannot create service {}", SEND_NOTIF_TAG, MailServerImpl.SERVICE_NAME, smse);
}
throw new InternalServerErrorException("Cannot create the service: " + MailServerImpl.SERVICE_NAME, smse);
} catch (SSOException ssoe) {
if (debug.errorEnabled()) {
debug.error("{} :: Invalid SSOToken ", SEND_NOTIF_TAG, ssoe);
}
throw new InternalServerErrorException("Cannot create the service: " + MailServerImpl.SERVICE_NAME, ssoe);
}
if (mailattrs == null || mailattrs.isEmpty()) {
if (debug.errorEnabled()) {
debug.error("{} :: no attrs set {}", SEND_NOTIF_TAG, mailattrs);
}
throw new NotFoundException("No service Config Manager found for realm " + realm);
}
// Get MailServer Implementation class
String attr = mailattrs.get(MAIL_IMPL_CLASS).iterator().next();
MailServer mailServer;
try {
mailServer = mailServerLoader.load(attr, realm);
} catch (IllegalStateException e) {
debug.error("{} :: Failed to load mail server implementation: {}", SEND_NOTIF_TAG, attr, e);
throw new InternalServerErrorException("Failed to load mail server implementation: " + attr, e);
}
try {
// Check if subject has not been included
if (StringUtils.isBlank(subject)) {
// Use default email service subject
subject = mailattrs.get(MAIL_SUBJECT).iterator().next();
}
} catch (Exception e) {
if (debug.warningEnabled()) {
debug.warning("{} no subject found ", SEND_NOTIF_TAG, e);
}
subject = "";
}
try {
// Check if Custom Message has been included
if (StringUtils.isBlank(message)) {
// Use default email service message
message = mailattrs.get(MAIL_MESSAGE).iterator().next();
}
message = message + System.getProperty("line.separator") + confirmationLink;
} catch (Exception e) {
if (debug.warningEnabled()) {
debug.warning("{} no message found", SEND_NOTIF_TAG, e);
}
message = confirmationLink;
}
// Send the emails via the implementation class
try {
mailServer.sendEmail(to, subject, message);
} catch (MessagingException e) {
if (debug.errorEnabled()) {
debug.error("{} Failed to send mail", SEND_NOTIF_TAG, e);
}
throw new InternalServerErrorException("Failed to send mail", e);
}
}
use of com.sun.identity.sm.ServiceConfigManager 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.ServiceConfigManager 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