mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Add method to check if authorities already exist
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2957 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="permissionServiceImpl" class="org.alfresco.repo.security.permissions.impl.PermissionServiceImpl">
|
||||
<bean id="permissionServiceImpl" class="org.alfresco.repo.security.permissions.impl.AllowPermissionServiceImpl">
|
||||
<property name="nodeService">
|
||||
<ref bean="nodeService" />
|
||||
</property>
|
||||
@@ -578,6 +578,7 @@
|
||||
org.alfresco.service.cmr.security.AuthorityService.getContainingAuthorities=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.authorityExists=ACL_METHOD.ROLE_ADMINISTRATOR
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
@@ -88,4 +88,12 @@ public interface AuthorityDAO
|
||||
* @return
|
||||
*/
|
||||
Set<String> getAllAuthorities(AuthorityType type);
|
||||
|
||||
/**
|
||||
* Test if an authority already exists.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
boolean authorityExists(String name);
|
||||
}
|
||||
|
@@ -89,6 +89,13 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
this.userToAuthorityCache = userToAuthorityCache;
|
||||
}
|
||||
|
||||
public boolean authorityExists(String name)
|
||||
{
|
||||
NodeRef ref = getAuthorityOrNull(name);
|
||||
return ref != null;
|
||||
}
|
||||
|
||||
|
||||
public void addAuthority(String parentName, String childName)
|
||||
{
|
||||
NodeRef parentRef = getAuthorityOrNull(parentName);
|
||||
|
@@ -241,4 +241,9 @@ public class AuthorityServiceImpl implements AuthorityService
|
||||
authorityDAO.removeAuthority(parentName, childName);
|
||||
}
|
||||
|
||||
public boolean authorityExists(String name)
|
||||
{
|
||||
return authorityDAO.authorityExists(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -237,9 +237,11 @@ public class AuthorityServiceTest extends TestCase
|
||||
String auth4;
|
||||
String auth5;
|
||||
|
||||
assertFalse(pubAuthorityService.authorityExists(pubAuthorityService.getName(AuthorityType.GROUP, "one")));
|
||||
assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "one");
|
||||
assertTrue(pubAuthorityService.authorityExists(auth1));
|
||||
assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "two");
|
||||
|
@@ -207,4 +207,9 @@ public class SimpleAuthorityServiceImpl implements AuthorityService
|
||||
|
||||
}
|
||||
|
||||
public boolean authorityExists(String name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import javax.transaction.UserTransaction;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
@@ -91,7 +92,7 @@ public class SimpleAuthorityServiceTest extends TestCase
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
authenticationService.clearCurrentSecurityContext();
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
tx.rollback();
|
||||
super.tearDown();
|
||||
}
|
||||
@@ -106,6 +107,8 @@ public class SimpleAuthorityServiceTest extends TestCase
|
||||
|
||||
public void testAdminUser()
|
||||
{
|
||||
assertFalse(authorityService.authorityExists("woof"));
|
||||
|
||||
authenticationComponent.setCurrentUser("admin");
|
||||
assertTrue(authorityService.hasAdminAuthority());
|
||||
assertTrue(pubAuthorityService.hasAdminAuthority());
|
||||
@@ -119,6 +122,7 @@ public class SimpleAuthorityServiceTest extends TestCase
|
||||
|
||||
public void testAuthorities()
|
||||
{
|
||||
assertFalse(pubAuthorityService.authorityExists("woof"));
|
||||
assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.ADMIN).size());
|
||||
assertTrue(pubAuthorityService.getAllAuthorities(AuthorityType.ADMIN).contains(
|
||||
PermissionService.ADMINISTRATOR_AUTHORITY));
|
||||
|
@@ -172,4 +172,12 @@ public interface AuthorityService
|
||||
*/
|
||||
public String getName(AuthorityType type, String shortName);
|
||||
|
||||
/**
|
||||
* Check if an authority exists.
|
||||
*
|
||||
* @param name (the long name).
|
||||
* @return
|
||||
*/
|
||||
public boolean authorityExists(String name);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user