use of cz.metacentrum.perun.core.api.Role in project perun by CESNET.
the class AttributesManagerImpl method getAttributeRights.
@Override
public List<AttributeRights> getAttributeRights(PerunSession sess, final int attributeId) throws InternalErrorException {
List<AttributeRights> rights = null;
try {
rights = jdbc.query("select " + attributeRightSelectQuery + " from attributes_authz join roles on " + "attributes_authz.role_id=roles.id join action_types on attributes_authz.action_type_id=action_types.id where " + "attributes_authz.attr_id=?", new AttributeRightsExtractor(attributeId), attributeId);
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
// set also empty rights for other roles (not present in DB)
boolean roleExists;
List<Role> listOfRoles = new ArrayList<Role>();
listOfRoles.add(Role.FACILITYADMIN);
listOfRoles.add(Role.GROUPADMIN);
listOfRoles.add(Role.SELF);
listOfRoles.add(Role.VOADMIN);
for (Role roleToTry : listOfRoles) {
roleExists = false;
Iterator itr = rights.iterator();
while ((itr.hasNext()) && (!roleExists)) {
AttributeRights right = (AttributeRights) itr.next();
if (right.getRole().equals(roleToTry)) {
roleExists = true;
}
}
if (!roleExists) {
rights.add(new AttributeRights(attributeId, roleToTry, new ArrayList<ActionType>()));
}
}
return rights;
}
use of cz.metacentrum.perun.core.api.Role in project perun by CESNET.
the class AuthzResolverImpl method getRoles.
public AuthzRoles getRoles(User user) throws InternalErrorException {
AuthzRoles authzRoles = new AuthzRoles();
if (user != null) {
try {
// Get roles from Authz table
List<Pair<Role, Map<String, Set<Integer>>>> authzRolesPairs = jdbc.query("select " + authzRoleMappingSelectQuery + ", roles.name as role_name from authz left join roles on authz.role_id=roles.id where authz.user_id=? or authorized_group_id in " + "(select groups.id from groups join groups_members on groups.id=groups_members.group_id join members on " + "members.id=groups_members.member_id join users on users.id=members.user_id where users.id=?)", AUTHZROLE_MAPPER, user.getId(), user.getId());
for (Pair<Role, Map<String, Set<Integer>>> pair : authzRolesPairs) {
authzRoles.putAuthzRoles(pair.getLeft(), pair.getRight());
}
// Get service users for user
List<Integer> authzServiceUsers = jdbc.query("select specific_user_users.specific_user_id as id from users, " + "specific_user_users where users.id=specific_user_users.user_id and specific_user_users.status='0' and users.id=? " + "and specific_user_users.type=?", Utils.ID_MAPPER, user.getId(), SpecificUserType.SERVICE.getSpecificUserType());
for (Integer serviceUserId : authzServiceUsers) {
authzRoles.putAuthzRole(Role.SELF, User.class, serviceUserId);
}
// Get members for user
List<Integer> authzMember = jdbc.query("select members.id as id from members where members.user_id=?", Utils.ID_MAPPER, user.getId());
for (Integer memberId : authzMember) {
authzRoles.putAuthzRole(Role.SELF, Member.class, memberId);
}
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
return authzRoles;
}
use of cz.metacentrum.perun.core.api.Role in project perun by CESNET.
the class AuthzResolverImpl method initialize.
public void initialize() throws InternalErrorException {
if (perun.isPerunReadOnly())
log.debug("Loading authzresolver manager init in readOnly version.");
// Check if all roles defined in class Role exists in the DB
for (Role role : Role.values()) {
try {
if (0 == jdbc.queryForInt("select count(*) from roles where name=?", role.getRoleName())) {
//Skip creating not existing roles for read only Perun
if (perun.isPerunReadOnly()) {
throw new InternalErrorException("One of deafult roles not exists in DB - " + role);
} else {
int newId = Utils.getNewId(jdbc, "roles_id_seq");
jdbc.update("insert into roles (id, name) values (?,?)", newId, role.getRoleName());
}
}
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
}
Aggregations