use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebResource method copyAttributes.
private GluuGroup copyAttributes(GluuGroupApi group) {
GluuGroup gluuGroup = new GluuGroup();
gluuGroup.setDescription(group.getDescription());
gluuGroup.setDisplayName(group.getDisplayName());
gluuGroup.setOwner(group.getOwner());
gluuGroup.setStatus(group.getStatus());
gluuGroup.setOrganization(organizationService.getDnForOrganization());
gluuGroup.setMembers(group.getMembers());
gluuGroup.setInum(group.getInum());
return gluuGroup;
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebResource method updateGroup.
@PUT
@Operation(summary = "Update group", description = "Update a group")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuGroupApi.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateGroup(GluuGroupApi group) {
String inum = group.getInum();
inum = inum.equalsIgnoreCase("") ? null : inum;
log("Update group " + inum);
try {
Objects.requireNonNull(inum, "inum should not be null");
Objects.requireNonNull(group, "Attempt to update null group");
GluuGroup existingGroup = groupService.getGroupByInum(inum);
if (existingGroup != null) {
group.setInum(existingGroup.getInum());
GluuGroup groupToUpdate = updateValues(existingGroup, group);
groupToUpdate.setDn(groupService.getDnForGroup(inum));
groupService.updateGroup(groupToUpdate);
return Response.ok(convert(Arrays.asList(groupService.getGroupByInum(inum))).get(0)).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebResource method addGroupMember.
@POST
@Operation(summary = "Add group member", description = "Add group member")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuGroupApi[].class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Path(ApiConstants.INUM_PARAM_PATH + ApiConstants.GROUP_MEMBERS + ApiConstants.MEMBER_INUM_PARAM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response addGroupMember(@PathParam(ApiConstants.INUM) @NotNull String groupInum, @PathParam(ApiConstants.MEMBER_INUM) @NotNull String memberInum) {
log("Add member " + memberInum + " to group" + groupInum);
try {
Objects.requireNonNull(groupInum, "Group's inum should not be null");
Objects.requireNonNull(memberInum, "Member's inum should not be null");
GluuGroup group = groupService.getGroupByInum(groupInum);
GluuCustomPerson person = personService.getPersonByInum(memberInum);
if (group != null && person != null) {
List<String> members = new ArrayList<String>();
if (group.getMembers() != null) {
members = group.getMembers();
}
members.add(personService.getDnForPerson(person.getInum()));
group.setMembers(members);
groupService.updateGroup(group);
return Response.ok(Response.Status.OK).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebResource method removeGroupMember.
@DELETE
@Operation(summary = "Remove group member", description = "Remove a member from group")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Path(ApiConstants.INUM_PARAM_PATH + ApiConstants.GROUP_MEMBERS + ApiConstants.MEMBER_INUM_PARAM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response removeGroupMember(@PathParam(ApiConstants.INUM) @NotNull String groupInum, @PathParam(ApiConstants.MEMBER_INUM) @NotNull String memberInum) {
log("Remove member " + memberInum + " from group" + groupInum);
try {
Objects.requireNonNull(groupInum, "Group's inum should not be null");
Objects.requireNonNull(memberInum, "Member's inum should not be null");
GluuGroup group = groupService.getGroupByInum(groupInum);
GluuCustomPerson person = personService.getPersonByInum(memberInum);
if (group != null && person != null) {
List<String> members = new ArrayList<String>(group.getMembers());
members.remove(personService.getDnForPerson(person.getInum()));
group.setMembers(members);
groupService.updateGroup(group);
return Response.ok(Response.Status.OK).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebResource method createGroup.
@POST
@Operation(summary = "Add group", description = "Add a group")
@ApiResponses(value = { @ApiResponse(responseCode = "201", content = @Content(schema = @Schema(implementation = GluuGroupApi.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response createGroup(GluuGroupApi group) {
log("Adding group " + group.getDisplayName());
try {
Objects.requireNonNull(group, "Attempt to create null group");
GluuGroup gluuGroup = copyAttributes(group);
String inum = gluuGroup.getInum();
if (StringHelper.isEmpty(inum)) {
inum = groupService.generateInumForNewGroup();
}
gluuGroup.setDn(groupService.getDnForGroup(inum));
gluuGroup.setInum(inum);
groupService.addGroup(gluuGroup);
return Response.status(Response.Status.CREATED).entity(convert(Arrays.asList(groupService.getGroupByInum(inum))).get(0)).build();
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
Aggregations