@Override public User delegate(UserManager um) { return um.addRole(user, roleName); } });
@Override public void execute(InstallContext installContext) throws TaskExecutionException { UserManager userManager = securitySupport.getUserManager(); User anonymous = userManager.getUser("anonymous"); userManager.addRole(anonymous, "categorization-base"); } }
@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."); } } } }
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 ); }