1. Sebastian Sdorra
  2. scm-manager

Commits

Sebastian Sdorra  committed 6dcce54

replace groups class with groupnames

  • Participants
  • Parent commits bd3f12b
  • Branches apache-shiro

Comments (0)

Files changed (5)

File scm-core/src/main/java/sonia/scm/group/GroupNames.java

View file
+/**
+ * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of SCM-Manager;
+ * nor the names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.group;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import com.google.common.collect.Lists;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.io.Serializable;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+/**
+ * This class represents all associated groups for a user.
+ *
+ * @author Sebastian Sdorra
+ * @since 1.21
+ */
+public class GroupNames implements Serializable, Iterable<String>
+{
+
+  /** Field description */
+  private static final long serialVersionUID = 8615685985213897947L;
+
+  //~--- constructors ---------------------------------------------------------
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param collection
+   */
+  public GroupNames(Collection<String> collection)
+  {
+    this.collection = Collections.unmodifiableCollection(collection);
+  }
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param groupName
+   * @param groupNames
+   */
+  public GroupNames(String groupName, String... groupNames)
+  {
+    this.collection = Lists.asList(groupName, groupNames);
+  }
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param groupName
+   *
+   * @return
+   */
+  public boolean contains(String groupName)
+  {
+    return collection.contains(groupName);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  @Override
+  public Iterator<String> iterator()
+  {
+    return collection.iterator();
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  public Collection<String> getCollection()
+  {
+    return collection;
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private Collection<String> collection;
+}

File scm-webapp/src/main/java/sonia/scm/api/rest/resources/AuthenticationResource.java

View file
 import sonia.scm.ScmClientConfig;
 import sonia.scm.ScmState;
 import sonia.scm.config.ScmConfiguration;
+import sonia.scm.group.GroupNames;
 import sonia.scm.repository.RepositoryManager;
-import sonia.scm.security.Groups;
 import sonia.scm.security.ScmAuthenticationToken;
 import sonia.scm.user.User;
 import sonia.scm.user.UserManager;
   {
     PrincipalCollection collection = subject.getPrincipals();
     User user = collection.oneByType(User.class);
-    Groups groups = collection.oneByType(Groups.class);
+    GroupNames groups = collection.oneByType(GroupNames.class);
 
-    return new ScmState(contextProvider, user, groups.getGroups(),
+    return new ScmState(contextProvider, user, groups.getCollection(),
       repositoryManger.getConfiguredTypes(), userManager.getDefaultType(),
       new ScmClientConfig(configuration));
   }

File scm-webapp/src/main/java/sonia/scm/security/Groups.java

-/**
- * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer. 2. Redistributions in
- * binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution. 3. Neither the name of SCM-Manager;
- * nor the names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * http://bitbucket.org/sdorra/scm-manager
- *
- */
-
-
-
-package sonia.scm.security;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import java.io.Serializable;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-public class Groups implements Serializable, Iterable<String>
-{
-
-  /** Field description */
-  private static final long serialVersionUID = -4152799570939669716L;
-
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   *
-   * @param groups
-   */
-  public Groups(Collection<String> groups)
-  {
-    this.groups = groups;
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  @Override
-  public Iterator<String> iterator()
-  {
-    return getGroups().iterator();
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  public Collection<String> getGroups()
-  {
-    if (groups == null)
-    {
-      groups = Collections.EMPTY_LIST;
-    }
-
-    return groups;
-  }
-
-  //~--- fields ---------------------------------------------------------------
-
-  /** Field description */
-  private Collection<String> groups;
-}

File scm-webapp/src/main/java/sonia/scm/security/ScmRealm.java

View file
 import sonia.scm.config.ScmConfiguration;
 import sonia.scm.group.Group;
 import sonia.scm.group.GroupManager;
+import sonia.scm.group.GroupNames;
 import sonia.scm.repository.Permission;
 import sonia.scm.repository.PermissionType;
 import sonia.scm.repository.Repository;
         logger.trace("coullect AuthorizationInfo for user {}", user.getName());
       }
 
-      Groups groups = principals.oneByType(Groups.class);
+      GroupNames groups = principals.oneByType(GroupNames.class);
 
       info = createAuthorizationInfo(user, groups);
     }
      */
     collection.add(user.getId(), NAME);
     collection.add(user, NAME);
-    collection.add(new Groups(groups), NAME);
+    collection.add(new GroupNames(groups), NAME);
 
     return new SimpleAuthenticationInfo(collection, token.getPassword());
   }
    *
    * @return
    */
-  private AuthorizationInfo createAuthorizationInfo(User user, Groups groups)
+  private AuthorizationInfo createAuthorizationInfo(User user,
+    GroupNames groups)
   {
     Set<String> roles = Sets.newHashSet();
     List<org.apache.shiro.authz.Permission> permissions = null;

File scm-webapp/src/main/java/sonia/scm/web/security/BasicSecurityContext.java

View file
 import org.slf4j.LoggerFactory;
 
 import sonia.scm.config.ScmConfiguration;
-import sonia.scm.security.Groups;
 import sonia.scm.security.ScmAuthenticationToken;
 import sonia.scm.user.User;
 import sonia.scm.user.UserManager;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
+import sonia.scm.group.GroupNames;
 
 /**
  *
   public Collection<String> getGroups()
   {
     Subject subject = SecurityUtils.getSubject();
-    Groups groups = getPrincipal(Groups.class);
+    GroupNames groups = getPrincipal(GroupNames.class);
 
     Collection<String> groupCollection = null;
 
     if (groups != null)
     {
-      groupCollection = groups.getGroups();
+      groupCollection = groups.getCollection();
     }
     else
     {