Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhar16 committed Dec 9, 2015
2 parents 2e0d0a0 + 9c73dcf commit d4e609a
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 151 deletions.
40 changes: 23 additions & 17 deletions server/src/main/java/org/gluu/oxtrust/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ public static void deleteGroupFromPerson(GluuGroup group, String dn) throws Exce
}

}
public static String iterableToString(Iterable<?> list){
if(list == null){

public static String iterableToString(Iterable<?> list) {
if (list == null) {
return "";
}

StringBuilder sb = new StringBuilder();
for(Object item : list){
for (Object item : list) {
sb.append(item);
sb.append(",");
}
if(sb.length()>0){
sb.deleteCharAt(sb.length()-1);
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
}
Expand Down Expand Up @@ -229,7 +229,7 @@ private static boolean isMemberExist(List<String> groupMembers, String dn) {

public static boolean isBasicAuth() {
String mode = OxTrustConfiguration.instance().getApplicationConfiguration().getAuthMode();
if (mode.equalsIgnoreCase("basic")) {
if ("basic".equalsIgnoreCase(mode)) {
return true;
}
return false;
Expand All @@ -243,7 +243,7 @@ public static boolean isBasicAuth() {

public static boolean isOxAuth() {
String mode = OxTrustConfiguration.instance().getApplicationConfiguration().getAuthMode();
if (mode.equalsIgnoreCase("oxauth")) {
if ("oxauth".equalsIgnoreCase(mode)) {
return true;
}
return false;
Expand Down Expand Up @@ -296,18 +296,24 @@ public static String getParentXriFromIname(String inum) {
String parentXri = inum.substring(0, inum.lastIndexOf(OxTrustConstants.inameDelimiter));
return parentXri.toLowerCase();
}
/*
public static String getSchoolClassParentIname() {
return OxTrustConfiguration.instance().getApplicationConfiguration().getOrgInum() + Configuration.inameDelimiter + OxTrustConfiguration.instance().getApplicationConfiguration().getOxPlusIname()
+ Configuration.inameDelimiter + Configuration.INAME_CLASS_OBJECTTYPE;
}
*/

/*
* public static String getSchoolClassParentIname() { return
* OxTrustConfiguration
* .instance().getApplicationConfiguration().getOrgInum() +
* Configuration.inameDelimiter +
* OxTrustConfiguration.instance().getApplicationConfiguration
* ().getOxPlusIname() + Configuration.inameDelimiter +
* Configuration.INAME_CLASS_OBJECTTYPE; }
*/
public static String getPersonParentInum() {
return OxTrustConfiguration.instance().getApplicationConfiguration().getOrgInum() + OxTrustConstants.inumDelimiter + OxTrustConstants.INUM_PERSON_OBJECTTYPE;
return OxTrustConfiguration.instance().getApplicationConfiguration().getOrgInum() + OxTrustConstants.inumDelimiter
+ OxTrustConstants.INUM_PERSON_OBJECTTYPE;
}

public static String getPersonParentIname() {
return OxTrustConfiguration.instance().getApplicationConfiguration().getOrgIname() + OxTrustConstants.inameDelimiter + OxTrustConstants.INAME_PERSON_OBJECTTYPE;
return OxTrustConfiguration.instance().getApplicationConfiguration().getOrgIname() + OxTrustConstants.inameDelimiter
+ OxTrustConstants.INAME_PERSON_OBJECTTYPE;
}

}
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());
}
}
}
Loading

0 comments on commit d4e609a

Please sign in to comment.