@Override public User delegate(UserManager um) { return um.getUser(subject); } });
@Override public Collection<User> delegate(UserManager userManager) { return userManager.getAllUsers(); } });
@Override public User delegate(UserManager um) { return um.getAnonymousUser(); } });
private void executeImpl() throws Exception { SecuritySupport securitySupport = Components.getComponent( SecuritySupport.class ); UserManager userManager = securitySupport.getUserManager(); User mgnlUser = null; if( user != null ) { mgnlUser = userManager.getUser( user ); } else { mgnlUser = userManager.getAnonymousUser(); } if( mgnlUser == null ) { throw new TaskExecutionException( error_missing_user.format( user != null ? user : "anonymous" ) ); } RoleManager roleManager = securitySupport.getRoleManager(); if( roleManager.getRole( role ) == null ) { throw new TaskExecutionException( error_missing_role.format( role ) ); } userManager.addRole( mgnlUser, role ); }
@Override public void execute(InstallContext ctx) throws TaskExecutionException { UserManager userManager = Components.getComponent(SecuritySupport.class).getUserManager(); User user = userManager.getUser(username); if (user == null) { ctx.warn(String.format("User \"%s\" not found, can't add the \"%s\" role.", username, rolename)); } else { // TODO this "might" save at node level, thus breaking the "save once per module install/update" rule :( // (copied from AddRoleToUserTask) try { userManager.removeRole(user, rolename); } catch (UnsupportedOperationException e) { ctx.warn(String.format("Can't remove role \"%s\" from user \"%s\" due to an unsupported operation exception. This is most likely the case if the users are managed externally.", rolename, username)); } } } }
@Override public void execute(InstallContext ctx) throws TaskExecutionException { final UserManager userManager = SecuritySupport.Factory.getInstance().getUserManager(); final User user = userManager.getUser(username); if (user == null) { ctx.warn("User \"" + username + "\" not found, can't add him/her to the \"" + groupname + "\" group."); } else { // TODO this saves at node level, thus breaking the "save once per module install/update" rule :( try { userManager.addGroup(user, groupname); } catch (UnsupportedOperationException e) { ctx.warn("Can't add the user \"" + username + "\" to the \"" + groupname + "\" group due to an unsupported operation exception. This is most likely the case if the users are managed externaly."); } } } }
@Override public Collection<String> delegate(UserManager userManager) { return userManager.getUsersWithGroup(groupName, transitive); } });
@Override public User delegate(UserManager um) { return um.getSystemUser(); } });
@Override public User delegate(UserManager um) { return um.addRole(user, roleName); } });
@Override public void execute(InstallContext ctx) throws TaskExecutionException { final UserManager userManager = SecuritySupport.Factory.getInstance().getUserManager(); final User user = userManager.getUser(username); if (user == null) { ctx.warn("User \"" + username + "\" not found, can't add the \"" + rolename + "\" role."); } else { // TODO this saves at node level, thus breaking the "save once per module install/update" rule :( try { userManager.addRole(user, rolename); } catch (UnsupportedOperationException e) { ctx.warn("Can't add the user \"" + username + "\" to the \"" + rolename + "\" role due to an unsupported operation exception. This is most likely the case if the users are managed externaly."); } } } }
@Override public Collection<String> delegate(UserManager userManager) { return userManager.getUsersWithGroup(groupName); } });
public static User getSystemUser() { return getSecuritySupport().getUserManager(Realm.REALM_SYSTEM.getName()).getSystemUser(); }
@Override public User delegate(UserManager um) { return um.getUser(name); } });
@Override public void sendGroupMessage(final String groupName, final Message message) { Collection<String> userNames = securitySupportProvider.get().getUserManager().getUsersWithGroup(groupName, true); for (String userName : userNames) { sendMessage(userName, message); } // Reset it to null simply to avoid assumptions about the id in calling code message.setId(null); }
/** * @return Collection<User> * @throws RepositoryException */ protected static Collection<User> getAllUserNodes(UserManager manager) throws RepositoryException { return manager.getAllUsers(); }
public static User getAnonymousUser() { return getSecuritySupport().getUserManager(Realm.REALM_SYSTEM.getName()).getAnonymousUser(); }
@Test public void userManagerReturnsSystemUserWithCorrectRole() throws Exception { //WHEN User user = securitySupport.getUserManager().getSystemUser(); //THEN assertThat(user.hasRole("superuser"), is(true)); }
protected void validateUsername(String name) { if (StringUtils.isBlank(name)) { throw new IllegalArgumentException(name + " is not a valid username."); } User user; if (isAllowCrossRealmDuplicateNames()) { user = this.getUser(name); } else { user = Security.getUserManager().getUser(name); } if (user != null) { throw new IllegalArgumentException("User with name " + name + " already exists."); } }
private Set<String> getAllRecipients(final Task task) { HashSet<String> users = new HashSet<String>(); log.debug("Found actorId [{}]", task.getActorId()); if (StringUtils.isNotBlank(task.getActorId())) { users.add(task.getActorId()); } if (task.getActorIds() != null) { log.debug("Found actorIds {}", task.getActorIds()); users.addAll(task.getActorIds()); } log.debug("Found groups {}", task.getGroupIds()); if (task.getGroupIds() != null) { for (String group : task.getGroupIds()) { Collection<String> usersOfGroupTransitive = securitySupport.get().getUserManager().getUsersWithGroup(group, true); users.addAll(usersOfGroupTransitive); } } return users; }