From c6f5fe9078cdee0b63f46c00107f123e3817e36b Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Wed, 29 Jun 2011 13:13:47 +0000 Subject: [PATCH] HEAD test/build fix (SimpleAuthorityServiceTest) - does not in fact test the SimpleAuthorityService and effectively a subset of AuthorityServiceTest - fixed by removing it !! ... likely not used since r2746 (sic) when groups were merged in as a non-ent only feature (Alf 1.2'ish ?) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28691 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../authority/SimpleAuthorityServiceImpl.java | 381 ------------------ .../authority/SimpleAuthorityServiceTest.java | 160 -------- 2 files changed, 541 deletions(-) delete mode 100644 source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java delete mode 100644 source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceTest.java diff --git a/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java b/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java deleted file mode 100644 index 6fd3b9c3ad..0000000000 --- a/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.security.authority; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.alfresco.query.PagingRequest; -import org.alfresco.query.PagingResults; -import org.alfresco.repo.security.authentication.AuthenticationContext; -import org.alfresco.repo.tenant.TenantService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.security.AuthorityService; -import org.alfresco.service.cmr.security.AuthorityType; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.security.PersonService; -import org.alfresco.service.cmr.security.PersonService.PersonInfo; -import org.alfresco.util.Pair; - -/** - * The default implementation of the authority service. - * - * @author Andy Hind - */ -public class SimpleAuthorityServiceImpl implements AuthorityService -{ - private PersonService personService; - - private Set adminSet = Collections.singleton(PermissionService.ADMINISTRATOR_AUTHORITY); - - private Set guestSet = Collections.singleton(PermissionService.GUEST_AUTHORITY); - - private Set allSet = Collections.singleton(PermissionService.ALL_AUTHORITIES); - - private Set adminUsers; - - private AuthenticationContext authenticationContext; - - private Set guestUsers; - - private TenantService tenantService; - - - public SimpleAuthorityServiceImpl() - { - super(); - } - - public void setPersonService(PersonService personService) - { - this.personService = personService; - } - - public void setTenantService(TenantService tenantService) - { - this.tenantService = tenantService; - } - - - public boolean hasAdminAuthority() - { - String currentUserName = authenticationContext.getCurrentUserName(); - - // note: for MT, this currently relies on a naming convention which assumes that all tenant admins will - // have the same base name as the default non-tenant specific admin. Typically "admin" is the default required admin user, - // although, if for example "bob" is also listed as an admin then all tenant-specific bob's will also have admin authority - - return ((currentUserName != null) && (adminUsers.contains(currentUserName) || adminUsers.contains(tenantService.getBaseNameUser(currentUserName)))); - } - - public boolean isAdminAuthority(String authorityName) - { - String canonicalName = personService.getUserIdentifier(authorityName); - if (canonicalName == null) - { - canonicalName = authorityName; - } - return adminUsers.contains(canonicalName); - } - - public boolean hasGuestAuthority() - { - String currentUserName = authenticationContext.getCurrentUserName(); - - // note: for MT, this currently relies on a naming convention which assumes that all tenant admins will - // have the same base name as the default non-tenant specific guest. - - return ((currentUserName != null) && (guestUsers.contains(currentUserName) || guestUsers.contains(tenantService.getBaseNameUser(currentUserName)))); - } - - public boolean isGuestAuthority(String authorityName) - { - String canonicalName = personService.getUserIdentifier(authorityName); - if (canonicalName == null) - { - canonicalName = authorityName; - } - return guestUsers.contains(canonicalName); - } - - // IOC - - public void setAuthenticationContext(AuthenticationContext authenticationContext) - { - this.authenticationContext = authenticationContext; - } - - public void setAdminUsers(Set adminUsers) - { - this.adminUsers = adminUsers; - } - - public void setGuestUsers(Set guestUsers) - { - this.guestUsers = guestUsers; - } - - public Set getAuthorities() - { - Set authorities = new HashSet(); - String currentUserName = authenticationContext.getCurrentUserName(); - if (adminUsers.contains(currentUserName)) - { - authorities.addAll(adminSet); - } - else if (!guestUsers.contains(currentUserName)) - { - authorities.addAll(allSet); - } - return authorities; - } - - public Set getAllAuthorities(AuthorityType type) - { - Set authorities = new HashSet(); - switch (type) - { - case ADMIN: - authorities.addAll(adminSet); - break; - case EVERYONE: - authorities.addAll(allSet); - break; - case GUEST: - authorities.addAll(guestSet); - break; - case GROUP: - authorities.addAll(allSet); - break; - case OWNER: - break; - case ROLE: - break; - case USER: - for (PersonInfo person : personService.getPeople(null, true, null, new PagingRequest(0, Integer.MAX_VALUE, null)).getPage()) - { - authorities.add(person.getUserName()); - } - break; - default: - break; - } - return authorities; - } - - public PagingResults getAuthorities(AuthorityType type, String zoneName, String displayNameFilter, boolean sortByDisplayName, boolean sortAscending, PagingRequest pagingRequest) - { - return new PagingResults() - { - @Override - public String getQueryExecutionId() - { - return null; - } - @Override - public List getPage() - { - return Collections.emptyList(); - } - @Override - public boolean hasMoreItems() - { - return false; - } - @Override - public Pair getTotalResultCount() - { - return null; - } - @Override - public boolean permissionsApplied() - { - return true; - } - }; - } - - public void addAuthority(String parentName, String childName) - { - - } - - public void addAuthority(Collection parentNames, String childName) - { - - } - - public String createAuthority(AuthorityType type, String shortName) - { - return ""; - } - - - public void deleteAuthority(String name) - { - - } - - public void deleteAuthority(String name, boolean cascade) - { - - } - - public Set getAllRootAuthorities(AuthorityType type) - { - return getAllAuthorities(type); - } - - public Set getContainedAuthorities(AuthorityType type, String name, boolean immediate) - { - return Collections.emptySet(); - } - - public Set getContainingAuthorities(AuthorityType type, String name, boolean immediate) - { - return Collections.emptySet(); - } - - public String getName(AuthorityType type, String shortName) - { - if (type.isFixedString()) - { - return type.getFixedString(); - } - else if (type.isPrefixed()) - { - return type.getPrefixString() + shortName; - } - else - { - return shortName; - } - } - - public String getShortName(String name) - { - AuthorityType type = AuthorityType.getAuthorityType(name); - if (type.isFixedString()) - { - return ""; - } - else if (type.isPrefixed()) - { - return name.substring(type.getPrefixString().length()); - } - else - { - return name; - } - - } - - public void removeAuthority(String parentName, String childName) - { - - } - - public boolean authorityExists(String name) - { - return false; - } - - public Set getAuthoritiesForUser(String currentUserName) - { - Set authorities = new HashSet(); - if (adminUsers.contains(currentUserName)) - { - authorities.addAll(adminSet); - } - if(AuthorityType.getAuthorityType(currentUserName) != AuthorityType.GUEST) - { - authorities.addAll(allSet); - } - return authorities; - } - - public String getAuthorityDisplayName(String name) - { - return ""; - } - - public void setAuthorityDisplayName(String authorityName, String authorityDisplayName) - { - - } - - public Set getAllAuthoritiesInZone(String zoneName, AuthorityType type) - { - return Collections.emptySet(); - } - - public NodeRef getOrCreateZone(String zoneName) - { - return null; - } - - public void addAuthorityToZones(String authorityName, Set zones) - { - - } - - public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, Set authorityZones) - { - return ""; - } - - public Set getAllRootAuthoritiesInZone(String zoneName, AuthorityType type) - { - return Collections.emptySet(); - } - - public Set getAuthorityZones(String name) - { - return Collections.emptySet(); - } - - public Set getDefaultZones() - { - return Collections.emptySet(); - } - - public void removeAuthorityFromZones(String authorityName, Set zones) - { - - } - - public NodeRef getZone(String zoneName) - { - return null; - } - - public NodeRef getAuthorityNodeRef(String name) - { - return null; - } - - public Set findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, - String displayNamePattern, String zoneName) - { - return Collections.emptySet(); - } -} diff --git a/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceTest.java b/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceTest.java deleted file mode 100644 index 038336abeb..0000000000 --- a/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.security.authority; - -import java.util.List; - -import javax.transaction.Status; -import javax.transaction.UserTransaction; - -import junit.framework.TestCase; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.query.PagingRequest; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.MutableAuthenticationDao; -import org.alfresco.repo.transaction.AlfrescoTransactionSupport; -import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.security.AuthorityService; -import org.alfresco.service.cmr.security.AuthorityType; -import org.alfresco.service.cmr.security.MutableAuthenticationService; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.security.PersonService; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.util.ApplicationContextHelper; -import org.springframework.context.ApplicationContext; - -public class SimpleAuthorityServiceTest extends TestCase -{ - private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); - - private AuthenticationComponent authenticationComponent; - - private MutableAuthenticationService authenticationService; - - private AuthorityService authorityService; - - private AuthorityService pubAuthorityService; - - private MutableAuthenticationDao authenticationDAO; - - private PersonService personService; - - private UserTransaction tx; - - public SimpleAuthorityServiceTest() - { - super(); - - } - - public void setUp() throws Exception - { - if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) - { - throw new AlfrescoRuntimeException( - "A previous tests did not clean up transaction: " + - AlfrescoTransactionSupport.getTransactionId()); - } - - authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); - authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService"); - authorityService = (AuthorityService) ctx.getBean("authorityService"); - pubAuthorityService = (AuthorityService) ctx.getBean("AuthorityService"); - personService = (PersonService) ctx.getBean("personService"); - authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao"); - - this.authenticationComponent.setSystemUserAsCurrentUser(); - - TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE - .getLocalName()); - tx = transactionService.getUserTransaction(); - tx.begin(); - - if (!authenticationDAO.userExists("andy")) - { - authenticationService.createAuthentication("andy", "andy".toCharArray()); - } - - if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName())) - { - authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray()); - } - - if (!authenticationDAO.userExists("administrator")) - { - authenticationService.createAuthentication("administrator", "administrator".toCharArray()); - } - } - - @Override - protected void tearDown() throws Exception - { - if ((tx.getStatus() == Status.STATUS_ACTIVE) || (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)) - { - tx.rollback(); - } - AuthenticationUtil.clearCurrentSecurityContext(); - super.tearDown(); - } - - public void testNonAdminUser() - { - authenticationComponent.setCurrentUser("andy"); - assertFalse(authorityService.hasAdminAuthority()); - assertFalse(pubAuthorityService.hasAdminAuthority()); - assertEquals(1, authorityService.getAuthorities().size()); - } - - public void testAdminUser() - { - assertFalse(authorityService.authorityExists("woof")); - - authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); - assertTrue(authorityService.hasAdminAuthority()); - assertTrue(pubAuthorityService.hasAdminAuthority()); - assertEquals(6, authorityService.getAuthorities().size()); - } - - public void testAuthorities() - { - assertFalse(pubAuthorityService.authorityExists("woof")); - assertEquals(1, getAllAuthorities(AuthorityType.ADMIN).size()); - assertTrue(getAllAuthorities(AuthorityType.ADMIN).contains(PermissionService.ADMINISTRATOR_AUTHORITY)); - assertEquals(1, getAllAuthorities(AuthorityType.EVERYONE).size()); - assertTrue(getAllAuthorities(AuthorityType.EVERYONE).contains(PermissionService.ALL_AUTHORITIES)); - assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); - assertEquals(1, getAllAuthorities(AuthorityType.GUEST).size()); - assertTrue(getAllAuthorities(AuthorityType.GUEST).contains(PermissionService.GUEST_AUTHORITY)); - assertEquals(0, getAllAuthorities(AuthorityType.OWNER).size()); - assertEquals(0, getAllAuthorities(AuthorityType.ROLE).size()); - assertEquals(2, getAllAuthorities(AuthorityType.USER).size()); - - int peopleCnt = personService.getPeople(null, true, null, new PagingRequest(0, Integer.MAX_VALUE, null)).getPage().size(); - assertEquals(peopleCnt, getAllAuthorities(AuthorityType.USER).size()); - } - - private List getAllAuthorities(AuthorityType type) - { - return pubAuthorityService.getAuthorities(type, null, null, false, true, new PagingRequest(0, Integer.MAX_VALUE, null)).getPage(); - } - -}