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);
}
}
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);
}
}
Aggregations