First cut REST group api - read methods working.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13891 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2009-04-07 15:36:16 +00:00
parent caf8143451
commit 14413ff7ee
7 changed files with 226 additions and 53 deletions

View File

@@ -694,6 +694,7 @@
org.alfresco.service.cmr.security.AuthorityService.getAuthorities=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAuthorities=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.getAllAuthorities=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAllAuthorities=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.getAllRootAuthorities=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAllRootAuthorities=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.findAuthoritiesByShortName=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.findAuthorities=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.findAuthorities=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.createAuthority=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.createAuthority=ACL_METHOD.ROLE_ADMINISTRATOR
org.alfresco.service.cmr.security.AuthorityService.addAuthority=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.addAuthority=ACL_METHOD.ROLE_ADMINISTRATOR
@@ -703,7 +704,7 @@
org.alfresco.service.cmr.security.AuthorityService.getContainingAuthorities=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getContainingAuthorities=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.getShortName=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getShortName=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.getName=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getName=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.authorityExists=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.authorityExists=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.getAuthoritiesForUser=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.getAuthoritiesForUser=ACL_METHOD.ROLE_ADMINISTRATOR
org.alfresco.service.cmr.security.AuthorityService.setAuthorityDisplayName=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.setAuthorityDisplayName=ACL_METHOD.ROLE_ADMINISTRATOR
org.alfresco.service.cmr.security.AuthorityService.getAuthorityDisplayName=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAuthorityDisplayName=ACL_ALLOW

View File

@@ -257,6 +257,13 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
return authorities; return authorities;
} }
public Set<String> findAuthoritiesByShortName(AuthorityType type, String shortNamePattern)
{
String fullNamePattern = getName(type, shortNamePattern);
return findAuthorities(type, fullNamePattern);
}
public void addAuthority(String parentName, String childName) public void addAuthority(String parentName, String childName)
{ {
if (AuthorityType.getAuthorityType(childName).equals(AuthorityType.USER)) if (AuthorityType.getAuthorityType(childName).equals(AuthorityType.USER))

View File

@@ -284,4 +284,11 @@ public class SimpleAuthorityServiceImpl implements AuthorityService
} }
public Set<String> findAuthoritiesByShortName(AuthorityType type,
String shortNamePattern)
{
String fullNamePattern = getName(type, shortNamePattern);
return findAuthorities(type, fullNamePattern);
}
} }

View File

