/*
* #%L
* Alfresco Repository WAR Community
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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 .
* #L%
*/
package org.alfresco.web.bean.users;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.component.UISelectOne;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.OwnableService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.IContextListener;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.bean.BrowseBean;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.dialog.FilterViewSupport;
import org.alfresco.web.bean.repository.MapNode;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.alfresco.web.ui.common.component.UIListItem;
import org.alfresco.web.ui.common.component.UIModeList;
import org.alfresco.web.ui.common.component.data.UIRichList;
import org.alfresco.web.ui.repo.WebResources;
/**
* Bean backing the Manage Space/Content Permission pages.
*
* @author Kevin Roast
*/
public abstract class UserMembersBean extends BaseDialogBean implements IContextListener, FilterViewSupport
{
private static final String MSG_SUCCESS_INHERIT_NOT = "success_not_inherit_permissions";
private static final String MSG_SUCCESS_INHERIT = "success_inherit_permissions";
private static final String ERROR_DELETE = "error_remove_user";
private static final String OUTCOME_FINISH = "finish";
private static final String LOCAL = "local";
private static final String INHERITED = "inherited";
private final static String MSG_CLOSE = "close";
private String filterMode = LOCAL;
/** NodeService bean reference */
transient private NodeService nodeService;
/** SearchService bean reference */
transient private SearchService searchService;
/** PermissionService bean reference */
transient private PermissionService permissionService;
/** AuthorityService bean reference */
transient private AuthorityService authorityService;
/** PersonService bean reference */
transient private PersonService personService;
/** BrowseBean bean refernce */
protected BrowseBean browseBean;
/** OwnableService bean reference */
transient private OwnableService ownableService;
/** Component reference for Users RichList control */
private UIRichList usersRichList;
/** action context */
private String personAuthority = null;
/** action context */
private String personName = null;
/** datamodel for table of roles for current person */
private transient DataModel personRolesDataModel = null;
/** roles for current person */
private List personRoles = null;
/**
* Default constructor
*/
public UserMembersBean()
{
UIContextService.getInstance(FacesContext.getCurrentInstance()).registerBean(this);
}
// ------------------------------------------------------------------------------
// Abstract methods
/**
* Returns the node that is being acted upon
*
* @return The node to manage permissions for
*/
public abstract Node getNode();
// ------------------------------------------------------------------------------
// Bean property getters and setters
/**
* @param nodeService The NodeService to set.
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
protected NodeService getNodeService()
{
if (nodeService == null)
{
nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
}
return nodeService;
}
/**
* @param searchService The search service
*/
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
protected SearchService getSearchService()
{
if (searchService == null)
{
searchService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getSearchService();
}
return searchService;
}
/**
* @param permissionService The PermissionService to set.
*/
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
protected PermissionService getPermissionService()
{
if (permissionService == null)
{
permissionService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getPermissionService();
}
return permissionService;
}
/**
* @param authorityService The AuthorityService to set.
*/
public void setAuthorityService(AuthorityService authorityService)
{
this.authorityService = authorityService;
}
protected AuthorityService getAuthorityService()
{
if (authorityService == null)
{
authorityService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getAuthorityService();
}
return authorityService;
}
/**
* @param ownableService The ownableService to set.
*/
public void setOwnableService(OwnableService ownableService)
{
this.ownableService = ownableService;
}
protected OwnableService getOwnableService()
{
if (ownableService == null)
{
ownableService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getOwnableService();
}
return ownableService;
}
/**
* @param personService The personService to set.
*/
public void setPersonService(PersonService personService)
{
this.personService = personService;
}
protected PersonService getPersonService()
{
if (personService == null)
{
personService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getPersonService();
}
return personService;
}
/**
* @param browseBean The BrowseBean to set.
*/
public void setBrowseBean(BrowseBean browseBean)
{
this.browseBean = browseBean;
}
/**
* @return Returns the usersRichList.
*/
public UIRichList getUsersRichList()
{
return this.usersRichList;
}
/**
* @param usersRichList The usersRichList to set.
*/
public void setUsersRichList(UIRichList usersRichList)
{
this.usersRichList = usersRichList;
}
/**
* Returns the properties for current Person roles JSF DataModel
*
* @return JSF DataModel representing the current Person roles
*/
public DataModel getPersonRolesDataModel()
{
if (this.personRolesDataModel == null)
{
this.personRolesDataModel = new ListDataModel();
}
if (this.personRolesDataModel.getWrappedData() == null)
{
this.personRolesDataModel.setWrappedData(this.personRoles);
}
return this.personRolesDataModel;
}
/**
* @return Returns the current person authority.
*/
public String getPersonAuthority()
{
return this.personAuthority;
}
/**
* @param person The person person authority to set.
*/
public void setPersonAuthority(String person)
{
this.personAuthority = person;
}
/**
* @return Returns the personName.
*/
public String getPersonName()
{
return this.personName;
}
/**
* @param personName The personName to set.
*/
public void setPersonName(String personName)
{
this.personName = personName;
}
/**
* @return true if the current user can change permissions on this Space
*/
public boolean getHasChangePermissions()
{
return getNode().hasPermission(PermissionService.CHANGE_PERMISSIONS);
}
/**
* @return Returns the inherit parent permissions flag set for the current space.
*/
public boolean isInheritPermissions()
{
return this.getPermissionService().getInheritParentPermissions(getNode().getNodeRef());
}
/**
* @param inheritPermissions The inheritPermissions to set.
*/
public void setInheritPermissions(boolean inheritPermissions)
{
// stub - no impl as changes are made immediately using a ValueChanged listener
}
/**
* Return the owner username
*/
public String getOwner()
{
return this.getOwnableService().getOwner(getNode().getNodeRef());
}
/**
* @return the list of user nodes for list data binding
*/
public List