mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Slight refactor/improvement to SecurityClearanceService as part of reviewing RM-2113.
The API had been dealing with Pair<PersonInfo, ClassificationLevel> objects and I've extracted that out into its own type: SecurityClearance. Should make some of the code more readable. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@103133 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2015 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.classification;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple data type for a single user's security clearance.
|
||||||
|
*
|
||||||
|
* @author Neil Mc Erlean
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public final class SecurityClearance implements Serializable
|
||||||
|
{
|
||||||
|
private final PersonInfo personInfo;
|
||||||
|
private final ClassificationLevel classificationLevel;
|
||||||
|
|
||||||
|
public SecurityClearance(final PersonInfo personInfo, final ClassificationLevel classificationLevel)
|
||||||
|
{
|
||||||
|
Objects.requireNonNull(personInfo);
|
||||||
|
Objects.requireNonNull(classificationLevel);
|
||||||
|
|
||||||
|
this.personInfo = personInfo;
|
||||||
|
this.classificationLevel = classificationLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the {@link PersonInfo} for this security clearance. */
|
||||||
|
public PersonInfo getPersonInfo() { return this.personInfo; }
|
||||||
|
|
||||||
|
/** Returns the {@link ClassificationLevel} for this security clearance. */
|
||||||
|
public ClassificationLevel getClassificationLevel() { return this.classificationLevel; }
|
||||||
|
|
||||||
|
@Override public String toString()
|
||||||
|
{
|
||||||
|
StringBuilder msg = new StringBuilder();
|
||||||
|
msg.append(SecurityClearance.class.getSimpleName())
|
||||||
|
.append(':').append(personInfo.getUserName())
|
||||||
|
.append(" [").append(classificationLevel).append(']');
|
||||||
|
|
||||||
|
return msg.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
SecurityClearance that = (SecurityClearance) o;
|
||||||
|
|
||||||
|
return this.personInfo.equals(that.personInfo) &&
|
||||||
|
this.classificationLevel.equals(that.classificationLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public int hashCode() { return Objects.hash(personInfo, classificationLevel); }
|
||||||
|
}
|
@@ -21,8 +21,6 @@ package org.alfresco.module.org_alfresco_module_rm.classification;
|
|||||||
import org.alfresco.query.PagingRequest;
|
import org.alfresco.query.PagingRequest;
|
||||||
import org.alfresco.query.PagingResults;
|
import org.alfresco.query.PagingResults;
|
||||||
import org.alfresco.service.cmr.security.NoSuchPersonException;
|
import org.alfresco.service.cmr.security.NoSuchPersonException;
|
||||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
|
||||||
import org.alfresco.util.Pair;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service offers access to users' security clearance levels.
|
* This service offers access to users' security clearance levels.
|
||||||
@@ -35,10 +33,10 @@ public interface SecurityClearanceService
|
|||||||
/**
|
/**
|
||||||
* Get the currently authenticated user's security clearance.
|
* Get the currently authenticated user's security clearance.
|
||||||
*
|
*
|
||||||
* @return a {@link PersonInfo}, {@link ClassificationLevel} pair for the currently authenticated user.
|
* @return the security clearance for the currently authenticated user.
|
||||||
* @throws NoSuchPersonException if the current user's person node cannot be found.
|
* @throws NoSuchPersonException if the current user's person node cannot be found.
|
||||||
*/
|
*/
|
||||||
Pair<PersonInfo, ClassificationLevel> getUserSecurityClearance();
|
SecurityClearance getUserSecurityClearance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get users' security clearances.
|
* Get users' security clearances.
|
||||||
@@ -46,9 +44,9 @@ public interface SecurityClearanceService
|
|||||||
* @param userNameFragment A username fragment which will be used to apply a 'starts with' query.
|
* @param userNameFragment A username fragment which will be used to apply a 'starts with' query.
|
||||||
* @param sortAscending if @code true} returns data sorted in ascending order by username.
|
* @param sortAscending if @code true} returns data sorted in ascending order by username.
|
||||||
* @param req paging request definition.
|
* @param req paging request definition.
|
||||||
* @return {@link PersonInfo}, {@link ClassificationLevel} pairs for the specified page of users.
|
* @return security clearances for the specified page of users.
|
||||||
*/
|
*/
|
||||||
PagingResults<Pair<PersonInfo, ClassificationLevel>> getUsersSecurityClearance(String userNameFragment,
|
PagingResults<SecurityClearance> getUsersSecurityClearance(String userNameFragment,
|
||||||
boolean sortAscending,
|
boolean sortAscending,
|
||||||
PagingRequest req);
|
PagingRequest req);
|
||||||
}
|
}
|
||||||
|
@@ -25,12 +25,10 @@ import static org.alfresco.model.ContentModel.PROP_USERNAME;
|
|||||||
import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.ASPECT_SECURITY_CLEARANCE;
|
import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.ASPECT_SECURITY_CLEARANCE;
|
||||||
import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.PROP_CLEARANCE_LEVEL;
|
import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.PROP_CLEARANCE_LEVEL;
|
||||||
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
|
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
|
||||||
import org.alfresco.query.PagingRequest;
|
import org.alfresco.query.PagingRequest;
|
||||||
import org.alfresco.query.PagingResults;
|
import org.alfresco.query.PagingResults;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
@@ -52,7 +50,7 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
|
|||||||
public void setClassificationService(ClassificationService service) { this.classificationService = service; }
|
public void setClassificationService(ClassificationService service) { this.classificationService = service; }
|
||||||
public void setPersonService (PersonService service) { this.personService = service; }
|
public void setPersonService (PersonService service) { this.personService = service; }
|
||||||
|
|
||||||
public Pair<PersonInfo, ClassificationLevel> getUserSecurityClearance()
|
public SecurityClearance getUserSecurityClearance()
|
||||||
{
|
{
|
||||||
final String currentUser = authenticationUtil.getFullyAuthenticatedUser();
|
final String currentUser = authenticationUtil.getFullyAuthenticatedUser();
|
||||||
Objects.requireNonNull(currentUser, "Fully authenticated user is null, which is not allowed.");
|
Objects.requireNonNull(currentUser, "Fully authenticated user is null, which is not allowed.");
|
||||||
@@ -60,7 +58,7 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
|
|||||||
return getUserSecurityClearance(currentUser);
|
return getUserSecurityClearance(currentUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<PersonInfo, ClassificationLevel> getUserSecurityClearance(final String userName)
|
private SecurityClearance getUserSecurityClearance(final String userName)
|
||||||
{
|
{
|
||||||
final NodeRef personNode = personService.getPerson(userName, false);
|
final NodeRef personNode = personService.getPerson(userName, false);
|
||||||
final PersonInfo personInfo = personService.getPerson(personNode);
|
final PersonInfo personInfo = personService.getPerson(personNode);
|
||||||
@@ -76,23 +74,23 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
|
|||||||
}
|
}
|
||||||
else { classificationLevel = classificationService.getDefaultClassificationLevel(); }
|
else { classificationLevel = classificationService.getDefaultClassificationLevel(); }
|
||||||
|
|
||||||
return new Pair<>(personInfo, classificationLevel);
|
return new SecurityClearance(personInfo, classificationLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PagingResults<Pair<PersonInfo, ClassificationLevel>> getUsersSecurityClearance(String userNameFragment,
|
public PagingResults<SecurityClearance> getUsersSecurityClearance(String userNameFragment,
|
||||||
boolean sortAscending,
|
boolean sortAscending,
|
||||||
PagingRequest req)
|
PagingRequest req)
|
||||||
{
|
{
|
||||||
final List<QName> filterProps = asList(PROP_USERNAME, PROP_FIRSTNAME, PROP_LASTNAME);
|
final List<QName> filterProps = asList(PROP_USERNAME, PROP_FIRSTNAME, PROP_LASTNAME);
|
||||||
final List<Pair<QName, Boolean>> sortProps = asList(new Pair<>(PROP_USERNAME, sortAscending));
|
final List<Pair<QName, Boolean>> sortProps = asList(new Pair<>(PROP_USERNAME, sortAscending));
|
||||||
|
|
||||||
final PagingResults<PersonInfo> p = personService.getPeople(userNameFragment, filterProps, sortProps, req);
|
final PagingResults<PersonInfo> p = personService.getPeople(userNameFragment, filterProps, sortProps, req);
|
||||||
|
|
||||||
return new PagingResults<Pair<PersonInfo, ClassificationLevel>>()
|
return new PagingResults<SecurityClearance>()
|
||||||
{
|
{
|
||||||
@Override public List<Pair<PersonInfo, ClassificationLevel>> getPage()
|
@Override public List<SecurityClearance> getPage()
|
||||||
{
|
{
|
||||||
List<Pair<PersonInfo, ClassificationLevel>> pcPage= new ArrayList<>(p.getPage().size());
|
List<SecurityClearance> pcPage= new ArrayList<>(p.getPage().size());
|
||||||
for (PersonInfo pi : p.getPage())
|
for (PersonInfo pi : p.getPage())
|
||||||
{
|
{
|
||||||
pcPage.add(getUserSecurityClearance(pi.getUserName()));
|
pcPage.add(getUserSecurityClearance(pi.getUserName()));
|
||||||
|
Reference in New Issue
Block a user