@@ -24,16 +24,13 @@
*/ */
package org.alfresco.repo.security.authority.script; package org.alfresco.repo.security.authority.script;
import java.util.List; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import org.alfresco.repo.jscript.BaseScopableProcessorExtension; import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.AuthorityType;
/** /**
* Script object representing the authority service. * Script object representing the authority service.
* *
@@ -59,11 +56,17 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
* Search the root groups, those without a parent group. * Search the root groups, those without a parent group.
* @return The root groups (empty if there are no root groups) * @return The root groups (empty if there are no root groups)
*/ */
public ScriptGroup[] searchRootGroups(String pattern, boolean includeInternal) public ScriptGroup[] searchRootGroups(String shortNamePattern, boolean includeInternal)
{ {
ScriptGroup[] groups = new ScriptGroup[0]; Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>(0);
Set<String> authorities = authorityService.getAllRootAuthorities(AuthorityType.GROUP); Set<String> authorities = authorityService.getAllRootAuthorities(AuthorityType.GROUP);
return groups; for(String authority : authorities)
{
ScriptGroup group = new ScriptGroup(authority, authorityService);
groups.add(group);
}
return groups.toArray(new ScriptGroup[groups.size()]);
} }
/** /**
@@ -72,20 +75,34 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
*/ */
public ScriptGroup[] getAllRootGroups(boolean includeInternal) public ScriptGroup[] getAllRootGroups(boolean includeInternal)
{ {
ScriptGroup[] groups = new ScriptGroup[0]; Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>(0);
Set<String> authorities = authorityService.getAllRootAuthorities(AuthorityType.GROUP); Set<String> authorities = authorityService.getAllRootAuthorities(AuthorityType.GROUP);
return groups; for(String authority : authorities)
{
ScriptGroup group = new ScriptGroup(authority, authorityService);
groups.add(group);
}
return groups.toArray(new ScriptGroup[groups.size()]);
} }
/** /**
* Get a group given its short name * Get a group given its short name
* @param shortName * @param shortName
* @return * @return the authority or null if it can't be found
*/ */
public ScriptGroup getGroup(String shortName) public ScriptGroup getGroup(String shortName)
{ {
Set<String> authorities = authorityService.findAuthorities(AuthorityType.GROUP, shortName);
return new ScriptGroup(); String fullName = authorityService.getName(AuthorityType.GROUP, shortName);
if (authorityService.authorityExists(fullName))
{
ScriptGroup group = new ScriptGroup(fullName, authorityService);
return group;
}
// group not found.
return null;
} }
/** /**
@@ -94,23 +111,28 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
*/ */
public ScriptGroup createRootGroup(String shortName, String displayName) public ScriptGroup createRootGroup(String shortName, String displayName)
{ {
String newName = authorityService.createAuthority(AuthorityType.GROUP, null, shortName, displayName); authorityService.createAuthority(AuthorityType.GROUP, null, shortName, displayName);
return getGroup(shortName);
return new ScriptGroup();
} }
/** /**
* Search for groups * Search for groups
* *
* @param shortNameFilter partial match on shortName (* and ?) work. if empty then matches everything. * @param shortNameFilter partial match on shortName (* and ?) work. If empty then matches everything.
* @param includeInternal * @param includeInternal
* @return the groups matching the query * @return the groups matching the query
*/ */
public ScriptGroup[] listGroups(String shortNameFilter, boolean includeInternal) public ScriptGroup[] searchGroups(String shortNameFilter, boolean includeInternal)
{ {
ScriptGroup[] groups = new ScriptGroup[0]; Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>(0);
Set<String> authorities = authorityService.findAuthorities(AuthorityType.GROUP, shortNameFilter); Set<String> authorities = authorityService.findAuthoritiesByShortName(AuthorityType.GROUP, shortNameFilter);
return groups; for(String authority : authorities)
{
ScriptGroup group = new ScriptGroup(authority, authorityService);
groups.add(group);
}
return groups.toArray(new ScriptGroup[groups.size()]);
} }
} }

View File

