Skip to content

Commit

Permalink
Test commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yurem committed Dec 9, 2015
1 parent 8956686 commit 9c73dcf
Showing 1 changed file with 23 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@
*/
@Name("scim2UserEndpoint")
@Path("/scim/v2/Users")
@Api(value = "/scim/v2/Users", description = "SCIM2 User Endpoint (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.4.1)",
authorizations = {
@Authorization(value = "Authorization", type = "oauth2")})
@Produces({"application/json", "application/xml"})
@Api(value = "/scim/v2/Users", description = "SCIM2 User Endpoint (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.4.1)", authorizations = { @Authorization(value = "Authorization", type = "oauth2") })
@Produces({ "application/json", "application/xml" })
public class UserWebService extends BaseScimWebService {

@Logger
Expand All @@ -72,10 +70,7 @@ public class UserWebService extends BaseScimWebService {

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "List Users",
notes = "Returns a list of users (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.4)",
response = ListResponse.class
)
@ApiOperation(value = "List Users", notes = "Returns a list of users (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.4)", response = ListResponse.class)
public Response listUsers(@HeaderParam("Authorization") String authorization,
@QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString,
@QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy,
Expand All @@ -96,7 +91,7 @@ public Response listUsers(@HeaderParam("Authorization") String authorization,
for (GluuCustomPerson gluuPerson : personList) {
log.info(" copying person from GluuPerson to ScimPerson ");
User person = CopyUtils2.copy(gluuPerson, null);

log.info(" adding ScimPerson to the AllPersonList ");
log.info(" person to be added userid : " + person.getUserName());
personsListResponse.getResources().add(person);
Expand All @@ -107,24 +102,20 @@ public Response listUsers(@HeaderParam("Authorization") String authorization,
List<String> schema = new ArrayList<String>();
schema.add("urn:ietf:params:scim:api:messages:2.0:ListResponse");
log.info("setting schema");
personsListResponse.setSchemas(schema);
personsListResponse.setSchemas(schema);
personsListResponse.setTotalResults(personsListResponse.getResources().size());
URI location = new URI("/v2/Users/");
return Response.ok(personsListResponse).location(location).build();
} catch (Exception ex) {
log.error("Exception: ", ex);
return getErrorResponse("Unexpected processing error, please check the input parameters",
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return getErrorResponse("Unexpected processing error, please check the input parameters", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}

@Path("{uid}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Find User by id",
notes = "Returns a Users on the basis of provided uid as path param (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.4.2.1)",
response = User.class
)
@ApiOperation(value = "Find User by id", notes = "Returns a Users on the basis of provided uid as path param (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.4.2.1)", response = User.class)
public Response getUserByUid(@HeaderParam("Authorization") String authorization, @PathParam("uid") String uid) throws Exception {
personService = PersonService.instance();

Expand All @@ -148,21 +139,17 @@ public Response getUserByUid(@HeaderParam("Authorization") String authorization,
return getErrorResponse("Resource " + uid + " not found", Response.Status.NOT_FOUND.getStatusCode());
} catch (Exception ex) {
log.error("Exception: ", ex);
System.out.println("UserWebService Ex: "+ex);
return getErrorResponse("Unexpected processing error, please check the input parameters",
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
System.out.println("UserWebService Ex: " + ex);
return getErrorResponse("Unexpected processing error, please check the input parameters", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}

@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Create User",
notes = "Create User (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.3)",
response = User.class
)
public Response createUser(@HeaderParam("Authorization") String authorization, @ApiParam(value = "User", required = true)User person) throws WebApplicationException,
JsonGenerationException, JsonMappingException, IOException, Exception {
@ApiOperation(value = "Create User", notes = "Create User (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.3)", response = User.class)
public Response createUser(@HeaderParam("Authorization") String authorization, @ApiParam(value = "User", required = true) User person)
throws WebApplicationException, JsonGenerationException, JsonMappingException, IOException, Exception {
personService = PersonService.instance();

Response authorizationResponse = processAuthorization(authorization);
Expand Down Expand Up @@ -210,20 +197,17 @@ public Response createUser(@HeaderParam("Authorization") String authorization, @
return Response.created(URI.create(uri)).entity(newPerson).build();
} catch (Exception ex) {
log.error("Failed to add user", ex);
return getErrorResponse("Unexpected processing error, please check the input parameters",
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return getErrorResponse("Unexpected processing error, please check the input parameters", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}

@Path("{uid}")
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Update User",
notes = "Update User (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.3)",
response = User.class
)
public Response updateUser(@HeaderParam("Authorization") String authorization, @PathParam("uid") String uid,@ApiParam(value = "User", required = true) User person) throws Exception {
@ApiOperation(value = "Update User", notes = "Update User (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.3)", response = User.class)
public Response updateUser(@HeaderParam("Authorization") String authorization, @PathParam("uid") String uid,
@ApiParam(value = "User", required = true) User person) throws Exception {
personService = PersonService.instance();

Response authorizationResponse = processAuthorization(authorization);
Expand Down Expand Up @@ -254,17 +238,14 @@ public Response updateUser(@HeaderParam("Authorization") String authorization, @
} catch (Exception ex) {
log.error("Exception: ", ex);
ex.printStackTrace();
return getErrorResponse("Unexpected processing error, please check the input parameters",
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return getErrorResponse("Unexpected processing error, please check the input parameters", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}

@Path("{uid}")
@DELETE
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Delete User",
notes = "Delete User (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.3)"
)
@ApiOperation(value = "Delete User", notes = "Delete User (https://tools.ietf.org/html/draft-ietf-scim-api-19#section-3.3)")
public Response deleteUser(@HeaderParam("Authorization") String authorization, @PathParam("uid") String uid) throws Exception {
personService = PersonService.instance();

Expand Down Expand Up @@ -295,22 +276,20 @@ public Response deleteUser(@HeaderParam("Authorization") String authorization, @
return getErrorResponse("Resource " + uid + " not found", Response.Status.NOT_FOUND.getStatusCode());
} catch (Exception ex) {
log.error("Exception: ", ex);
return getErrorResponse("Unexpected processing error, please check the input parameters",
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return getErrorResponse("Unexpected processing error, please check the input parameters", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}

@Path("{uid}")
@PATCH
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })

public Response updateUserPatch(@HeaderParam("Authorization") String authorization, @PathParam("uid") String uid, ScimPersonPatch person) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}

return null;
}

Expand All @@ -329,9 +308,8 @@ public Response personSearch(@HeaderParam("Authorization") String authorization,
GluuCustomPerson gluuPerson = personService.getPersonByAttribute(searchPattern.getAttribute(), searchPattern.getValue());
if (gluuPerson == null) {
// sets HTTP status code 404 Not Found
return getErrorResponse(
"No result found for search pattern '" + searchPattern.getAttribute() + " = " + searchPattern.getValue()
+ "' please try again or use another pattern.", Response.Status.NOT_FOUND.getStatusCode());
return getErrorResponse("No result found for search pattern '" + searchPattern.getAttribute() + " = " + searchPattern.getValue()
+ "' please try again or use another pattern.", Response.Status.NOT_FOUND.getStatusCode());
}
ScimPerson person = CopyUtils.copy(gluuPerson, null);
URI location = new URI("/Users/" + gluuPerson.getInum());
Expand All @@ -341,8 +319,7 @@ public Response personSearch(@HeaderParam("Authorization") String authorization,
return getErrorResponse("Resource not found", Response.Status.NOT_FOUND.getStatusCode());
} catch (Exception ex) {
log.error("Exception: ", ex);
return getErrorResponse("Unexpected processing error, please check the input parameters",
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return getErrorResponse("Unexpected processing error, please check the input parameters", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
}

0 comments on commit 9c73dcf

Please sign in to comment.