use of org.forgerock.json.resource.InternalServerErrorException 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 org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class PendingRequestsService method denyPendingRequest.
/**
* Denies the pending request with the specified {@literal id}.
*
* @param id The pending request id.
* @param realm The current realm.
* @throws ResourceException If the pending request is not found or could not be marked as denied.
*/
public void denyPendingRequest(String id, String realm) throws ResourceException {
try {
UmaPendingRequest request = store.read(id);
store.delete(id);
AMIdentity resourceOwner = coreWrapper.getIdentity(request.getResourceOwnerId(), realm);
auditLogger.log(request.getResourceSetId(), request.getResourceSetName(), resourceOwner, UmaAuditType.REQUEST_DENIED, request.getRequestingPartyId());
} catch (NotFoundException e) {
throw new org.forgerock.json.resource.NotFoundException("Pending request, " + id + ", not found", e);
} catch (ServerException e) {
throw new InternalServerErrorException("Failed to mark pending request, " + id + ", as denied", e);
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class OathDevicesResource method deleteInstance.
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String resourceId, DeleteRequest request) {
try {
final AuthenticatorOathService realmOathService = oathServiceFactory.create(getRealm(context));
//could be admin
final AMIdentity identity = getUserIdFromUri(context);
//make sure we successfully delete
Promise<ResourceResponse, ResourceException> promise = super.deleteInstance(context, resourceId, request);
//then reset the skippable attr
realmOathService.setUserSkipOath(identity, AuthenticatorOathService.NOT_SET);
return promise;
} catch (InternalServerErrorException | SMSException e) {
debug.error("OathDevicesResource :: Delete - Unable to communicate with the SMS.", e);
return new InternalServerErrorException().asPromise();
} catch (SSOException | IdRepoException e) {
debug.error("OathDevicesResource :: Delete - Unable to reset identity attributes", e);
return new InternalServerErrorException().asPromise();
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class UserDevicesDao method saveDeviceProfiles.
/**
* Saves a user's device profiles.
*
* @param username User whose profiles to return.
* @param realm Realm in which we are operating.
* @param profiles The user's device profiles to store.
*
* @throws InternalServerErrorException If there is a problem storing the device profiles.
*/
public void saveDeviceProfiles(String username, String realm, List<JsonValue> profiles) throws InternalServerErrorException {
final AMIdentity identity = getIdentity(username, realm);
Set<String> vals = new HashSet<>();
try {
final DeviceService deviceService = serviceFactory.create(realm);
final DeviceSerialisation deviceSerialisation = deviceService.getDeviceSerialisationStrategy();
final String attrName = deviceService.getConfigStorageAttributeName();
for (JsonValue profile : profiles) {
vals.add(deviceSerialisation.deviceProfileToString(profile));
}
Map<String, Set> attrMap = new HashMap<>();
attrMap.put(attrName, vals);
identity.setAttributes(attrMap);
identity.store();
} catch (SSOException | IdRepoException | SMSException e) {
throw new InternalServerErrorException(e.getMessage(), e);
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class UserDevicesDao method getDeviceProfiles.
/**
* Gets a user's device profiles. The returned profiles must be stored in JSON format.
*
* @param username User whose profiles to return.
* @param realm Realm in which we are operating.
* @return A list of device profiles.
* @throws InternalServerErrorException If there is a problem retrieving the device profiles.
*/
public List<JsonValue> getDeviceProfiles(String username, String realm) throws InternalServerErrorException {
List<JsonValue> devices = new ArrayList<>();
final AMIdentity identity = getIdentity(username, realm);
try {
final DeviceService deviceService = serviceFactory.create(realm);
final String attrName = deviceService.getConfigStorageAttributeName();
final DeviceSerialisation deviceSerialisation = deviceService.getDeviceSerialisationStrategy();
Set<String> set = (Set<String>) identity.getAttribute(attrName);
for (String profile : set) {
devices.add(deviceSerialisation.stringToDeviceProfile(profile));
}
return devices;
} catch (SSOException | IdRepoException | SMSException e) {
throw new InternalServerErrorException(e.getMessage(), e);
}
}
Aggregations