@@ -26,6 +26,7 @@ package org.alfresco.repo.security.authority.script;
import java.io.Serializable; import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import org.alfresco.repo.security.authority.script.Authority.ScriptAuthorityType; import org.alfresco.repo.security.authority.script.Authority.ScriptAuthorityType;
@@ -38,11 +39,29 @@ import org.alfresco.service.cmr.security.AuthorityType;
*/ */
public class ScriptGroup implements Authority, Serializable public class ScriptGroup implements Authority, Serializable
{ {
/**
*
*/
private static final long serialVersionUID = 6073732221341647273L;
/**
*
*/
private transient AuthorityService authorityService; private transient AuthorityService authorityService;
private ScriptAuthorityType authorityType = ScriptAuthorityType.GROUP; private ScriptAuthorityType authorityType = ScriptAuthorityType.GROUP;
private String shortName; private String shortName;
private String fullName; private String fullName;
private String displayName; private String displayName;
private boolean isAdmin;
// how to calculate this private boolean isInternal;
public ScriptGroup(String fullName, AuthorityService authorityService)
{
this.authorityService = authorityService;
this.fullName = fullName;
shortName = authorityService.getShortName(fullName);
displayName = authorityService.getAuthorityDisplayName(fullName);
isAdmin = authorityService.isAdminAuthority(fullName);
}
/** /**
* Delete this group * Delete this group
@@ -52,14 +71,6 @@ public class ScriptGroup implements Authority, Serializable
authorityService.deleteAuthority(fullName); authorityService.deleteAuthority(fullName);
} }
/**
* Get the parents of this group.
*/
ScriptGroup[] getParents()
{
return null;
}
public void setAuthorityType(ScriptAuthorityType authorityType) { public void setAuthorityType(ScriptAuthorityType authorityType) {
this.authorityType = authorityType; this.authorityType = authorityType;
} }
@@ -95,32 +106,138 @@ public class ScriptGroup implements Authority, Serializable
/** /**
* Get child groups of this group * Get child groups of this group
*/ */
ScriptUser[] getUsers() private ScriptUser[] childUsers;
public ScriptUser[] getChildUsers()
{ {
Set<String> users = authorityService.getContainedAuthorities(AuthorityType.USER, fullName, true); if(childUsers == null)
//TODO {
return null; Set<String> children = authorityService.getContainedAuthorities(AuthorityType.USER, fullName, true);
Set<ScriptUser> users = new LinkedHashSet<ScriptUser>();
for(String authority : children)
{
ScriptUser user = new ScriptUser(authority, authorityService);
users.add(user);
}
childUsers = users.toArray(new ScriptUser[users.size()]);
}
return childUsers;
} }
/** /**
* Get child groups of this group * Get child groups of this group
*/ */
ScriptGroup[] getChildGroups() public ScriptGroup[] getChildGroups()
{ {
Set<String> children = authorityService.getContainedAuthorities(AuthorityType.GROUP, fullName, true); Set<String> children = authorityService.getContainedAuthorities(AuthorityType.GROUP, fullName, true);
//TODO Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>();
for(String authority : children)
{
ScriptGroup group = new ScriptGroup(authority, authorityService);
groups.add(group);
return null; }
return groups.toArray(new ScriptGroup[groups.size()]);
} }
/** /**
* Get the parents of this this group * Get the parents of this this group
*/ */
ScriptGroup[] getParentGroups() private ScriptGroup[] parentCache;
public ScriptGroup[] getParentGroups()
{
if(parentCache == null)
{ {
Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, fullName, true); Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, fullName, true);
//TODO Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>();
return null; for(String authority : parents)
} {
ScriptGroup group = new ScriptGroup(authority, authorityService);
groups.add(group);
} }
parentCache = groups.toArray(new ScriptGroup[groups.size()]);
}
return parentCache;
}
/**
* Get all the parents of this this group
*/
public ScriptGroup[] getAllParentGroups()
{
Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, fullName, false);
Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>();
for(String authority : parents)
{
ScriptGroup group = new ScriptGroup(authority, authorityService);
groups.add(group);
}
return groups.toArray(new ScriptGroup[groups.size()]);
}
/**
* Get all the children of this group, regardless of type
*/
public Authority[] getAllChildren()
{
Authority[] groups = getChildGroups();
Authority[] users = getChildUsers();
Authority[] ret = new Authority[groups.length + users.length];
System.arraycopy(groups, 0, ret, 0, groups.length);
System.arraycopy(users, 0, ret, groups.length, users.length);
return ret;
}
/**
* Is this a root group?
* @return
*/
public boolean isRootGroup()
{
ScriptGroup[] groups = getParentGroups();
return (groups.length == 0);
}
/**
* Is this an admin group?
* @return
*/
public boolean isAdminGroup()
{
return this.isAdmin;
}
/**
* Is this an internal group?
* @return
*/
public boolean isInternalGroup()
{
//TODO Not yet implemeted
return true;
}
/**
* Get the number of users contained within this group.
* @return the number of users contained within this group.
*/
public int getUserCount()
{
ScriptUser[] users = getChildUsers();
return users.length;
}
/**
* Get the number of child groups contained within this group.
* @return the number of child groups contained within this group.
*/
public int getGroupCount()
{
ScriptGroup[] groups = getChildGroups();
return groups.length;
}
}

View File

@@ -42,6 +42,15 @@ public class ScriptUser implements Authority, Serializable
private String fullName; private String fullName;
private String displayName; private String displayName;
public ScriptUser(String fullName, AuthorityService authorityService)
{
this.authorityService = authorityService;
this.fullName = fullName;
shortName = authorityService.getShortName(fullName);
displayName = authorityService.getAuthorityDisplayName(fullName);
//isInternal = authorityService.
}
public void setAuthorityType(ScriptAuthorityType authorityType) { public void setAuthorityType(ScriptAuthorityType authorityType) {
this.authorityType = authorityType; this.authorityType = authorityType;
} }

View File

