mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
changes for issue '#2 Support applying permissions to groups as well as users'
This commit is contained in:
@@ -60,6 +60,7 @@ import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -323,6 +324,30 @@ public class XmlGroupManager extends AbstractGroupManager
|
||||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param member
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<Group> getGroupsForMember(String member)
|
||||
{
|
||||
LinkedList<Group> groups = new LinkedList<Group>();
|
||||
|
||||
for (Group group : groupDB.values())
|
||||
{
|
||||
if (group.isMember(member))
|
||||
{
|
||||
groups.add(group.clone());
|
||||
}
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,11 +42,17 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.group.GroupManager;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserManager;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -74,15 +80,18 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
*
|
||||
* @param configuration
|
||||
* @param authenticator
|
||||
* @param groupManager
|
||||
* @param userManager
|
||||
*/
|
||||
@Inject
|
||||
public BasicSecurityContext(ScmConfiguration configuration,
|
||||
AuthenticationManager authenticator,
|
||||
GroupManager groupManager,
|
||||
UserManager userManager)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.authenticator = authenticator;
|
||||
this.groupManager = groupManager;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
@@ -128,6 +137,8 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
{
|
||||
userManager.create(user);
|
||||
}
|
||||
|
||||
loadGroups();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -150,10 +161,28 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
public void logout(HttpServletRequest request, HttpServletResponse response)
|
||||
{
|
||||
user = null;
|
||||
groups = null;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<String> getGroups()
|
||||
{
|
||||
if (groups == null)
|
||||
{
|
||||
groups = new HashSet<String>();
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -183,6 +212,28 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
return getUser() != null;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
private void loadGroups()
|
||||
{
|
||||
groups = new HashSet<String>();
|
||||
|
||||
Collection<Group> groupCollection =
|
||||
groupManager.getGroupsForMember(user.getName());
|
||||
|
||||
if (groupCollection != null)
|
||||
{
|
||||
for (Group group : groupCollection)
|
||||
{
|
||||
groups.add(group.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@@ -191,6 +242,12 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
/** Field description */
|
||||
private ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private GroupManager groupManager;
|
||||
|
||||
/** Field description */
|
||||
private Set<String> groups = new HashSet<String>();
|
||||
|
||||
/** Field description */
|
||||
private User user;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user