Search in sources :

Example 6 with Environment

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;
}
Also used : Environment(io.gravitee.am.model.Environment)

Example 7 with Environment

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);
}
Also used : EnvironmentService(io.gravitee.am.service.EnvironmentService) Context(javax.ws.rs.core.Context) Permissions.of(io.gravitee.am.management.service.permissions.Permissions.of) AsyncResponse(javax.ws.rs.container.AsyncResponse) Permission(io.gravitee.am.model.permissions.Permission) Autowired(org.springframework.beans.factory.annotation.Autowired) Environment(io.gravitee.am.model.Environment) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) ApiResponses(io.swagger.annotations.ApiResponses) Suspended(javax.ws.rs.container.Suspended) Acl(io.gravitee.am.model.Acl) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(io.gravitee.common.http.MediaType) javax.ws.rs(javax.ws.rs) User(io.gravitee.am.identityprovider.api.User) ApiResponse(io.swagger.annotations.ApiResponse) ResourceContext(javax.ws.rs.container.ResourceContext) Permissions.or(io.gravitee.am.management.service.permissions.Permissions.or) ReferenceType(io.gravitee.am.model.ReferenceType) User(io.gravitee.am.identityprovider.api.User) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 8 with Environment

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;
}
Also used : Environment(io.gravitee.am.model.Environment)

Example 9 with 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());
}
Also used : EnvironmentService(io.gravitee.am.service.EnvironmentService) Logger(org.slf4j.Logger) Date(java.util.Date) Maybe(io.reactivex.Maybe) LoggerFactory(org.slf4j.LoggerFactory) Environment(io.gravitee.am.model.Environment) EventType(io.gravitee.am.common.audit.EventType) AuditService(io.gravitee.am.service.AuditService) Single(io.reactivex.Single) EnvironmentAuditBuilder(io.gravitee.am.service.reporter.builder.management.EnvironmentAuditBuilder) Organization(io.gravitee.am.model.Organization) Component(org.springframework.stereotype.Component) OrganizationService(io.gravitee.am.service.OrganizationService) Flowable(io.reactivex.Flowable) User(io.gravitee.am.identityprovider.api.User) NewEnvironment(io.gravitee.am.service.model.NewEnvironment) AuditBuilder(io.gravitee.am.service.reporter.builder.AuditBuilder) EnvironmentRepository(io.gravitee.am.repository.management.api.EnvironmentRepository) Lazy(org.springframework.context.annotation.Lazy) EnvironmentNotFoundException(io.gravitee.am.service.exception.EnvironmentNotFoundException) Collections(java.util.Collections) Environment(io.gravitee.am.model.Environment) NewEnvironment(io.gravitee.am.service.model.NewEnvironment)

Example 10 with Environment

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)));
}
Also used : EnvironmentService(io.gravitee.am.service.EnvironmentService) Logger(org.slf4j.Logger) Date(java.util.Date) Maybe(io.reactivex.Maybe) LoggerFactory(org.slf4j.LoggerFactory) Environment(io.gravitee.am.model.Environment) EventType(io.gravitee.am.common.audit.EventType) AuditService(io.gravitee.am.service.AuditService) Single(io.reactivex.Single) EnvironmentAuditBuilder(io.gravitee.am.service.reporter.builder.management.EnvironmentAuditBuilder) Organization(io.gravitee.am.model.Organization) Component(org.springframework.stereotype.Component) OrganizationService(io.gravitee.am.service.OrganizationService) Flowable(io.reactivex.Flowable) User(io.gravitee.am.identityprovider.api.User) NewEnvironment(io.gravitee.am.service.model.NewEnvironment) AuditBuilder(io.gravitee.am.service.reporter.builder.AuditBuilder) EnvironmentRepository(io.gravitee.am.repository.management.api.EnvironmentRepository) Lazy(org.springframework.context.annotation.Lazy) EnvironmentNotFoundException(io.gravitee.am.service.exception.EnvironmentNotFoundException) Collections(java.util.Collections) Date(java.util.Date)

Aggregations

Environment (io.gravitee.am.model.Environment)24 Test (org.junit.Test)16 NewEnvironment (io.gravitee.am.service.model.NewEnvironment)13 Single (io.reactivex.Single)8 Collections (java.util.Collections)8 EventType (io.gravitee.am.common.audit.EventType)7 DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)7 Organization (io.gravitee.am.model.Organization)7 EnvironmentRepository (io.gravitee.am.repository.management.api.EnvironmentRepository)7 EnvironmentNotFoundException (io.gravitee.am.service.exception.EnvironmentNotFoundException)7 Flowable (io.reactivex.Flowable)7 Maybe (io.reactivex.Maybe)7 Before (org.junit.Before)7 ReferenceType (io.gravitee.am.model.ReferenceType)6 TechnicalException (io.gravitee.am.repository.exceptions.TechnicalException)6 OrganizationNotFoundException (io.gravitee.am.service.exception.OrganizationNotFoundException)6 TestObserver (io.reactivex.observers.TestObserver)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 RunWith (org.junit.runner.RunWith)6 Mock (org.mockito.Mock)6