mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-04-01 18:00:12 +02:00
changes for issue '#2 Support applying permissions to groups as well as users'
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user