mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-05-07 03:26:32 +02:00
improve api for global permissions
This commit is contained in:
@@ -31,27 +31,69 @@
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.31
|
||||
*/
|
||||
public class SecurityConfigurationChangedEvent
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlRootElement(name = "assigned-permission")
|
||||
public class AssignedPermission implements PermissionObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor is only visible for JAXB.
|
||||
*
|
||||
*/
|
||||
public AssignedPermission() {}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param oldConfiguration
|
||||
* @param newConfiguration
|
||||
* @param permission
|
||||
*/
|
||||
public SecurityConfigurationChangedEvent(
|
||||
SecurityConfiguration oldConfiguration,
|
||||
SecurityConfiguration newConfiguration)
|
||||
public AssignedPermission(AssignedPermission permission)
|
||||
{
|
||||
this.oldConfiguration = oldConfiguration;
|
||||
this.newConfiguration = newConfiguration;
|
||||
this.name = permission.name;
|
||||
this.groupPermission = permission.groupPermission;
|
||||
this.permission = permission.permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param permission
|
||||
*/
|
||||
public AssignedPermission(String name, String permission)
|
||||
{
|
||||
this.name = name;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param groupPermission
|
||||
* @param permission
|
||||
*/
|
||||
public AssignedPermission(String name, boolean groupPermission,
|
||||
String permission)
|
||||
{
|
||||
this.name = name;
|
||||
this.groupPermission = groupPermission;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -62,9 +104,10 @@ public class SecurityConfigurationChangedEvent
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SecurityConfiguration getNewConfiguration()
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return newConfiguration;
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,16 +116,32 @@ public class SecurityConfigurationChangedEvent
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SecurityConfiguration getOldConfiguration()
|
||||
public String getPermission()
|
||||
{
|
||||
return oldConfiguration;
|
||||
return permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isGroupPermission()
|
||||
{
|
||||
return groupPermission;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private SecurityConfiguration newConfiguration;
|
||||
@XmlElement(name = "group-permission")
|
||||
private boolean groupPermission;
|
||||
|
||||
/** Field description */
|
||||
private SecurityConfiguration oldConfiguration;
|
||||
private String name;
|
||||
|
||||
/** Field description */
|
||||
private String permission;
|
||||
}
|
||||
@@ -49,49 +49,36 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.31
|
||||
*/
|
||||
@XmlRootElement(name = "permissions")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlRootElement(name = "global-permission")
|
||||
public final class GlobalPermission implements PermissionObject, Serializable
|
||||
public class PermissionDescriptor implements Serializable
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final long serialVersionUID = 4794267414178121515L;
|
||||
private static final long serialVersionUID = -9141065458354047154L;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
* Constructor is only visible for JAXB.
|
||||
*
|
||||
*/
|
||||
public GlobalPermission() {}
|
||||
public PermissionDescriptor() {}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param permission
|
||||
* @param displayName
|
||||
* @param description
|
||||
* @param value
|
||||
*/
|
||||
public GlobalPermission(String name, String permission)
|
||||
public PermissionDescriptor(String displayName, String description,
|
||||
String value)
|
||||
{
|
||||
this(name, false, permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param group
|
||||
* @param permission
|
||||
*/
|
||||
public GlobalPermission(String name, boolean groupPermission, String permission)
|
||||
{
|
||||
this.name = name;
|
||||
this.groupPermission = groupPermission;
|
||||
this.permission = permission;
|
||||
this.displayName = displayName;
|
||||
this.description = description;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -117,13 +104,11 @@ public final class GlobalPermission implements PermissionObject, Serializable
|
||||
return false;
|
||||
}
|
||||
|
||||
final GlobalPermission other = (GlobalPermission) obj;
|
||||
final PermissionDescriptor other = (PermissionDescriptor) obj;
|
||||
|
||||
//J-
|
||||
return Objects.equal(name, other.name)
|
||||
&& Objects.equal(groupPermission, other.groupPermission)
|
||||
&& Objects.equal(permission, other.permission);
|
||||
//J+
|
||||
return Objects.equal(displayName, other.displayName)
|
||||
&& Objects.equal(description, other.description)
|
||||
&& Objects.equal(value, other.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +120,7 @@ public final class GlobalPermission implements PermissionObject, Serializable
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hashCode(name, groupPermission, permission);
|
||||
return Objects.hashCode(displayName, description, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,12 +132,14 @@ public final class GlobalPermission implements PermissionObject, Serializable
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
||||
//J-
|
||||
return Objects.toStringHelper(this)
|
||||
.add("name", name)
|
||||
.add("groupPermission", groupPermission)
|
||||
.add("permisison", permission)
|
||||
.add("displayName", displayName)
|
||||
.add("description", description)
|
||||
.add("value", value)
|
||||
.toString();
|
||||
|
||||
//J+
|
||||
}
|
||||
|
||||
@@ -164,10 +151,9 @@ public final class GlobalPermission implements PermissionObject, Serializable
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getName()
|
||||
public String getDescription()
|
||||
{
|
||||
return name;
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,9 +162,9 @@ public final class GlobalPermission implements PermissionObject, Serializable
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPermission()
|
||||
public String getDisplayName()
|
||||
{
|
||||
return permission;
|
||||
return displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,21 +173,20 @@ public final class GlobalPermission implements PermissionObject, Serializable
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isGroupPermission()
|
||||
public String getValue()
|
||||
{
|
||||
return groupPermission;
|
||||
return value;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "group")
|
||||
private boolean groupPermission;
|
||||
private String description;
|
||||
|
||||
/** Field description */
|
||||
private String name;
|
||||
@XmlElement(name = "display-name")
|
||||
private String displayName;
|
||||
|
||||
/** Field description */
|
||||
private String permission;
|
||||
private String value;
|
||||
}
|
||||
@@ -33,8 +33,14 @@ package sonia.scm.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -47,9 +53,65 @@ public interface SecuritySystem
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param permission
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SecurityConfiguration getConfiguration();
|
||||
public StoredAssignedPermission addPermission(AssignedPermission permission);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param permission
|
||||
*/
|
||||
public void deletePermission(StoredAssignedPermission permission);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void deletePermission(String id);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* @param permission
|
||||
*/
|
||||
public void modifyPermission(StoredAssignedPermission permission);
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<StoredAssignedPermission> getAllPermissions();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<PermissionDescriptor> getAvailablePermissions();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param predicate
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<StoredAssignedPermission> getPermissions(
|
||||
Predicate<AssignedPermission> predicate);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -58,14 +120,4 @@ public interface SecuritySystem
|
||||
* @return
|
||||
*/
|
||||
public PrincipalCollection getSystemAccount();
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
*/
|
||||
public void setConfiguration(SecurityConfiguration configuration);
|
||||
}
|
||||
|
||||
@@ -31,18 +31,10 @@
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
@@ -50,31 +42,46 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.31
|
||||
*/
|
||||
@XmlRootElement(name = "security")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class SecurityConfiguration
|
||||
@XmlRootElement(name = "assigned-permission")
|
||||
public class StoredAssignedPermission extends AssignedPermission
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor is only visible for JAXB.
|
||||
*
|
||||
*/
|
||||
public StoredAssignedPermission() {}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* @param permission
|
||||
*/
|
||||
public StoredAssignedPermission(String id, AssignedPermission permission)
|
||||
{
|
||||
super(permission);
|
||||
this.id = id;
|
||||
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<GlobalPermission> getGlobalPermissions()
|
||||
public String getId()
|
||||
{
|
||||
if (globalPermissions == null)
|
||||
{
|
||||
globalPermissions = Lists.newArrayList();
|
||||
}
|
||||
|
||||
return globalPermissions;
|
||||
return id;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "permission")
|
||||
@XmlElementWrapper(name = "global-permissions")
|
||||
private List<GlobalPermission> globalPermissions;
|
||||
private String id;
|
||||
}
|
||||
Reference in New Issue
Block a user