Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2013, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.as.test.integration.management.rbac;
 
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.ADMINISTRATOR_ROLE;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.ADMINISTRATOR_USER;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.AUDITOR_ROLE;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.AUDITOR_USER;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.DEPLOYER_ROLE;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.DEPLOYER_USER;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.MAINTAINER_ROLE;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.MAINTAINER_USER;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.MONITOR_ROLE;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.MONITOR_USER;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.OPERATOR_ROLE;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.OPERATOR_USER;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.SUPERUSER_ROLE;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.SUPERUSER_USER;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.addRoleMapping;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.addRoleUser;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.removeRoleMapping;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.removeRoleUser;
 
 import java.util.Map;
 import java.util.Set;
 
Task that can add user->role mappings to the access=authorization configuration.

Author(s):
Brian Stansberry (c) 2013 Red Hat Inc.
 
 
     private final Map<StringSet<String>> rolesToUsers = new HashMap<StringSet<String>>();
 
     protected UserRolesMappingServerSetupTask(final Map<StringSet<String>> rolesToUsers) {
         this..putAll(rolesToUsers);
     }
 
 
     public void setup(ModelControllerClient clientthrows IOException {
         for (Map.Entry<StringSet<String>> roleEntry : .entrySet()) {
             String role = roleEntry.getKey();
             addRoleMapping(roleclient);
             for (String user : roleEntry.getValue()) {
                 addRoleUser(roleuserclient);
             }
         }
     }
 
     public void tearDown(ModelControllerClient clientthrows IOException {
         for (Map.Entry<StringSet<String>> roleEntry : .entrySet()) {
             String role = roleEntry.getKey();
             for (String user : roleEntry.getValue()) {
                 removeRoleUser(roleuserclient);
             }
             if (!.equals(role)) {
                 removeRoleMapping(roleclient);
             }
         }
     }

    
UserRolesMappingServerSetupTask that adds a single user mapping for each standard role, with the username the same as the role name.
 
     public static class StandardUsersSetup extends UserRolesMappingServerSetupTask {
 
         static {
             Map<StringSet<String>> rolesToUsers = new HashMap<StringSet<String>>();
             rolesToUsers.put(, Collections.singleton());
             rolesToUsers.put(, Collections.singleton());
             rolesToUsers.put(, Collections.singleton());
             rolesToUsers.put(, Collections.singleton());
            rolesToUsers.put(, Collections.singleton());
            rolesToUsers.put(, Collections.singleton());
            rolesToUsers.put(, Collections.singleton());
             = rolesToUsers;
        }
        private static final Map<StringSet<String>> STANDARD_USERS;
        public static final StandardUsersSetup INSTANCE = new StandardUsersSetup();
        public StandardUsersSetup() {
            super();
        }
    }
New to GrepCode? Check out our FAQ X