use of org.gluu.oxtrust.model.scim2.User in project oxTrust by GluuFederation.
the class ResourceTypeWS method getResourceTypeUser.
@Path("User")
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response getResourceTypeUser(@HeaderParam("Authorization") String authorization) throws Exception {
ResourceType userResourceType = new ResourceType();
userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
userResourceType.setEndpoint("/v2/Users");
userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
Meta userMeta = new Meta();
userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
userMeta.setResourceType("ResourceType");
userResourceType.setMeta(userMeta);
List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
userExtensionSchema.setRequired(false);
schemaExtensions.add(userExtensionSchema);
userResourceType.setSchemaExtensions(schemaExtensions);
// ResourceType[] resourceTypes = new ResourceType[]{userResourceType};
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
// return Response.ok(resourceTypes).location(location).build();
return Response.ok(userResourceType).location(location).build();
}
use of org.gluu.oxtrust.model.scim2.User in project oxTrust by GluuFederation.
the class ResourceTypeWS method listResources.
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listResources(@HeaderParam("Authorization") String authorization) throws Exception {
ListResponse listResponse = new ListResponse();
List<String> schemas = new ArrayList<String>();
schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
listResponse.setSchemas(schemas);
// START: User
ResourceType userResourceType = new ResourceType();
userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
userResourceType.setEndpoint("/v2/Users");
userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
Meta userMeta = new Meta();
userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
userMeta.setResourceType("ResourceType");
userResourceType.setMeta(userMeta);
List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
userExtensionSchema.setRequired(false);
schemaExtensions.add(userExtensionSchema);
userResourceType.setSchemaExtensions(schemaExtensions);
// START: Group
ResourceType groupResourceType = new ResourceType();
groupResourceType.setDescription(Constants.GROUP_CORE_SCHEMA_DESCRIPTION);
groupResourceType.setEndpoint("/v2/Groups");
groupResourceType.setName(Constants.GROUP_CORE_SCHEMA_NAME);
groupResourceType.setId(Constants.GROUP_CORE_SCHEMA_NAME);
groupResourceType.setSchema(Constants.GROUP_CORE_SCHEMA_ID);
Meta groupMeta = new Meta();
groupMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
groupMeta.setResourceType("ResourceType");
groupResourceType.setMeta(groupMeta);
// START: FidoDevice
ResourceType fidoDeviceResourceType = new ResourceType();
fidoDeviceResourceType.setDescription(Constants.FIDO_DEVICES_CORE_SCHEMA_DESCRIPTION);
fidoDeviceResourceType.setEndpoint("/v2/FidoDevices");
fidoDeviceResourceType.setName(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
fidoDeviceResourceType.setId(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
fidoDeviceResourceType.setSchema(Constants.FIDO_DEVICES_CORE_SCHEMA_ID);
Meta fidoDeviceMeta = new Meta();
fidoDeviceMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/FidoDevice");
fidoDeviceMeta.setResourceType("ResourceType");
fidoDeviceResourceType.setMeta(fidoDeviceMeta);
// ResourceType[] resourceTypes = new ResourceType[]{userResourceType, groupResourceType};
List<Resource> resourceTypes = new ArrayList<Resource>();
resourceTypes.add(userResourceType);
resourceTypes.add(groupResourceType);
resourceTypes.add(fidoDeviceResourceType);
listResponse.setResources(resourceTypes);
listResponse.setTotalResults(resourceTypes.size());
listResponse.setItemsPerPage(10);
listResponse.setStartIndex(1);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes");
// return Response.ok(resourceTypes).location(location).build();
return Response.ok(listResponse).location(location).build();
}
use of org.gluu.oxtrust.model.scim2.User in project oxTrust by GluuFederation.
the class UserExtensionsTest method testCreatePersonFromUserObject.
@Test(dependsOnMethods = "testCreatePersonFromJsonString")
@Parameters
public void testCreatePersonFromUserObject() throws Exception {
System.out.println(" testCreatePersonFromUserObject() ");
// Create custom attributes
// String, not
GluuAttribute scimCustomFirst = null;
// multi-valued
if (attributeService.getAttributeByName("scimCustomFirst") == null) {
scimCustomFirst = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomFirst", "Custom First", "First custom attribute", GluuAttributeDataType.STRING, OxMultivalued.FALSE);
}
// Date, multi-valued
GluuAttribute scimCustomSecond = null;
if (attributeService.getAttributeByName("scimCustomSecond") == null) {
scimCustomSecond = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomSecond", "Custom Second", "Second custom attribute", GluuAttributeDataType.DATE, OxMultivalued.TRUE);
}
// Numeric, not
GluuAttribute scimCustomThird = null;
// multi-valued
if (attributeService.getAttributeByName("scimCustomThird") == null) {
scimCustomThird = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomThird", "Custom Third", "Third custom attribute", GluuAttributeDataType.NUMERIC, OxMultivalued.FALSE);
}
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
User user = createUserObject();
// Create Person
GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
assertNotNull(gluuPerson, "gluuPerson is null!");
System.out.println(">>>>>>>>>> gluuPerson.getUid() = " + gluuPerson.getUid());
String inum = personService.generateInumForNewPerson();
String dn = personService.getDnForPerson(inum);
String iname = personService.generateInameForNewPerson(user.getUserName());
gluuPerson.setDn(dn);
gluuPerson.setInum(inum);
gluuPerson.setIname(iname);
gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
personService.addPerson(gluuPerson);
// Retrieve Person
GluuCustomPerson retrievedPerson = personService.getPersonByUid(gluuPerson.getUid());
assertNotNull(retrievedPerson, "Failed to find person.");
User newPerson = copyUtils2.copy(retrievedPerson, null);
Extension extension = newPerson.getExtension(Constants.USER_EXT_SCHEMA_ID);
assertNotNull(extension, "(Persistence) Custom extension not persisted.");
Extension.Field customFirstField = extension.getFields().get("scimCustomFirst");
assertNotNull(customFirstField, "(Persistence) \"scimCustomFirst\" field not persisted.");
assertEquals(customFirstField.getValue(), "customFirstValue");
System.out.println("##### (Persistence) customFirstField.getValue() = " + customFirstField.getValue());
Extension.Field customSecondField = extension.getFields().get("scimCustomSecond");
assertNotNull(customSecondField, "(Persistence) \"scimCustomSecond\" field not persisted.");
List<Date> dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
assertEquals(dateList.size(), 2);
System.out.println("##### (Persistence) dateList.get(0) = " + dateList.get(0));
System.out.println("##### (Persistence) dateList.get(1) = " + dateList.get(1));
Extension.Field customThirdField = extension.getFields().get("scimCustomThird");
assertNotNull(customThirdField, "(Persistence) \"scimCustomThird\" field not persisted.");
assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
System.out.println("##### (Persistence) customThirdField.getValue() = " + customThirdField.getValue());
// Remove Person
memberService.removePerson(retrievedPerson);
// Remove custom attributes
// schemaService.removeAttributeTypeFromObjectClass(scimCustomFirst.getOrigin(),
// scimCustomFirst.getName());
// schemaService.removeStringAttribute(scimCustomFirst.getName());
// attributeService.removeAttribute(scimCustomFirst);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomSecond.getOrigin(),
// scimCustomSecond.getName());
// schemaService.removeStringAttribute(scimCustomSecond.getName());
// attributeService.removeAttribute(scimCustomSecond);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomThird.getOrigin(),
// scimCustomThird.getName());
// schemaService.removeStringAttribute(scimCustomThird.getName());
// attributeService.removeAttribute(scimCustomThird);
}
use of org.gluu.oxtrust.model.scim2.User in project oxTrust by GluuFederation.
the class UserExtensionsTest method createUserObject.
private User createUserObject() throws Exception {
User user = new User();
user.setUserName("userjson.add.username");
String testUserName = user.getUserName() + " (" + System.currentTimeMillis() + ")";
user.setUserName(testUserName);
user.setPassword("test");
user.setDisplayName("Scim2DisplayName");
Email email = new Email();
email.setValue("scim@gluu.org");
email.setType(org.gluu.oxtrust.model.scim2.Email.Type.WORK);
email.setPrimary(true);
user.getEmails().add(email);
PhoneNumber phone = new PhoneNumber();
phone.setType(org.gluu.oxtrust.model.scim2.PhoneNumber.Type.WORK);
phone.setValue("654-6509-263");
user.getPhoneNumbers().add(phone);
org.gluu.oxtrust.model.scim2.Address address = new org.gluu.oxtrust.model.scim2.Address();
address.setCountry("US");
address.setStreetAddress("random street");
address.setLocality("Austin");
address.setPostalCode("65672");
address.setRegion("TX");
address.setPrimary(true);
address.setType(org.gluu.oxtrust.model.scim2.Address.Type.WORK);
address.setFormatted(address.getStreetAddress() + " " + address.getLocality() + " " + address.getPostalCode() + " " + address.getRegion() + " " + address.getCountry());
user.getAddresses().add(address);
user.setPreferredLanguage("US_en");
org.gluu.oxtrust.model.scim2.Name name = new org.gluu.oxtrust.model.scim2.Name();
name.setFamilyName("SCIM");
name.setGivenName("SCIM");
user.setName(name);
// User Extensions
Extension.Builder extensionBuilder = new Extension.Builder(Constants.USER_EXT_SCHEMA_ID);
extensionBuilder.setField("scimCustomFirst", "customFirstValue");
// extensionBuilder.setFieldAsList("scimCustomSecond", Arrays.asList(new
// String[]{"2016-02-23T03:35:22Z", "2016-02-24T01:52:05Z"}));
extensionBuilder.setFieldAsList("scimCustomSecond", Arrays.asList(new Date[] { (new DateTime("1969-01-02")).toDate(), (new DateTime("2016-02-27")).toDate() }));
extensionBuilder.setField("scimCustomThird", new BigDecimal(3000));
user.addExtension(extensionBuilder.build());
return user;
}
use of org.gluu.oxtrust.model.scim2.User in project oxTrust by GluuFederation.
the class UserWebService method deleteUser.
@Path("{id}")
@DELETE
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Delete User", notes = "Delete User (https://tools.ietf.org/html/rfc7644#section-3.6)")
public Response deleteUser(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id) throws Exception {
Response authorizationResponse;
if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
log.info(" ##### SCIM Test Mode is ACTIVE");
authorizationResponse = processTestModeAuthorization(token);
} else {
authorizationResponse = processAuthorization(authorization);
}
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
scim2UserService.deleteUser(id);
return Response.noContent().build();
} catch (EntryPersistenceException ex) {
log.error("Failed to delete user", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.NOT_FOUND, "Resource " + id + " not found");
} catch (Exception ex) {
log.error("Failed to delete user", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
Aggregations