/** * Gets all the roles for the (un)authenticated user. Anonymous and Authenticated roles are * appended if necessary * * @return all expanded roles for a user * @throws Exception */ public Set<Role> getAllRoles() throws Exception { return getAllRoles(getAuthenticatedUser()); }
/** * Gets all the roles for a user. Anonymous and Authenticated roles are appended if necessary * * @param user * @return all expanded roles for a user * @should not fail with null user * @should add anonymous role to all users * @should add authenticated role to all authenticated users * @should return same roles as user getAllRoles method */ public Set<Role> getAllRoles(User user) throws Exception { Set<Role> roles = new HashSet<>(); // add the Anonymous Role roles.add(getAnonymousRole()); // add the Authenticated role if (user != null && getAuthenticatedUser() != null && getAuthenticatedUser().equals(user)) { roles.addAll(user.getAllRoles()); roles.add(getAuthenticatedRole()); } return roles; }
/** * @return "active" user who has been authenticated, otherwise <code>null</code> */ public static User getAuthenticatedUser() { if (Daemon.isDaemonThread()) { return Daemon.getDaemonThreadUser(); } return getUserContext().getAuthenticatedUser(); }
User user = userContext.getAuthenticatedUser(); if (user != null) { httpSession.setAttribute("username", user.getUsername());
&& (getAuthenticatedUser().hasPrivilege(privilege) || getAuthenticatedRole().hasPrivilege(privilege))) { notifyPrivilegeListeners(getAuthenticatedUser(), privilege, true); return true; notifyPrivilegeListeners(getAuthenticatedUser(), privilege, true); return true; notifyPrivilegeListeners(getAuthenticatedUser(), privilege, true); return true; notifyPrivilegeListeners(getAuthenticatedUser(), privilege, false); return false;
public void authenticateMockUser() { User user = new User(); user.setUuid("1010d442-e134-11de-babe-001e378eb67e"); user.setUserId(1); user.setUsername("admin"); user.addRole(new Role(RoleConstants.SUPERUSER)); Person person = new Person(); person.setUuid("6adb7c42-cfd2-4301-b53b-ff17c5654ff7"); person.setId(1); person.addName(new PersonName("Bob", "", "Smith")); Calendar calendar = Calendar.getInstance(); calendar.set(1980, 01, 01); person.setBirthdate(calendar.getTime()); person.setGender("M"); user.setPerson(person); when(userContext.getAuthenticatedUser()).thenReturn(user); when(userContext.isAuthenticated()).thenReturn(true); }
person.setGender("M"); user.setPerson(person); when(userContext.getAuthenticatedUser()).thenReturn(user); when(userContext.isAuthenticated()).thenReturn(true);
testStr = HtmlFormEntryUtil.getTestStr(includeStr.substring(includeOrExcludeTestIndex)); testRoles = testStr.split(","); User currentUser = Context.getUserContext().getAuthenticatedUser(); try { Set<Role> assignedRoles = currentUser.getAllRoles(); testStr = HtmlFormEntryUtil.getTestStr(includeStr.substring(includeOrExcludeTestIndex)) ; testRoles = testStr.split(","); User currentUser = Context.getUserContext().getAuthenticatedUser(); try { Set<Role> assignedRoles = currentUser.getAllRoles();