Search in sources :

Example 56 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi 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 57 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi 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)

Example 58 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi 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();
    }
}
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 59 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

the class OxAuthJsonSettingWebResource method getOxAuthJsonSettings.

@GET
@Operation(summary = "Get json oxauth settings", description = "Gets oxAuth configuration in JSON format", responses = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = OxAuthJsonConfiguration.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response getOxAuthJsonSettings() {
    try {
        log(logger, "Processing oxauth json settings retrieval request");
        this.oxAuthDynamicConfigJson = jsonConfigurationService.getOxAuthDynamicConfigJson();
        OxAuthJsonConfiguration configuration = new ObjectMapper().readValue(this.oxAuthDynamicConfigJson, OxAuthJsonConfiguration.class);
        return Response.ok(configuration).build();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : OxAuthJsonConfiguration(org.gluu.oxtrust.api.server.model.OxAuthJsonConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation)

Example 60 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

the class OxAuthJsonSettingWebResource method updateOxauthJsonSetting.

@PUT
@Operation(summary = "Update json oxauth settings", description = "Updates the oxAuth JSON configuration")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = OxAuthJsonConfiguration.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateOxauthJsonSetting(OxAuthJsonConfiguration oxAuthJsonSetting) {
    try {
        log(logger, "Processing oxauth json settings update request");
        Preconditions.checkNotNull(oxAuthJsonSetting, "Attempt to update null oxauth json settings");
        String value = new ObjectMapper().writeValueAsString(oxAuthJsonSetting);
        jsonConfigurationService.saveOxAuthDynamicConfigJson(value);
        return Response.ok(Constants.RESULT_SUCCESS).build();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)75 Operation (io.swagger.v3.oas.annotations.Operation)50 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)47 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Response (javax.ws.rs.core.Response)21 ArrayList (java.util.ArrayList)20 DefaultValue (javax.ws.rs.DefaultValue)20 HeaderParam (javax.ws.rs.HeaderParam)20 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)20 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)19 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)19 ListViewResponse (org.gluu.persist.model.ListViewResponse)19 URI (java.net.URI)17 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)17 Path (javax.ws.rs.Path)16 Consumes (javax.ws.rs.Consumes)11 GluuGroup (org.gluu.oxtrust.model.GluuGroup)10 OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)10 Scope (org.oxauth.persistence.model.Scope)10