use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class CertificatesResource method list.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List registered certificates for a security domain", notes = "User must have the DOMAIN_CERTIFICATE[LIST] permission on the specified domain " + "or DOMAIN_CERTIFICATE[LIST] permission on the specified environment " + "or DOMAIN_CERTIFICATE[LIST] permission on the specified organization. " + "Each returned certificate is filtered and contains only basic information such as id, name and type.")
@ApiResponses({ @ApiResponse(code = 200, message = "List registered certificates for a security domain", response = CertificateEntity.class, responseContainer = "Set"), @ApiResponse(code = 500, message = "Internal server error") })
public void list(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @QueryParam("use") String use, @Suspended final AsyncResponse response) {
final int certificateExpiryThreshold = environment.getProperty("services.certificate.expiryThreshold", Integer.class, 14);
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_CERTIFICATE, Acl.LIST).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapPublisher(__ -> certificateService.findByDomain(domain)).filter(c -> {
if (!StringUtils.isEmpty(use)) {
final JsonObject config = JsonObject.mapFrom(Json.decodeValue(c.getConfiguration(), HashMap.class));
if (config != null && config.getJsonArray("use") != null) {
return config.getJsonArray("use").contains(use);
}
}
// no value, return true as sig should be the default
return true;
}).map(cert -> this.filterCertificateInfos(cert, certificateExpiryThreshold)).sorted((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())).toList().map(sortedCertificates -> Response.ok(sortedCertificates).build())).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class DomainResource method get.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get a security domain", notes = "User must have the DOMAIN[READ] permission on the specified domain, environment or organization. " + "Domain will be filtered according to permissions (READ on DOMAIN_USER_ACCOUNT, DOMAIN_IDENTITY_PROVIDER, DOMAIN_FORM, DOMAIN_LOGIN_SETTINGS, " + "DOMAIN_DCR, DOMAIN_SCIM, DOMAIN_SETTINGS)")
@ApiResponses({ @ApiResponse(code = 200, message = "Domain", response = Domain.class), @ApiResponse(code = 500, message = "Internal server error") })
public void get(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domainId, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domainId, Permission.DOMAIN, Acl.READ).andThen(domainService.findById(domainId).switchIfEmpty(Maybe.error(new DomainNotFoundException(domainId))).flatMapSingle(domain -> findAllPermissions(authenticatedUser, organizationId, environmentId, domainId).map(userPermissions -> filterDomainInfos(domain, userPermissions)))).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class DomainResource method updateInternal.
private void updateInternal(String organizationId, String environmentId, String domainId, final PatchDomain patchDomain, final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
Set<Permission> requiredPermissions = patchDomain.getRequiredPermissions();
if (requiredPermissions.isEmpty()) {
// If there is no require permission, it means there is nothing to update. This is not a valid request.
response.resume(new BadRequestException("You need to specify at least one value to update."));
} else {
Completable.merge(requiredPermissions.stream().map(permission -> checkAnyPermission(organizationId, environmentId, domainId, permission, Acl.UPDATE)).collect(Collectors.toList())).andThen(domainService.patch(domainId, patchDomain, authenticatedUser).flatMap(domain -> findAllPermissions(authenticatedUser, organizationId, environmentId, domainId).map(userPermissions -> filterDomainInfos(domain, userPermissions)))).subscribe(response::resume, response::resume);
}
}
use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class MembersResource method addOrUpdateMember.
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add or update an organization member", notes = "User must have ORGANIZATION_MEMBER[READ] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Member has been added or updated successfully"), @ApiResponse(code = 400, message = "Membership parameter is not valid"), @ApiResponse(code = 500, message = "Internal server error") })
public void addOrUpdateMember(@PathParam("organizationId") String organizationId, @Valid @NotNull NewMembership newMembership, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
final Membership membership = convert(newMembership);
membership.setReferenceId(organizationId);
membership.setReferenceType(ReferenceType.ORGANIZATION);
checkPermission(ReferenceType.ORGANIZATION, organizationId, Permission.ORGANIZATION_MEMBER, Acl.CREATE).andThen(organizationService.findById(organizationId).flatMap(organization -> membershipService.addOrUpdate(organizationId, membership, authenticatedUser)).map(membership1 -> Response.created(URI.create("/organizations/" + organizationId + "/members/" + membership1.getId())).entity(membership1).build())).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class IdentityProviderResource method update.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an identity provider", notes = "User must have the DOMAIN_IDENTITY_PROVIDER[UPDATE] permission on the specified domain " + "or DOMAIN_IDENTITY_PROVIDER[UPDATE] permission on the specified environment " + "or DOMAIN_IDENTITY_PROVIDER[UPDATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Identity provider successfully updated", response = IdentityProvider.class), @ApiResponse(code = 500, message = "Internal server error") })
public void update(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @PathParam("identity") String identity, @ApiParam(name = "identity", required = true) @Valid @NotNull UpdateIdentityProvider updateIdentityProvider, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_IDENTITY_PROVIDER, Acl.UPDATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(__ -> identityProviderService.update(domain, identity, updateIdentityProvider, authenticatedUser, false))).map(idp -> hideConfiguration(idp)).subscribe(response::resume, response::resume);
}
Aggregations