replace groups class with groupnames

This commit is contained in:
Sebastian Sdorra
2012-08-30 10:38:56 +02:00
parent c7f11a8203
commit 81060af003
4 changed files with 52 additions and 24 deletions

View File

@@ -1,101 +0,0 @@
/**
* 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;
}

View File

@@ -60,6 +60,7 @@ import sonia.scm.cache.CacheManager;
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;
@@ -273,7 +274,7 @@ public class ScmRealm extends AuthorizingRealm
logger.trace("coullect AuthorizationInfo for user {}", user.getName());
}
Groups groups = principals.oneByType(Groups.class);
GroupNames groups = principals.oneByType(GroupNames.class);
info = createAuthorizationInfo(user, groups);
}
@@ -545,7 +546,7 @@ public class ScmRealm extends AuthorizingRealm
*/
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());
}
@@ -559,7 +560,8 @@ public class ScmRealm extends AuthorizingRealm
*
* @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;