@Test public void testHasRole() { User user = new User(); user.addRole(1, "testrole"); assertTrue("User should have role 'testrole'", user.hasRole("testrole")); assertFalse("User should NOT have role 'dummyrole'", user.hasRole("dummyrole")); user.addRole(2, "testrole 2"); assertTrue("User should have role 'testrole 2'", user.hasRole("testrole 2")); assertFalse("User should NOT have role 'dummyrole'", user.hasRole("dummyrole")); String[] rolesArray = new String[] { "role 1", "role 2"}; assertFalse("User should NOT have any role in given array", user.hasAnyRoleIn(rolesArray)); user.addRole(3, "role 2"); assertTrue("User should have role listed in given array", user.hasAnyRoleIn(rolesArray)); user.addRole(4, Role.getAdminRole().getName()); assertTrue("Admin user should have any role", user.hasRole("any role what so ever")); }
public boolean hasRole(String pRoleName) { for (Role r : getRoles()) { if (r.getName().equals(pRoleName) || r.getName().equalsIgnoreCase(Role.getAdminRole().getName())) { return true; } } return false; }
User implements Serializable { public boolean hasRole(String pRoleName) { for (Role r : getRoles()) { if (r.getName().equals(pRoleName) || r.getName().equalsIgnoreCase(Role.getAdminRole().getName())) { return true; } } return false; } }
User implements Serializable { public boolean hasRole(String pRoleName) { for (Role r : getRoles()) { if (r.getName().equals(pRoleName) || r.getName().equalsIgnoreCase(Role.getAdminRole().getName())) { return true; } } return false; }  }
User implements Serializable { public boolean hasRole(String pRoleName) { for (Role r : getRoles()) { if (r.getName().equals(pRoleName) || r.getName().equalsIgnoreCase(Role.getAdminRole().getName())) { return true; } } return false; }  void clearRoles(); String getAttributes(); void setAttributes(String attribs); boolean setAttribute(String key, String value); Object getAttribute(String key); JSONObject getAttributesJSON(); void setAttributes(JSONObject attribs); void addRole(final Role role); void addRole(final long id, final String name); void setRoles(Set<Role> roles); Set<Role> getRoles(); boolean hasRole(String pRoleName); boolean hasRoleWithId(long pRoleId); boolean hasAnyRoleIn(String[] pRoleName); long getId(); void setId(long id); String getFullName(); void setFirstname(String name); void setLastname(String name); String getUuid(); void setUuid(String uuid); Boolean isGuest(); Boolean isAdmin(); String getScreenname(); void setScreenname(String screenname); String getEmail(); void setEmail(String email); String getLastname(); String getFirstname(); JSONObject toJSON(); static User parse(JSONObject json); @Override boolean equals(Object o); @Override int hashCode(); }
User implements Serializable { public boolean hasRole(String pRoleName) { for (Role r : getRoles()) { if (r.getName().equals(pRoleName) || r.getName().equalsIgnoreCase(Role.getAdminRole().getName())) { return true; } } return false; }  void clearRoles(); String getAttributes(); void setAttributes(String attribs); boolean setAttribute(String key, String value); Object getAttribute(String key); JSONObject getAttributesJSON(); void setAttributes(JSONObject attribs); void addRole(final Role role); void addRole(final long id, final String name); void setRoles(Set<Role> roles); Set<Role> getRoles(); boolean hasRole(String pRoleName); boolean hasRoleWithId(long pRoleId); boolean hasAnyRoleIn(String[] pRoleName); long getId(); void setId(long id); String getFullName(); void setFirstname(String name); void setLastname(String name); String getUuid(); void setUuid(String uuid); Boolean isGuest(); Boolean isAdmin(); String getScreenname(); void setScreenname(String screenname); String getEmail(); void setEmail(String email); String getLastname(); String getFirstname(); JSONObject toJSON(); static User parse(JSONObject json); @Override boolean equals(Object o); @Override int hashCode();  }