use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.
the class EnvironmentsResource method filterEnvironmentInfos.
private Environment filterEnvironmentInfos(Environment environment) {
Environment filteredEnvironment = new Environment();
filteredEnvironment.setId(environment.getId());
filteredEnvironment.setName(environment.getName());
filteredEnvironment.setDescription(environment.getDescription());
filteredEnvironment.setDomainRestrictions(environment.getDomainRestrictions());
filteredEnvironment.setHrids(environment.getHrids());
return filteredEnvironment;
}
use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.
the class EnvironmentsResource method list.
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List all the environments", notes = "User must have the ENVIRONMENT[LIST] permission on the specified organization " + "AND either ENVIRONMENT[READ] permission on each environment " + "or ENVIRONMENT[READ] permission on the specified organization." + "Each returned environment is filtered and contains only basic information such as id and name.")
@ApiResponses({ @ApiResponse(code = 200, message = "List all the environments of the organization", response = Environment.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
public void list(@PathParam("organizationId") String organizationId, @Suspended final AsyncResponse response) {
User authenticatedUser = getAuthenticatedUser();
checkPermission(ReferenceType.ORGANIZATION, organizationId, Permission.ENVIRONMENT, Acl.LIST).andThen(environmentService.findAll(organizationId)).flatMapMaybe(environment -> hasPermission(authenticatedUser, or(of(ReferenceType.ENVIRONMENT, environment.getId(), Permission.ENVIRONMENT, Acl.READ), of(ReferenceType.ORGANIZATION, organizationId, Permission.ENVIRONMENT, Acl.READ))).filter(Boolean::booleanValue).map(permit -> environment)).map(this::filterEnvironmentInfos).sorted((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())).toList().subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.
the class MongoEnvironmentRepository method convert.
private Environment convert(EnvironmentMongo environmentMongo) {
Environment environment = new Environment();
environment.setId(environmentMongo.getId());
environment.setHrids(environmentMongo.getHrids());
environment.setDescription(environmentMongo.getDescription());
environment.setName(environmentMongo.getName());
environment.setOrganizationId(environmentMongo.getOrganizationId());
environment.setDomainRestrictions(environmentMongo.getDomainRestrictions());
environment.setCreatedAt(environmentMongo.getCreatedAt());
environment.setUpdatedAt(environmentMongo.getUpdatedAt());
return environment;
}
use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.
the class EnvironmentServiceImpl method createDefault.
@Override
public Maybe<Environment> createDefault() {
Environment environment = new Environment();
environment.setId(Environment.DEFAULT);
environment.setHrids(Collections.singletonList(Environment.DEFAULT.toLowerCase()));
environment.setName("Default environment");
environment.setDescription("Default environment");
environment.setOrganizationId(Organization.DEFAULT);
environment.setDomainRestrictions(Collections.emptyList());
// No need to create default organization of one or more organizations already exist.
return environmentRepository.count().filter(aLong -> aLong == 0).flatMap(aLong -> createInternal(environment, null).toMaybe());
}
use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.
the class EnvironmentServiceImpl method createInternal.
private Single<Environment> createInternal(Environment toCreate, User createdBy) {
Date now = new Date();
toCreate.setCreatedAt(now);
toCreate.setUpdatedAt(now);
return environmentRepository.create(toCreate).doOnSuccess(environment -> auditService.report(AuditBuilder.builder(EnvironmentAuditBuilder.class).type(EventType.ENVIRONMENT_CREATED).environment(environment).principal(createdBy))).doOnError(throwable -> auditService.report(AuditBuilder.builder(EnvironmentAuditBuilder.class).type(EventType.ENVIRONMENT_CREATED).environment(toCreate).principal(createdBy).throwable(throwable)));
}
Aggregations