Search in sources :

Example 1 with DeviceService

use of org.forgerock.openam.core.rest.devices.services.DeviceService 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 2 with DeviceService

use of org.forgerock.openam.core.rest.devices.services.DeviceService 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

SSOException (com.iplanet.sso.SSOException)2 AMIdentity (com.sun.identity.idm.AMIdentity)2 IdRepoException (com.sun.identity.idm.IdRepoException)2 SMSException (com.sun.identity.sm.SMSException)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 JsonValue (org.forgerock.json.JsonValue)2 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)2 DeviceService (org.forgerock.openam.core.rest.devices.services.DeviceService)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1