use of sqlite.kripton209.model1.User in project oxTrust by GluuFederation.
the class UserWebService method searchUsers.
@GET
@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 = "Search users", notes = "Returns a list of users (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchUsers(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) Integer count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) 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 {
count = (count == null) ? getMaxCount() : count;
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
} else {
log.info(" Searching users from LDAP ");
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuCustomPerson> gluuCustomPersons = search(personService.getDnForPerson(null), GluuCustomPerson.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
// List<GluuCustomPerson> personList = personService.findAllPersons(null);
ListResponse usersListResponse = new ListResponse();
List<String> schema = new ArrayList<String>();
schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
log.info(" setting schema");
usersListResponse.setSchemas(schema);
// Set total
usersListResponse.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && gluuCustomPersons != null && !gluuCustomPersons.isEmpty()) {
for (GluuCustomPerson gluuPerson : gluuCustomPersons) {
User user = copyUtils2.copy(gluuPerson, null);
log.info(" user to be added id : " + user.getUserName());
usersListResponse.getResources().add(user);
log.info(" user added? : " + usersListResponse.getResources().contains(user));
}
// Set the rest of results info
usersListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
usersListResponse.setStartIndex(vlvResponse.getStartIndex());
}
// Serialize to JSON
String json = serializeToJson(usersListResponse, attributesArray);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Users");
return Response.ok(json).location(location).build();
}
} catch (Exception ex) {
log.error("Error in searchUsers", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of sqlite.kripton209.model1.User in project oxTrust by GluuFederation.
the class UserWebService method patchUser.
// PATCH WEBSERVICES
@Path("/patch/{id}")
@PUT
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@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 = "patch user", notes = "Update user (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = User.class)
public Response patchUser(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @ApiParam(value = "User", required = true) ScimPatchUser user, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) 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 {
User updatedUser = scim2UserService.patchUser(id, user);
// Serialize to JSON
String json = serializeToJson(updatedUser, attributesArray);
URI location = new URI(updatedUser.getMeta().getLocation());
return Response.ok(json).location(location).build();
} catch (EntryPersistenceException ex) {
log.error("Failed to update user", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
} catch (DuplicateEntryException ex) {
log.error("DuplicateEntryException", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
} catch (Exception ex) {
log.error("Failed to update user", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of sqlite.kripton209.model1.User in project oxTrust by GluuFederation.
the class UserWebService method updateUser.
@Path("{id}")
@PUT
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@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 = "Update user", notes = "Update user (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = User.class)
public Response updateUser(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @ApiParam(value = "User", required = true) User user, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) 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 {
User updatedUser = scim2UserService.updateUser(id, user);
// Serialize to JSON
String json = serializeToJson(updatedUser, attributesArray);
URI location = new URI(updatedUser.getMeta().getLocation());
return Response.ok(json).location(location).build();
} catch (EntryPersistenceException ex) {
log.error("Failed to update user", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
} catch (DuplicateEntryException ex) {
log.error("DuplicateEntryException", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
} catch (Exception ex) {
log.error("Failed to update user", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of sqlite.kripton209.model1.User in project oxTrust by GluuFederation.
the class Scim2UserService method removeUserPatch.
private void removeUserPatch(Operation operation, String id) throws Exception {
User user = operation.getValue();
GluuCustomPerson updatedGluuPerson = patchUtil.removePatch(user, validUsernameByInum(user, id));
log.info(" Setting meta: removeUserPatch update user ");
setMeta(updatedGluuPerson);
}
use of sqlite.kripton209.model1.User in project oxTrust by GluuFederation.
the class UserDeserializer method deserialize.
@Override
public User deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
log.info(" deserialize() ");
try {
JsonNode rootNode = jsonParser.readValueAsTree();
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
User user = mapper.readValue(rootNode.toString(), User.class);
if (user.getSchemas() == null) {
throw new IllegalArgumentException("Required field \"schemas\" is null or missing.");
} else if (!user.getSchemas().contains(Constants.USER_CORE_SCHEMA_ID)) {
throw new IllegalArgumentException("User Core schema is required.");
} else if (user.getSchemas().contains(Constants.USER_EXT_SCHEMA_ID)) {
JsonNode userExtensionNode = rootNode.get(Constants.USER_EXT_SCHEMA_ID);
if (userExtensionNode != null) {
ExtensionDeserializer deserializer = new ExtensionDeserializer();
deserializer.setId(Constants.USER_EXT_SCHEMA_ID);
SimpleModule deserializerModule = new SimpleModule("ExtensionDeserializerModule", new Version(1, 0, 0, ""));
deserializerModule.addDeserializer(Extension.class, deserializer);
mapper.registerModule(deserializerModule);
Extension extension = mapper.readValue(userExtensionNode.toString(), Extension.class);
user.addExtension(extension);
} else {
throw new IllegalArgumentException("User Extension schema is indicated, but value body is absent.");
}
}
return user;
} catch (Exception e) {
e.printStackTrace();
throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
}
}
Aggregations