use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class GeoObjectImportConfiguration method enforceExecutePermissions.
@Override
public void enforceExecutePermissions() {
Organization org = type.getOrganization();
RolePermissionService perms = ServiceFactory.getRolePermissionService();
if (perms.isRA()) {
perms.enforceRA(org.getCode());
} else if (perms.isRM()) {
perms.enforceRM(org.getCode(), type);
} else {
perms.enforceRM();
}
}
use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class Organization method isRegistryAdmin.
/**
* @param org
* @return If the current user is part of the registry admin role for the
* given organization
*/
public static boolean isRegistryAdmin(Organization org) {
if (new RolePermissionService().isSRA()) {
return true;
}
String roleName = RegistryRole.Type.getRA_RoleName((org.getCode()));
final SessionIF session = Session.getCurrentSession();
if (session != null) {
return session.userHasRole(roleName);
}
return true;
}
use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class UserInfo method page.
public static JSONObject page(Integer pageSize, Integer pageNumber) {
final RolePermissionService perms = ServiceFactory.getRolePermissionService();
List<Organization> organizations = Organization.getUserOrganizations();
boolean isSRA = perms.isSRA();
boolean isRMorRCorAC = (!isSRA && !perms.isRA()) && (perms.isRM() || perms.isRC() || perms.isAC());
List<ExternalSystem> externalSystemList = ExternalSystem.getExternalSystemsForOrg(1, 100);
JSONArray externalSystems = new JSONArray();
for (ExternalSystem externalSystem : externalSystemList) {
externalSystems.put(new JSONObject(externalSystem.toJSON().toString()));
}
if (organizations.size() > 0 || isSRA) {
ValueQuery vQuery = new ValueQuery(new QueryFactory());
GeoprismUserQuery uQuery = new GeoprismUserQuery(vQuery);
UserInfoQuery iQuery = new UserInfoQuery(vQuery);
vQuery.SELECT(uQuery.getOid(), uQuery.getUsername(), uQuery.getFirstName(), uQuery.getLastName(), uQuery.getPhoneNumber(), uQuery.getEmail(), uQuery.getInactive());
vQuery.SELECT(iQuery.getAltFirstName(), iQuery.getAltLastName(), iQuery.getAltPhoneNumber(), iQuery.getPosition());
vQuery.SELECT(iQuery.getExternalSystemOid());
vQuery.WHERE(new LeftJoinEq(uQuery.getOid(), iQuery.getGeoprismUser()));
if (organizations.size() > 0) {
// restrict by org code
OrganizationQuery orgQuery = new OrganizationQuery(vQuery);
OrganizationUserQuery relQuery = new OrganizationUserQuery(vQuery);
for (Organization org : organizations) {
orgQuery.OR(orgQuery.getCode().EQ(org.getCode()));
}
vQuery.WHERE(relQuery.parentOid().EQ(orgQuery.getOid()));
vQuery.WHERE(uQuery.getOid().EQ(relQuery.childOid()));
}
if (isRMorRCorAC) {
vQuery.WHERE(uQuery.getInactive().EQ(false));
}
vQuery.ORDER_BY_ASC(uQuery.getUsername());
return serializePage(pageSize, pageNumber, externalSystems, vQuery);
}
JSONObject page = new JSONObject();
page.put("resultSet", new JSONArray());
page.put("count", 0);
page.put("pageNumber", pageNumber);
page.put("pageSize", pageSize);
page.put("externalSystems", externalSystems);
return page;
}
use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class ETLService method filterHistoryQueryBasedOnPermissions.
public void filterHistoryQueryBasedOnPermissions(ImportHistoryQuery ihq) {
List<String> raOrgs = new ArrayList<String>();
List<String> rmGeoObjects = new ArrayList<String>();
Condition cond = null;
SingleActorDAOIF actor = Session.getCurrentSession().getUser();
for (RoleDAOIF role : actor.authorizedRoles()) {
String roleName = role.getRoleName();
if (RegistryRole.Type.isOrgRole(roleName) && !RegistryRole.Type.isRootOrgRole(roleName)) {
if (RegistryRole.Type.isRA_Role(roleName)) {
String roleOrgCode = RegistryRole.Type.parseOrgCode(roleName);
raOrgs.add(roleOrgCode);
} else if (RegistryRole.Type.isRM_Role(roleName)) {
rmGeoObjects.add(roleName);
}
}
}
if (!new RolePermissionService().isSRA() && raOrgs.size() == 0 && rmGeoObjects.size() == 0) {
throw new ProgrammingErrorException("This endpoint must be invoked by an RA or RM");
}
for (String orgCode : raOrgs) {
Organization org = Organization.getByCode(orgCode);
Condition loopCond = ihq.getOrganization().EQ(org);
if (cond == null) {
cond = loopCond;
} else {
cond = cond.OR(loopCond);
}
}
for (String roleName : rmGeoObjects) {
String roleOrgCode = RegistryRole.Type.parseOrgCode(roleName);
Organization org = Organization.getByCode(roleOrgCode);
String gotCode = RegistryRole.Type.parseGotCode(roleName);
Condition loopCond = ihq.getGeoObjectTypeCode().EQ(gotCode).AND(ihq.getOrganization().EQ(org));
if (cond == null) {
cond = loopCond;
} else {
cond = cond.OR(loopCond);
}
// If they have permission to an abstract parent type, then they also have
// permission to all its children.
Optional<ServerGeoObjectType> op = ServiceFactory.getMetadataCache().getGeoObjectType(gotCode);
if (op.isPresent() && op.get().getIsAbstract()) {
List<ServerGeoObjectType> subTypes = op.get().getSubtypes();
for (ServerGeoObjectType subType : subTypes) {
Condition superCond = ihq.getGeoObjectTypeCode().EQ(subType.getCode()).AND(ihq.getOrganization().EQ(subType.getOrganization()));
cond = cond.OR(superCond);
}
}
}
if (cond != null) {
ihq.AND(cond);
}
}
use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class TransitionEvent method readOnly.
public boolean readOnly() {
RolePermissionService rps = ServiceFactory.getRolePermissionService();
ServerGeoObjectType type = ServiceFactory.getMetadataCache().getGeoObjectType(this.getBeforeTypeCode()).get();
final String orgCode = this.getBeforeTypeOrgCode();
return !(rps.isSRA() || rps.isRA(orgCode) || rps.isRM(orgCode, type) || rps.isRC(orgCode, type));
}
Aggregations