changes for issue '#2 Support applying permissions to groups as well as users'

This commit is contained in:
Sebastian Sdorra
2011-01-07 18:15:11 +01:00
parent 426f3fe525
commit adf7fae446
9 changed files with 239 additions and 8 deletions

View File

@@ -377,6 +377,19 @@ public class Group
return type;
}
/**
* Method description
*
*
* @param member
*
* @return
*/
public boolean isMember(String member)
{
return (members != null) && members.contains(member);
}
/**
* Method description
*

View File

@@ -38,10 +38,25 @@ package sonia.scm.group;
import sonia.scm.ListenerSupport;
import sonia.scm.Manager;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
/**
*
* @author Sebastian Sdorra
*/
public interface GroupManager
extends Manager<Group, GroupException>,
ListenerSupport<GroupListener> {}
extends Manager<Group, GroupException>, ListenerSupport<GroupListener>
{
/**
* Method description
*
*
* @param member
*
* @return
*/
public Collection<Group> getGroupsForMember(String member);
}

View File

@@ -85,6 +85,21 @@ public class Permission implements Serializable
this.type = type;
}
/**
* Constructs ...
*
*
* @param name
* @param groupPermission
* @param type
*/
public Permission(String name, boolean groupPermission, PermissionType type)
{
this.name = name;
this.groupPermission = groupPermission;
this.type = type;
}
//~--- get methods ----------------------------------------------------------
/**
@@ -109,8 +124,30 @@ public class Permission implements Serializable
return type;
}
/**
* Method description
*
*
* @return
*/
public boolean isGroupPermission()
{
return groupPermission;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param groupPermission
*/
public void setGroupPermission(boolean groupPermission)
{
this.groupPermission = groupPermission;
}
/**
* Method description
*
@@ -135,6 +172,9 @@ public class Permission implements Serializable
//~--- fields ---------------------------------------------------------------
/** Field description */
private boolean groupPermission = false;
/** Field description */
private String name;

View File

@@ -43,6 +43,7 @@ import sonia.scm.web.security.WebSecurityContext;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import java.util.List;
/**
@@ -134,7 +135,8 @@ public class PermissionUtil
if (permissions != null)
{
result = hasPermission(permissions, username, pt);
result = hasPermission(permissions, username,
securityContext.getGroups(), pt);
}
}
@@ -147,12 +149,13 @@ public class PermissionUtil
*
* @param permissions
* @param username
* @param groups
* @param pt
*
* @return
*/
private static boolean hasPermission(List<Permission> permissions,
String username, PermissionType pt)
String username, Collection<String> groups, PermissionType pt)
{
boolean result = false;
@@ -160,12 +163,15 @@ public class PermissionUtil
{
String name = p.getName();
if ((name != null) && name.equalsIgnoreCase(username)
&& (p.getType().getValue() >= pt.getValue()))
if ((name != null) && (p.getType().getValue() >= pt.getValue()))
{
result = true;
if (name.equals(username)
|| (p.isGroupPermission() && groups.contains(p.getName())))
{
result = true;
break;
break;
}
}
}

View File

@@ -40,6 +40,8 @@ import sonia.scm.user.User;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -76,6 +78,14 @@ public interface WebSecurityContext extends SecurityContext
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Collection<String> getGroups();
/**
* Method description
*