Search in sources :

Example 61 with ProtectedApi

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

the class PassportProviderWebResource method deleteProvider.

@DELETE
@Path(ApiConstants.ID_PARAM_PATH)
@Operation(summary = "Delete passport provider", description = "Delete a passport provider")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response deleteProvider(@PathParam(ApiConstants.ID) @NotNull String id) {
    log(logger, "Delete passport provider having id " + id);
    try {
        Objects.requireNonNull(id, "id should not be null");
        this.ldapOxPassportConfiguration = passportService.loadConfigurationFromLdap();
        this.passportConfiguration = this.ldapOxPassportConfiguration.getPassportConfiguration();
        List<Provider> providers = new ArrayList<>();
        providers.addAll(this.passportConfiguration.getProviders());
        Provider found = null;
        for (Provider provider : providers) {
            if (id.equalsIgnoreCase(provider.getId())) {
                found = provider;
                break;
            }
        }
        if (found != null) {
            providers.remove(found);
            this.passportConfiguration.setProviders(providers);
            this.ldapOxPassportConfiguration.setPassportConfiguration(this.passportConfiguration);
            this.passportService.updateLdapOxPassportConfiguration(this.ldapOxPassportConfiguration);
            return Response.ok().build();
        } else {
            return Response.ok(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : ArrayList(java.util.ArrayList) Provider(org.gluu.model.passport.Provider) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 62 with ProtectedApi

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

the class ScopeWebResource method getScopeClaims.

@GET
@Path(ApiConstants.INUM_PARAM_PATH + ApiConstants.CLAIMS)
@Operation(summary = "Get scope claims", description = "List all claims of a scope")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuAttribute[].class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response getScopeClaims(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    log(logger, "List all claims of scope ==> " + inum);
    try {
        Objects.requireNonNull(inum, "inum should not be null");
        Scope oxAuthScope = scopeService.getScopeByInum(inum);
        List<String> claimsDn = new ArrayList<String>();
        List<GluuAttribute> attributes = new ArrayList<GluuAttribute>();
        if (oxAuthScope != null) {
            claimsDn.addAll(oxAuthScope.getOxAuthClaims());
            for (String claimDn : claimsDn) {
                attributes.add(attributeService.getAttributeByDn(claimDn));
            }
            return Response.ok(attributes).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 : Scope(org.oxauth.persistence.model.Scope) ArrayList(java.util.ArrayList) GluuAttribute(org.gluu.model.GluuAttribute) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 63 with ProtectedApi

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

the class ScopeWebResource method updateScope.

@PUT
@Operation(summary = "Update openid connect scope", description = "Update openidconect scope")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = Scope.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateScope(Scope scope) {
    String inum = scope.getInum();
    log(logger, "Update scope " + inum);
    try {
        Objects.requireNonNull(scope, "Attempt to update scope null value");
        Objects.requireNonNull(inum);
        Scope existingScope = scopeService.getScopeByInum(inum);
        if (existingScope != null) {
            scope.setInum(existingScope.getInum());
            scopeService.updateScope(scope);
            return Response.ok(scopeService.getScopeByInum(inum)).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 : Scope(org.oxauth.persistence.model.Scope) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 64 with ProtectedApi

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

the class SmtpConfigurationWebResource method updateSmtpConfiguration.

@PUT
@Operation(summary = "Update smtp configuration", description = "Update smtp configuration")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = SmtpConfiguration.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateSmtpConfiguration(SmtpConfiguration smtpConfiguration) {
    try {
        Preconditions.checkNotNull(smtpConfiguration, "Attempt to update null smtpConfiguration");
        configurationService.encryptedSmtpPassword(smtpConfiguration);
        GluuConfiguration configurationUpdate = configurationService.getConfiguration();
        configurationUpdate.setSmtpConfiguration(smtpConfiguration);
        configurationService.updateConfiguration(configurationUpdate);
        return Response.ok(configurationService.getConfiguration().getSmtpConfiguration()).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) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 65 with ProtectedApi

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

the class SmtpConfigurationWebResource method testSmtpConfiguration.

@GET
@Path(ApiConstants.TEST)
@Operation(summary = "Test smtp configuration", description = "Test smtp configuration")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = SmtpConfiguration.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response testSmtpConfiguration() {
    try {
        SmtpConfiguration smtpConfiguration = configurationService.getConfiguration().getSmtpConfiguration();
        String password = encryptionService.decrypt(smtpConfiguration.getPassword());
        smtpConfiguration.setPasswordDecrypted(password);
        boolean result = mailService.sendMail(smtpConfiguration, smtpConfiguration.getFromEmailAddress(), smtpConfiguration.getFromName(), smtpConfiguration.getFromEmailAddress(), null, "SMTP Configuration verification", "Mail to test smtp configuration", "Mail to test smtp configuration");
        return Response.ok(result ? true : false).build();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : SmtpConfiguration(org.gluu.model.SmtpConfiguration) 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