Search in sources :

Example 1 with UpdateRole

use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.

the class RoleServiceTest method shouldUpdate_roleNotFound.

@Test
public void shouldUpdate_roleNotFound() {
    UpdateRole updateRole = Mockito.mock(UpdateRole.class);
    when(roleRepository.findById(ReferenceType.DOMAIN, DOMAIN, "my-role")).thenReturn(Maybe.empty());
    TestObserver testObserver = new TestObserver();
    roleService.update(DOMAIN, "my-role", updateRole).subscribe(testObserver);
    testObserver.assertError(RoleNotFoundException.class);
    testObserver.assertNotComplete();
    verify(roleRepository, never()).findAll(ReferenceType.DOMAIN, DOMAIN);
    verify(roleRepository, never()).create(any(Role.class));
}
Also used : Role(io.gravitee.am.model.Role) NewRole(io.gravitee.am.service.model.NewRole) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) UpdateRole(io.gravitee.am.service.model.UpdateRole) UpdateRole(io.gravitee.am.service.model.UpdateRole) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 2 with UpdateRole

use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.

the class RoleServiceTest method shouldNotUpdate_systemRole.

@Test
public void shouldNotUpdate_systemRole() {
    UpdateRole updateRole = new UpdateRole();
    Role role = new Role();
    role.setSystem(true);
    role.setReferenceType(ReferenceType.ORGANIZATION);
    role.setReferenceId(ORGANIZATION_ID);
    when(roleRepository.findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role")).thenReturn(Maybe.just(role));
    TestObserver testObserver = roleService.update(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role", updateRole, null).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertNotComplete();
    testObserver.assertError(SystemRoleUpdateException.class);
    verify(roleRepository, times(1)).findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role");
    verify(roleRepository, never()).findAll(ReferenceType.ORGANIZATION, ORGANIZATION_ID);
    verify(roleRepository, never()).update(any(Role.class));
}
Also used : Role(io.gravitee.am.model.Role) NewRole(io.gravitee.am.service.model.NewRole) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) UpdateRole(io.gravitee.am.service.model.UpdateRole) UpdateRole(io.gravitee.am.service.model.UpdateRole) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 3 with UpdateRole

use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.

the class RoleServiceTest method shouldUpdate_technicalException.

@Test
public void shouldUpdate_technicalException() {
    UpdateRole updateRole = Mockito.mock(UpdateRole.class);
    when(roleRepository.findById(ReferenceType.DOMAIN, DOMAIN, "my-role")).thenReturn(Maybe.error(TechnicalException::new));
    TestObserver testObserver = new TestObserver();
    roleService.update(DOMAIN, "my-role", updateRole).subscribe(testObserver);
    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
    verify(roleRepository, never()).findAll(ReferenceType.DOMAIN, DOMAIN);
    verify(roleRepository, never()).update(any(Role.class));
}
Also used : Role(io.gravitee.am.model.Role) NewRole(io.gravitee.am.service.model.NewRole) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) UpdateRole(io.gravitee.am.service.model.UpdateRole) UpdateRole(io.gravitee.am.service.model.UpdateRole) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 4 with UpdateRole

use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.

the class RoleResource method update.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a role", notes = "User must have the DOMAIN_ROLE[UPDATE] permission on the specified domain " + "or DOMAIN_ROLE[UPDATE] permission on the specified environment " + "or DOMAIN_ROLE[UPDATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Role successfully updated", response = RoleEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
public void update(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @PathParam("role") String role, @ApiParam(name = "role", required = true) @Valid @NotNull UpdateRole updateRole, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_ROLE, Acl.UPDATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(irrelevant -> roleService.update(domain, role, convert(updateRole), authenticatedUser)).map(this::convert)).subscribe(response::resume, response::resume);
}
Also used : Role(io.gravitee.am.model.Role) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) RoleEntity(io.gravitee.am.management.handlers.management.api.model.RoleEntity) DomainService(io.gravitee.am.service.DomainService) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) ApiResponses(io.swagger.annotations.ApiResponses) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) ApiOperation(io.swagger.annotations.ApiOperation) User(io.gravitee.am.identityprovider.api.User) ReferenceType(io.gravitee.am.model.ReferenceType) RoleService(io.gravitee.am.service.RoleService) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) RoleNotFoundException(io.gravitee.am.service.exception.RoleNotFoundException) NotNull(javax.validation.constraints.NotNull) Suspended(javax.ws.rs.container.Suspended) UpdateRole(io.gravitee.am.service.model.UpdateRole) MediaType(io.gravitee.common.http.MediaType) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ResourceContext(javax.ws.rs.container.ResourceContext) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with UpdateRole

use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.

the class RoleServiceTest method shouldUpdate.

@Test
public void shouldUpdate() {
    UpdateRole updateRole = Mockito.mock(UpdateRole.class);
    Role role = new Role();
    role.setReferenceType(ReferenceType.DOMAIN);
    role.setReferenceId("domain#1");
    when(roleRepository.findById(ReferenceType.DOMAIN, DOMAIN, "my-role")).thenReturn(Maybe.just(role));
    when(roleRepository.findAll(ReferenceType.DOMAIN, DOMAIN)).thenReturn(Flowable.empty());
    when(roleRepository.update(any(Role.class))).thenReturn(Single.just(role));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));
    TestObserver testObserver = roleService.update(DOMAIN, "my-role", updateRole).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(roleRepository, times(1)).findById(ReferenceType.DOMAIN, DOMAIN, "my-role");
    verify(roleRepository, times(1)).findAll(ReferenceType.DOMAIN, DOMAIN);
    verify(roleRepository, times(1)).update(any(Role.class));
}
Also used : Role(io.gravitee.am.model.Role) NewRole(io.gravitee.am.service.model.NewRole) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) UpdateRole(io.gravitee.am.service.model.UpdateRole) UpdateRole(io.gravitee.am.service.model.UpdateRole) Event(io.gravitee.am.model.common.event.Event) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Aggregations

UpdateRole (io.gravitee.am.service.model.UpdateRole)9 Role (io.gravitee.am.model.Role)8 DefaultRole (io.gravitee.am.model.permissions.DefaultRole)7 NewRole (io.gravitee.am.service.model.NewRole)7 TestObserver (io.reactivex.observers.TestObserver)7 Test (org.junit.Test)7 Acl (io.gravitee.am.model.Acl)2 ReferenceType (io.gravitee.am.model.ReferenceType)2 Event (io.gravitee.am.model.common.event.Event)2 Permission (io.gravitee.am.model.permissions.Permission)2 Maybe (io.reactivex.Maybe)2 User (io.gravitee.am.identityprovider.api.User)1 RoleEntity (io.gravitee.am.management.handlers.management.api.model.RoleEntity)1 AbstractResource (io.gravitee.am.management.handlers.management.api.resources.AbstractResource)1 TechnicalException (io.gravitee.am.repository.exceptions.TechnicalException)1 RoleRepository (io.gravitee.am.repository.management.api.RoleRepository)1 DomainService (io.gravitee.am.service.DomainService)1 RoleService (io.gravitee.am.service.RoleService)1 io.gravitee.am.service.exception (io.gravitee.am.service.exception)1 DomainNotFoundException (io.gravitee.am.service.exception.DomainNotFoundException)1