public class MyEnroler implements Enroler { private Application application; public MyEnroler(Application application) { this.application = application; } public void enrole(ClientInfo clientInfo) { Role role = new Role(application, "roleId", "Role name"); clientInfo.getRoles().add(role); } }
/** * Sets the authenticated user roles. * * @param roles * The authenticated user roles. */ public void setRoles(List<org.restlet.security.Role> roles) { synchronized (this) { List<org.restlet.security.Role> r = getRoles(); r.clear(); r.addAll(roles); } }
/** * Indicates if the authenticated client user associated to the current * request is in the given role name. * * @param roleName * The role name to test. * @return True if the authenticated subject is in the given role. */ public boolean isInRole(String roleName) { return getClientInfo().getRoles().contains(getRole(roleName)); }
protected boolean hasAdminRole() { ClientInfo clientInfo = getClientInfo(); List<Role> roles = clientInfo.getRoles(); boolean isAdmin = false; for (Role role : roles) { if (role.getName().equals("admin")) { isAdmin = true; break; } } return isAdmin; } @Post public XX handlePost(YY content) { if (!hasAdminRole()) { throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN); } (...) }
public class MyEnroler implements Enroler { public void enrole(ClientInfo clientInfo) { Request request = Request.getCurrent(); User user = request.getClientInfo().getUser(); if (user!=null) { List<UserRole> roles = user.getRoles(); if (roles!=null) { for (UserRole userRole : roles) { // example of role creation Role role = new Role(userRole.getName(), ""); clientInfo.getRoles().add(role); } } } } }
/** * Returns the highest limit associated to the user's roles. */ @Override public int getLimit(Request request, String countedValue) { // TODO we don't rely on the counted value? int result = 0; List<Role> roles = request.getClientInfo().getRoles(); // iterate over user's roles for (Role role : roles) { if (limitsPerRole.containsKey(role.getName()) && (limitsPerRole.get(role.getName()) > result)) { result = limitsPerRole.get(role.getName()); } } if (result == 0) { result = defaultLimit; } return result; }
/** * Returns the highest limit associated to the user's roles. */ @Override public int getLimit(Request request, String countedValue) { // TODO we don't rely on the counted value? int result = 0; List<Role> roles = request.getClientInfo().getRoles(); // iterate over user's roles for (Role role : roles) { if (limitsPerRole.containsKey(role.getName()) && (limitsPerRole.get(role.getName()) > result)) { result = limitsPerRole.get(role.getName()); } } if (result == 0) { result = defaultLimit; } return result; }
/** * Returns a boolean indicating whether the authenticated user is included * in the specified logical "role". If the user has not been authenticated, * the method returns <code>false</code>. * * @param roleName * a <code>String</code> specifying the name of the role * @return a <code>boolean</code> indicating whether the user making the * request belongs to a given role; <code>false</code> if the user * has not been authenticated * @see SecurityContext#isUserInRole(String) */ public boolean isUserInRole(String roleName) { Role role = Application.getCurrent().getRole(roleName); return (role != null) && this.request.getClientInfo().getRoles().contains(role); }
public void enrole(ClientInfo clientInfo) { User user = findUser(clientInfo.getUser().getIdentifier()); if (user != null) { // Find all the inherited groups of this user Set<Group> userGroups = findGroups(user); // Add roles specific to this user Set<Role> userRoles = findRoles(user); for (Role role : userRoles) { clientInfo.getRoles().add(role); } // Add roles common to group members Set<Role> groupRoles = findRoles(userGroups); for (Role role : groupRoles) { clientInfo.getRoles().add(role); } } } }
/** * Returns the highest limit associated to the user's roles. */ @Override public int getLimit(Request request, String countedValue) { // TODO we don't rely on the counted value? int result = 0; List<Role> roles = request.getClientInfo().getRoles(); // iterate over user's roles for (Role role : roles) { if (limitsPerRole.containsKey(role.getName()) && (limitsPerRole.get(role.getName()) > result)) { result = limitsPerRole.get(role.getName()); } } if (result == 0) { result = defaultLimit; } return result; }
/** * Returns the highest limit associated to the user's roles. */ @Override public int getLimit(Request request, String countedValue) { // TODO we don't rely on the counted value? int result = 0; List<Role> roles = request.getClientInfo().getRoles(); // iterate over user's roles for (Role role : roles) { if (limitsPerRole.containsKey(role.getName()) && (limitsPerRole.get(role.getName()) > result)) { result = limitsPerRole.get(role.getName()); } } if (result == 0) { result = defaultLimit; } return result; }
/** * Returns the highest limit associated to the user's roles. */ @Override public int getLimit(Request request, String countedValue) { // TODO we don't rely on the counted value? int result = 0; List<Role> roles = request.getClientInfo().getRoles(); // iterate over user's roles for (Role role : roles) { if (limitsPerRole.containsKey(role.getName()) && (limitsPerRole.get(role.getName()) > result)) { result = limitsPerRole.get(role.getName()); } } if (result == 0) { result = defaultLimit; } return result; }
dataModel.put("clientInfo", nextClientInfo); dataModel.put("isAuthenticated", nextClientInfo.isAuthenticated()); final List<Role> roles = nextClientInfo.getRoles(); final boolean isAdmin = roles.contains(RestletUtilRoles.ADMIN.getRole()); dataModel.put("isAdmin", isAdmin);
.getNext(); List<Role> userRoles = request.getClientInfo().getRoles();
.getNext(); List<Role> userRoles = request.getClientInfo().getRoles();
.getNext(); List<Role> userRoles = request.getClientInfo().getRoles();