/** * {@inheritDoc} */ public boolean equals(Object obj) { if (!(obj instanceof Role)) return false; return ((Role) obj).getId().equals(getId()); }
/** * {@inheritDoc} */ public boolean hasRole(String user, String role) { if (m_lazy) baseAuthzGroupService.m_storage.completeGet(this); BaseMember grant = (BaseMember) m_userGrants.get(user); if ((grant != null) && (grant.active) && (grant.role.getId().equals(role))) return true; return false; }
/** * {@inheritDoc} */ public int compareTo(Object obj) { if (!(obj instanceof Role)) throw new ClassCastException(); // if the object are the same, say so if (obj == this) return 0; // sort based on (unique) id int compare = getId().compareTo(((Role) obj).getId()); return compare; }
/** * gets the name of the role idependant of the site it belongs to * * @return */ public String getRoleName() { return getSakaiRole().getId(); }
private boolean hasPredefinedViewPermisson(Member member) { /* * just assume student role has the signup.view permission and could add * more roles to exclude */ return STUDENT_ROLE_ID.equalsIgnoreCase(member.getRole().getId()); }
public String getDisplayName() { return getSakaiRole().getId(); }
public Set getRolesIsAllowed(String function) { if (m_lazy) baseAuthzGroupService.m_storage.completeGet(this); Set rv = new HashSet(); for (Iterator i = m_roles.values().iterator(); i.hasNext();) { Role r = (Role) i.next(); if (r.isAllowed(function)) { rv.add(r.getId()); } } return rv; }
/** * {@inheritDoc} */ public Set getUsersHasRole(String role) { if (m_lazy) baseAuthzGroupService.m_storage.completeGet(this); Set rv = new HashSet(); for (Iterator it = m_userGrants.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String user = (String) entry.getKey(); BaseMember grant = (BaseMember) entry.getValue(); if (grant.active && grant.role.getId().equals(role)) { rv.add(user); } } return rv; }
public Map<String, Set<String>> getSitePermissions(String siteId) { Map<String, Set<String>> perms = new HashMap(); String userId = getCurrentUserId(); if (userId == null) { throw new SecurityException("This action (perms) is not accessible to anon and there is no current user."); } try { Site site = siteService.getSite(siteId); for (Role role : site.getRoles()) { Set<String> functions = role.getAllowedFunctions(); perms.put(role.getId(), functions.stream().filter(f -> f.startsWith("commons")).collect(Collectors.toSet())); } } catch (Exception e) { log.error("Failed to get current site permissions.", e); } return perms; }
/** * {@inheritDoc} */ public Role addRole(String id) throws RoleAlreadyDefinedException { if (m_lazy) baseAuthzGroupService.m_storage.completeGet(this); Role role = (Role) m_roles.get(id); if (role != null) throw new RoleAlreadyDefinedException(id); role = new BaseRole(id); m_roles.put(role.getId(), role); return role; }
public String getRoleForAgentAndSite(String agentString, String siteId) { String role = "anonymous_access"; if (siteId == null) return role; String realmName = "/site/" + siteId; Role userRole=null; try { AuthzGroup siteAuthzGroup = authzGroupService.getAuthzGroup(realmName); if (siteAuthzGroup!=null) userRole = siteAuthzGroup.getUserRole(agentString); if (userRole!=null) role = userRole.getId(); log.debug(realmName + ":" + role); } catch(GroupNotDefinedException e) { log.error("error in:" + this + "-getRoleForAgnetAndSite"); } return role; } /**
/** * {@inheritDoc} */ public Role addRole(String id, Role other) throws RoleAlreadyDefinedException { if (m_lazy) baseAuthzGroupService.m_storage.completeGet(this); Role role = (Role) m_roles.get(id); if (role != null) throw new RoleAlreadyDefinedException(id); role = new BaseRole(id, other); m_roles.put(role.getId(), role); return role; }
public List<String> getRoleIdsInRealm(String realmId) { AuthzGroup group; try { group = authzGroupService.getAuthzGroup(realmId); List<String> ret = new ArrayList<String>(); Set<Role> roles = group.getRoles(); Iterator<Role> i = roles.iterator(); while (i.hasNext()) { Role role = (Role)i.next(); ret.add(role.getId()); } return ret; } catch (GroupNotDefinedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
/** * {@inheritDoc} */ public Collection getGroupsWithMemberHasRole(String userId, String role) { Collection siteGroups = getGroups(); ArrayList<String> siteGroupRefs = new ArrayList<String>(siteGroups.size()); for ( Iterator it=siteGroups.iterator(); it.hasNext(); ) siteGroupRefs.add( ((Group)it.next()).getReference() ); List groups = authzGroupService.getAuthzUserGroupIds(siteGroupRefs, userId); Collection<Group> rv = new Vector<Group>(); for (Iterator i = groups.iterator(); i.hasNext();) { Member m = null; Group g = getGroup( (String)i.next() ); if ( g != null ) m = g.getMember(userId); if ((m != null) && (m.isActive()) && (m.getRole().getId().equals(role))) rv.add(g); } return rv; }
/** * {@inheritDoc} * @see org.sakaiproject.content.api.ContentHostingService#getRoleViews(String) */ public Set<String> getRoleViews(final String id) { String ref = getReference(id); LinkedHashSet<String> roleIds = new LinkedHashSet<String>(); AuthzGroup realm = null; try { realm = m_authzGroupService.getAuthzGroup(ref); } catch (GroupNotDefinedException e) { // if there is no authz group then no roles can have been defined. return roleIds; } Set<Role> roles = realm.getRoles(); for (Role role : roles) { if(role.isAllowed(AUTH_RESOURCE_READ)) { roleIds.add(role.getId()); } } return roleIds; }
/** * Helper to add a user to a group. THIS DOES NOT SAVE ANYTHING. It is merely a helper to add the user to the group object and return it. * * @param userUuid uuid of user * @param group Group obj * @return */ private Group addUserToGroup(String userUuid, Group group) { Site site = group.getContainingSite(); //same logic as in site-manage Role r = site.getUserRole(userUuid); Member m = site.getMember(userUuid); Role memberRole = m != null ? m.getRole() : null; //Each user should be marked as non provided //Get role first from site definition. //However, if the user is inactive, getUserRole would return null; then use member role instead group.addMember(userUuid, r != null ? r.getId() : memberRole != null? memberRole.getId() : "", m != null ? m.isActive() : true, false); return group; }
public MemberWithRoleId(Member m) { this.roleId = m.getRole() != null? m.getRole().getId():null; this.active = m.isActive(); this.provided = m.isProvided(); }
public MemberWithRoleId(Member m) { this.roleId = m.getRole() != null? m.getRole().getId():null; this.active = m.isActive(); this.provided = m.isProvided(); }
public RoleWrapper convertRole(Role sakaiRole, AuthzGroup siteRealm) { if (sakaiRole == null) { return null; } Id roleId = getOspiIdManager().getId(siteRealm.getId() + "/" + sakaiRole.getId()); //TODO using the same value for id and eid return new RoleWrapper(roleId, roleId, sakaiRole, siteRealm); } }
protected PermissionsEdit fillPermissionsInternal(PermissionsEdit edit, Id qualifier, boolean readOnly) { try { AuthzGroup siteRealm = AuthzGroupService.getAuthzGroup("/site/" + edit.getSiteId()); Set roles = siteRealm.getRoles(); for (Iterator i = roles.iterator(); i.hasNext();) { Role role = (Role) i.next(); Agent currentRole = getAgentManager().getWorksiteRole(role.getId(), edit.getSiteId()); List authzs = getAuthzManager().getAuthorizations(currentRole, null, qualifier); for (Iterator j = authzs.iterator(); j.hasNext();) { Authorization authz = (Authorization) j.next(); edit.getPermissions().add(new Permission(currentRole, authz.getFunction(), readOnly)); } } } catch (GroupNotDefinedException e) { logger.error("", e); throw new OspException(e); } return edit; }