@SuppressWarnings("deprecation") public static Role toRole(String scope) { return new Role(scope, null); }
/** * @return the name */ @Override public String getName() { return this.role.getName(); }
/** * Finds an existing role or creates a new one if needed. Note that a null * description will be set if the role has to be created. * * @param application * The parent application. * @param name * The role name to find or create. * @return The role found or created. */ public static Role get(Application application, String name) { return get(application, name, null); }
@Override public boolean equals(Object o) { if (!(o instanceof Role)) return false; Role that = (Role) o; return Objects.equals(that.getApplication(), getApplication()) && Objects.equals(that.getName(), getName()) && Objects.equals(that.getChildRoles(), getChildRoles()); }
/** * Finds the roles mapped to given user groups. * * @param application * The parent application. Can't be null. * @param userGroups * The user groups. * @return The roles found. * @throws IllegalArgumentException * If application is null. */ public Set<Role> findRoles(Application application, Set<Group> userGroups) { if (application == null) { throw new IllegalArgumentException( "The application argument can't be null"); } Set<Role> result = new HashSet<Role>(); Object source; for (RoleMapping mapping : getRoleMappings()) { source = mapping.getSource(); if ((userGroups != null) && userGroups.contains(source)) { if (mapping.getTarget().getApplication() == application) { result.add(mapping.getTarget()); } } } return result; }
/** * Unmaps an element (user, group or organization) defined in a component * from a role defined in the application. * * @param group * The source group. * @param role * The target role. */ private void unmap(Object source, Role role) { RoleMapping mapping; for (int i = getRoleMappings().size(); i >= 0; i--) { mapping = getRoleMappings().get(i); if (mapping.getSource().equals(source) && mapping.getTarget().equals(role)) { getRoleMappings().remove(i); } } }
@Override public int hashCode() { return SystemUtils.hashCode(getApplication(), getName(), getChildRoles()); }
/** * Finds the roles mapped to a given user group. * * @param application * The parent application. Can't be null. * @param userGroup * The user group. * @return The roles found. * @throws IllegalArgumentException * If application is null. */ public Set<Role> findRoles(Application application, Group userGroup) { if (application == null) { throw new IllegalArgumentException( "The application argument can't be null"); } Set<Role> result = new HashSet<Role>(); Object source; for (RoleMapping mapping : getRoleMappings()) { source = mapping.getSource(); if ((userGroup != null) && userGroup.equals(source)) { if (mapping.getTarget().getApplication() == application) { result.add(mapping.getTarget()); } } } return result; }
@Override public String toString() { return getName(); }
@SuppressWarnings("deprecation") public static List<Role> toRoles(String scopes) { String[] tmp = parseScope(scopes); List<Role> toRet = new ArrayList<Role>(tmp.length); for (String scope : tmp) { toRet.add(new Role(scope, null)); } return toRet; }
/** * Retrieves an existing role or creates a new one if needed based on its * name. Note that a null description will be set if the role has to be * created. * * @param name * The role name to find or create. * @return The role found or created. */ public Role getRole(String name) { return Role.get(getApplication(), name); }
/** * Finds the roles mapped to a given user, for a specific application. * * @param application * The parent application. Can't be null. * @param user * The user. * @return The roles found. * @throws IllegalArgumentException * If application is null. */ public Set<Role> findRoles(Application application, User user) { if (application == null) { throw new IllegalArgumentException( "The application argument can't be null"); } Set<Role> result = new HashSet<Role>(); Object source; for (RoleMapping mapping : getRoleMappings()) { source = mapping.getSource(); if ((user != null) && user.equals(source)) { if (mapping.getTarget().getApplication() == application) { result.add(mapping.getTarget()); } } } return result; }
/** * Indicates if the given role is in the list of roles. * * @param roles * The list of roles. * @param roleName * The name of the role to look for. * @return True if the list of roles contains the given role. */ protected boolean hasRole(List<Role> roles, String roleName) { for (Role role : roles) { if (role.getName().equals(roleName)) { return true; } } return false; } }
/** * Finds an existing role or creates a new one if needed. * * @param application * The parent application. * @param name * The role name to find or create. * @param description * The role description if one needs to be created. * @return The role found or created. */ public static Role get(Application application, String name, String description) { Role role = (application == null) ? null : application.getRole(name); return (role == null) ? new Role(application, name, description) : role; }
/** * Unmaps a group defined in a component from a role defined in the * application. * * @param group * The source group. * @param application * The parent application. Can't be null. * @param roleName * The target role name. * @throws IllegalArgumentException * If application is null. */ public void unmap(Group group, Application application, String roleName) { unmap(group, Role.get(application, roleName, null)); }
/** * Indicates if the given role is in the list of roles. * * @param roles * The list of roles. * @param roleName * The name of the role to look for. * @return True if the list of roles contains the given role. */ protected boolean hasRole(List<Role> roles, String roleName) { for (Role role : roles) { if (role.getName().equals(roleName)) { return true; } } return false; } }
RestletUtilRoles(final String roleName, final String description, final String uriString, final boolean assignable) { this.role = new Role(roleName, description); this.uri = ValueFactoryImpl.getInstance().createURI(uriString); this.assignable = assignable; }
/** * Maps a user defined in a component to a role defined in the application. * * @param user * The source user. * @param application * The parent application. Can't be null. * @param roleName * The target role name. * @throws IllegalArgumentException * If application is null. */ public void map(User user, Application application, String roleName) { map(user, Role.get(application, roleName, null)); }
/** * Indicates if the given role is in the list of roles. * * @param roles * The list of roles. * @param roleName * The name of the role to look for. * @return True if the list of roles contains the given role. */ protected boolean hasRole(List<Role> roles, String roleName) { for (Role role : roles) { if (role.getName().equals(roleName)) { return true; } } return false; } }
/** * Constructor. */ public MailServerApplication() { setName("RESTful Mail Server application"); setDescription("Example application for 'Restlet in Action' book"); setOwner("Restlet S.A.S."); setAuthor("The Restlet Team"); // Declare the supported roles getRoles().add(new Role(this, "CFO")); getRoles().add(new Role(this, "User")); }