use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.
the class OrganizationResourceDistributionServicePermissionsFilter 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 organizationId;
switch(methodName) {
case GET_RESOURCES_CAP_METHOD:
if (superPrivilegesChecker.hasSuperPrivileges()) {
// user is able to see information about all organizations
return;
}
// fall through
case CAP_RESOURCES_METHOD:
// we should check permissions on parent organization level
Organization organization = organizationManager.getById((String) arguments[0]);
organizationId = organization.getParent();
if (organizationId == null) {
// requested organization is root so manager should throw exception
return;
}
break;
case GET_DISTRIBUTED_RESOURCES:
organizationId = (String) arguments[0];
// get organization to ensure that organization exists
organizationManager.getById(organizationId);
if (superPrivilegesChecker.hasSuperPrivileges()) {
// user is able to see information about all organizations
return;
}
break;
default:
throw new ForbiddenException("The user does not have permission to perform this operation");
}
if (!currentSubject.hasPermission(OrganizationDomain.DOMAIN_ID, organizationId, OrganizationDomain.MANAGE_RESOURCES)) {
throw new ForbiddenException("The user does not have permission to manage resources of 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 shouldThrowConflictExceptionOnCreationIfOrganizationNameIsReserved.
@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionOnCreationIfOrganizationNameIsReserved() throws Exception {
final Organization organization = DtoFactory.newDto(OrganizationDto.class).withName("reserved").withParent(null);
manager.create(organization);
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
the class OrganizationManagerTest method shouldGenerateIdentifierWhenCreatingOrganization.
@Test
public void shouldGenerateIdentifierWhenCreatingOrganization() throws Exception {
final Organization organization = DtoFactory.newDto(OrganizationDto.class).withName("newOrg").withId("identifier");
manager.create(organization);
verify(organizationDao).create(organizationCaptor.capture());
final String id = organizationCaptor.getValue().getId();
assertNotNull(id);
assertNotEquals(id, "identifier");
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
the class OrganizationManagerTest method shouldGetOrganizationByName.
@Test
public void shouldGetOrganizationByName() throws Exception {
final OrganizationImpl toFetch = new OrganizationImpl("org123", "toFetchOrg", "org321");
when(organizationDao.getByName(eq("org123"))).thenReturn(toFetch);
final Organization fetched = manager.getByName("org123");
assertEquals(fetched, toFetch);
verify(organizationDao).getByName("org123");
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
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 + "'");
}
}
Aggregations