Search in sources :

Example 86 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project oxTrust by GluuFederation.

the class PeopleWebResource method updatePerson.

@PUT
@Operation(summary = "Update person", description = "Update a person")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuPersonApi.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updatePerson(GluuPersonApi person) {
    String inum = person.getInum();
    log(logger, "Update group " + inum);
    try {
        Objects.requireNonNull(inum, "inum should not be null");
        Objects.requireNonNull(person, "Attempt to update null person");
        GluuCustomPerson existingPerson = personService.getPersonByInum(inum);
        if (existingPerson != null) {
            person.setInum(existingPerson.getInum());
            person.setPassword(existingPerson.getUserPassword());
            GluuCustomPerson personToUpdate = updateValues(existingPerson, person);
            personToUpdate.setDn(personService.getDnForPerson(inum));
            personService.updatePerson(personToUpdate);
            return Response.ok(convert(Arrays.asList(personService.getPersonByInum(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();
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 87 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project oxTrust by GluuFederation.

the class AuthenticationMethodWebResource method updateAuthenticationMethod.

@PUT
@Operation(summary = "Update authentication methods", description = "Update authentication methods")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = AuthenticationMethod.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateAuthenticationMethod(AuthenticationMethod method) {
    log(logger, "Processing updateAuthenticationMethod()");
    try {
        Preconditions.checkNotNull(method, "Attempt to update null method");
        GluuConfiguration configuration = configurationService.getConfiguration();
        if (method.getDefaultAcr() != null || method.getOxtrustAcr() != null) {
            configuration.setAuthenticationMode(method.getDefaultAcr());
            configuration.setOxTrustAuthenticationMode(method.getOxtrustAcr());
            configurationService.updateConfiguration(configuration);
            configuration = configurationService.getConfiguration();
            method.setDefaultAcr(configuration.getAuthenticationMode());
            method.setOxtrustAcr(configuration.getOxTrustAuthenticationMode());
            return Response.ok(method).build();
        } else {
            return Response.status(Response.Status.PRECONDITION_FAILED).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 88 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses 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();
    }
}
Also used : GluuGroup(org.gluu.oxtrust.model.GluuGroup) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 89 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses 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();
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 90 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses 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();
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)99 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)48 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)47 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)47 Operation (io.swagger.v3.oas.models.Operation)39 PathItem (io.swagger.v3.oas.models.PathItem)35 OpenAPI (io.swagger.v3.oas.models.OpenAPI)34 Test (org.testng.annotations.Test)31 ArrayList (java.util.ArrayList)23 Schema (io.swagger.v3.oas.models.media.Schema)22 Content (io.swagger.v3.oas.models.media.Content)21 StringSchema (io.swagger.v3.oas.models.media.StringSchema)21 MediaType (io.swagger.v3.oas.models.media.MediaType)20 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)19 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)17 Path (javax.ws.rs.Path)17 Produces (javax.ws.rs.Produces)17 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)16 Components (io.swagger.v3.oas.models.Components)10