use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.
the class OrganizationPermissionsFilter method filter.
@Override
protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments) throws ApiException {
final String methodName = genericMethodResource.getMethod().getName();
final Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
String action;
String organizationId;
switch(methodName) {
case CREATE_METHOD:
final OrganizationDto organization = (OrganizationDto) arguments[0];
if (organization.getParent() != null) {
organizationId = organization.getParent();
action = OrganizationDomain.MANAGE_SUBORGANIZATIONS;
break;
}
// anybody can create root organization
return;
case UPDATE_METHOD:
organizationId = ((String) arguments[0]);
action = OrganizationDomain.UPDATE;
break;
case REMOVE_METHOD:
organizationId = ((String) arguments[0]);
action = OrganizationDomain.DELETE;
break;
case GET_BY_PARENT_METHOD:
organizationId = ((String) arguments[0]);
action = OrganizationDomain.MANAGE_SUBORGANIZATIONS;
if (superPrivilegesChecker.hasSuperPrivileges()) {
return;
}
break;
case GET_ORGANIZATIONS_METHOD:
final String userId = (String) arguments[0];
if (userId != null && !userId.equals(currentSubject.getUserId()) && !superPrivilegesChecker.hasSuperPrivileges()) {
throw new ForbiddenException("The user is able to specify only his own id");
}
// user specified his user id or has super privileges
return;
// methods accessible to every user
case GET_BY_ID_METHOD:
case FIND_METHOD:
return;
default:
throw new ForbiddenException("The user does not have permission to perform this operation");
}
// user is not admin and it is need to check permissions on organization instance level
final Organization organization = manager.getById(organizationId);
final String parentOrganizationId = organization.getParent();
// check permissions on parent organization level when updating or removing child organization
if (parentOrganizationId != null && (OrganizationDomain.UPDATE.equals(action) || OrganizationDomain.DELETE.equals(action))) {
if (currentSubject.hasPermission(OrganizationDomain.DOMAIN_ID, parentOrganizationId, MANAGE_SUBORGANIZATIONS)) {
// user has permissions to manage organization on parent organization level
return;
}
}
if (!currentSubject.hasPermission(DOMAIN_ID, organizationId, action)) {
throw new ForbiddenException("The user does not have permission to " + action + " organization with id '" + organizationId + "'");
}
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
the class OrganizationManagerTest method shouldUpdateOrganizationAndIgnoreNewIdAndParentFields.
@Test
public void shouldUpdateOrganizationAndIgnoreNewIdAndParentFields() throws Exception {
final OrganizationImpl existing = new OrganizationImpl("org123", "oldName", "parent123");
final OrganizationImpl expectedExistingToUpdate = new OrganizationImpl(existing);
expectedExistingToUpdate.setQualifiedName("newName");
final OrganizationImpl suborganization = new OrganizationImpl("org321", "oldName/suborgName", "org123");
final OrganizationImpl expectedSuborganizationToUpdate = new OrganizationImpl(suborganization);
expectedSuborganizationToUpdate.setQualifiedName(expectedExistingToUpdate.getQualifiedName() + "/" + suborganization.getName());
when(organizationDao.getById(any())).thenReturn(existing);
doReturn(new Page<>(singletonList(suborganization), 0, 1, 1)).when(organizationDao).getSuborganizations(anyString(), anyInt(), anyLong());
final OrganizationImpl update = new OrganizationImpl("newId", "newName", "newParentId");
final Organization updated = manager.update("organizationId", update);
verify(organizationDao).getById("organizationId");
verify(organizationDao, times(2)).update(organizationCaptor.capture());
List<OrganizationImpl> updatedOrganizations = organizationCaptor.getAllValues();
assertEquals(updatedOrganizations.get(0), expectedExistingToUpdate);
assertEquals(updatedOrganizations.get(1), expectedSuborganizationToUpdate);
verify(organizationDao).getSuborganizations(eq("oldName"), anyInt(), anyLong());
assertEquals(updated, expectedExistingToUpdate);
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
the class OrganizationManagerTest method shouldCreateOrganization.
@Test
public void shouldCreateOrganization() throws Exception {
final Organization toCreate = DtoFactory.newDto(OrganizationDto.class).withName("newOrg");
manager.create(toCreate);
verify(organizationDao).create(organizationCaptor.capture());
final OrganizationImpl createdOrganization = organizationCaptor.getValue();
assertEquals(createdOrganization.getName(), toCreate.getName());
assertEquals(createdOrganization.getQualifiedName(), toCreate.getName());
assertEquals(createdOrganization.getParent(), toCreate.getParent());
verify(eventService).publish(persistEventCaptor.capture());
assertEquals(persistEventCaptor.getValue().getOrganization(), createdOrganization);
verify(memberDao).store(new MemberImpl(USER_ID, createdOrganization.getId(), OrganizationDomain.getActions()));
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
the class OrganizationManagerTest method shouldGetOrganizationById.
@Test
public void shouldGetOrganizationById() throws Exception {
final OrganizationImpl toFetch = new OrganizationImpl("org123", "toFetchOrg", "org321");
when(organizationDao.getById(eq("org123"))).thenReturn(toFetch);
final Organization fetched = manager.getById("org123");
assertEquals(fetched, toFetch);
verify(organizationDao).getById("org123");
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
the class OrganizationServiceTest method shouldUpdateOrganization.
@Test
public void shouldUpdateOrganization() throws Exception {
when(orgManager.update(anyString(), any())).thenAnswer(invocationOnMock -> new OrganizationImpl((Organization) invocationOnMock.getArguments()[1]));
final OrganizationDto toUpdate = createOrganization();
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toUpdate).when().post(SECURE_PATH + "/organization/organization123");
assertEquals(response.statusCode(), 200);
final OrganizationDto createdOrganization = unwrapDto(response, OrganizationDto.class);
assertEquals(createdOrganization, toUpdate);
verify(linksInjector).injectLinks(any(), any());
verify(orgManager).update(eq("organization123"), eq(toUpdate));
}
Aggregations