Search in sources :

Example 41 with InternalServerErrorException

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")));
}
Also used : Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) MessagingException(javax.mail.MessagingException) SSOException(com.iplanet.sso.SSOException) MailServer(org.forgerock.openam.services.email.MailServer) ServiceConfig(com.sun.identity.sm.ServiceConfig) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 42 with InternalServerErrorException

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);
    }
}
Also used : ServerException(org.forgerock.openam.sm.datalayer.store.ServerException) AMIdentity(com.sun.identity.idm.AMIdentity) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) NotFoundException(org.forgerock.openam.sm.datalayer.store.NotFoundException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException)

Example 43 with InternalServerErrorException

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();
    }
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) AuthenticatorOathService(org.forgerock.openam.core.rest.devices.services.AuthenticatorOathService) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException) SSOException(com.iplanet.sso.SSOException)

Example 44 with InternalServerErrorException

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);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) DeviceService(org.forgerock.openam.core.rest.devices.services.DeviceService) JsonValue(org.forgerock.json.JsonValue) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMIdentity(com.sun.identity.idm.AMIdentity) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) HashSet(java.util.HashSet)

Example 45 with InternalServerErrorException

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);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) DeviceService(org.forgerock.openam.core.rest.devices.services.DeviceService) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMIdentity(com.sun.identity.idm.AMIdentity) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException)

Aggregations

InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)70 SSOException (com.iplanet.sso.SSOException)39 JsonValue (org.forgerock.json.JsonValue)33 SMSException (com.sun.identity.sm.SMSException)29 BadRequestException (org.forgerock.json.resource.BadRequestException)27 NotFoundException (org.forgerock.json.resource.NotFoundException)25 ResourceException (org.forgerock.json.resource.ResourceException)24 SSOToken (com.iplanet.sso.SSOToken)19 IdRepoException (com.sun.identity.idm.IdRepoException)18 Set (java.util.Set)15 ResourceResponse (org.forgerock.json.resource.ResourceResponse)15 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)14 AMIdentity (com.sun.identity.idm.AMIdentity)13 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 ForbiddenException (org.forgerock.json.resource.ForbiddenException)11 ServiceConfig (com.sun.identity.sm.ServiceConfig)10 NotSupportedException (org.forgerock.json.resource.NotSupportedException)10 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)10 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)9