Пример #1
0
 protected void addPropertiesWithPrefix(Properties properties, Group group) {
   if (properties != null) {
     if (group != null) {
       String prefix = group.getName() + ".";
       Properties suffixProperties = group.getProperties();
       addPropertiesWithPrefix(properties, prefix, suffixProperties);
     }
   }
 }
Пример #2
0
  protected Group getJoinedGroup(String userRole, Group group1, Group group2) {
    Group res = null;

    {
      Principal principal = null;
      String id = null;
      String name = null;

      // Set 'principal':
      {
        principal = new SimplePrincipal(userRole);
      }

      // Set 'id':
      {
        id = userRole;
      }

      // Set 'name':
      {
        name = ApplicationUserRoles.getDisplayName(userRole);
      }

      if (group1 == null) {
        if (group2 == null) {
          res = null;
        } else {
          // Set result from 'group2':
          {
            AbstractUserAuthorizor.DefaultGroup g = new AbstractUserAuthorizor.DefaultGroup(group2);

            g.setName(name);
            g.setPrincipal(principal);

            res = g;
          }
        }
      } else {
        if (group2 == null) {
          // Set result from 'group1':
          {
            AbstractUserAuthorizor.DefaultGroup g = new AbstractUserAuthorizor.DefaultGroup(group1);

            g.setName(name);
            g.setPrincipal(principal);

            res = g;
          }
        } else {
          Properties properties = null;
          Map<String, List<String>> attributes = null;
          List<Principal> userPrincipals = null;
          List<Principal> superGroupPrincipals = null;
          List<Principal> groupPrincipals = null;

          // Set 'properties':
          {
            properties = new Properties();

            // Add properties from 'group1':
            {
              addPropertiesWithPrefix(properties, group1);
            }

            // Add properties from 'group2':
            {
              addPropertiesWithPrefix(properties, group2);
            }
          }

          // Set 'attributes':
          {
            Map<String, List<String>> attributes1 = group1.getAttributes();
            Map<String, List<String>> attributes2 = group2.getAttributes();

            attributes = joinAttributes(attributes1, attributes2);
          }

          // Set 'userPrincipals':
          {
            userPrincipals = new ArrayList<Principal>();

            // Add user principals from 'group1':
            {
              List<Principal> l = group1.getUserPrincipals();
              if (l != null) {
                userPrincipals.addAll(l);
              }
            }

            // Add user principals from 'group2':
            {
              List<Principal> l = group2.getUserPrincipals();
              if (l != null) {
                userPrincipals.addAll(l);
              }
            }
          }

          // Set 'superGroupPrincipals':
          {
            superGroupPrincipals = new ArrayList<Principal>();

            // Add super-group principals from 'group1':
            {
              List<Principal> l = group1.getSuperGroupPrincipals();
              if (l != null) {
                superGroupPrincipals.addAll(l);
              }
            }

            // Add super-group principals from 'group2':
            {
              List<Principal> l = group2.getSuperGroupPrincipals();
              if (l != null) {
                superGroupPrincipals.addAll(l);
              }
            }
          }

          // Set 'groupPrincipals':
          {
            groupPrincipals = new ArrayList<Principal>();

            // Add group principals from 'group1':
            {
              List<Principal> l = group1.getGroupPrincipals();
              if (l != null) {
                groupPrincipals.addAll(l);
              }
            }

            // Add group principals from 'group2':
            {
              List<Principal> l = group2.getGroupPrincipals();
              if (l != null) {
                groupPrincipals.addAll(l);
              }
            }
          }

          res =
              new AbstractUserAuthorizor.DefaultGroup(
                  principal,
                  id,
                  name,
                  properties,
                  attributes,
                  userPrincipals,
                  superGroupPrincipals,
                  groupPrincipals);
        }
      }
    }

    return res;
  }