@@ -70,7 +70,7 @@ public interface AuthorityService
/** /**
* Get the authorities for the current user * Get the authorities for the current user
* *
* @return * @return authorities for the current user
*/ */
@Auditable @Auditable
public Set<String> getAuthorities(); public Set<String> getAuthorities();
@@ -86,16 +86,26 @@ public interface AuthorityService
* *
* @param type - * @param type -
* the type of authorities. * the type of authorities.
* @return * @return all authorities by type.
*/ */
@Auditable(parameters = {"type"}) @Auditable(parameters = {"type"})
public Set<String> getAllAuthorities(AuthorityType type); public Set<String> getAllAuthorities(AuthorityType type);
/** /**
* Find authorities by pattern matching (* and ?) * Find authorities by pattern matching (* and ?) against the authority name.
* @param type - the authority type * @param type - the authority type
* @param namePattern - the pattern * @param namePattern - the pattern which will be matched against the shortName.
* @return * @return the names of the authorities matching the pattern and type.
*/
@Auditable(parameters = {"type"})
public Set<String> findAuthoritiesByShortName(AuthorityType type, String shortNamePattern);
/**
* Find authorities by pattern matching (* and ?) against the full authority name.
* @param type - the authority type
* @param namePattern - the pattern which will be matched against the full authority name.
* @return the names of the authorites matching the pattern and type.
*/ */
@Auditable(parameters = {"type"}) @Auditable(parameters = {"type"})
public Set<String> findAuthorities(AuthorityType type, String namePattern); public Set<String> findAuthorities(AuthorityType type, String namePattern);
@@ -107,7 +117,7 @@ public interface AuthorityService
* *
* @param type - * @param type -
* the type of the authority * the type of the authority
* @return * @return all root authorities by type.
*/ */
@Auditable(parameters = {"type"}) @Auditable(parameters = {"type"})
public Set<String> getAllRootAuthorities(AuthorityType type); public Set<String> getAllRootAuthorities(AuthorityType type);
@@ -119,7 +129,7 @@ public interface AuthorityService
* @param type - * @param type -
* the type of the authority * the type of the authority
* @param parentName - * @param parentName -
* the name of the parent authority. If this is null then a root * the full name of the parent authority. If this is null then a root
* authority is created. * authority is created.
* @param shortName - * @param shortName -
* the short name of the authority to create * the short name of the authority to create
@@ -132,20 +142,20 @@ public interface AuthorityService
public String createAuthority(AuthorityType type, String parentName, String shortName); public String createAuthority(AuthorityType type, String parentName, String shortName);
/** /**
* Create an authority. If the parent is null thisw method creates a root * Create an authority. If the parent is null this method creates a root
* authority. * authority.
* *
* @param type - * @param type -
* the type of the authority * the type of the authority
* @param parentName - * @param parentName -
* the name of the parent authority. If this is null then a root * the full name of the parent authority. If this is null then a root
* authority is created. * authority is created.
* @param shortName - * @param shortName -
* the short name of the authority to create * the short name of the authority to create
* @param authorityDisplayName * @param authorityDisplayName
* the display name for the authority * the display name for the authority
* *
* @return the name of the authority (this will be the prefix, if any * @return the full name of the authority (this will be the prefix, if any
* associated with the type appended with the short name) * associated with the type appended with the short name)
*/ */
@Auditable(parameters = {"type", "parentName", "shortName", "authorityDisplayName"}) @Auditable(parameters = {"type", "parentName", "shortName", "authorityDisplayName"})
@@ -156,7 +166,7 @@ public interface AuthorityService
* group to a group or adding a user to a group. * group to a group or adding a user to a group.
* *
* @param parentName - * @param parentName -
* the string identifier for the parent. * the full name string identifier for the parent.
* @param childName - * @param childName -
* the string identifier for the child. * the string identifier for the child.
*/ */
@@ -245,7 +255,7 @@ public interface AuthorityService
* Check if an authority exists. * Check if an authority exists.
* *
* @param name (the long name). * @param name (the long name).
* @return * @return true, the authority exists.
*/ */
@Auditable(parameters = {"name"}) @Auditable(parameters = {"name"})
public boolean authorityExists(String name); public boolean authorityExists(String name);