use of org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method savePortletDefinition.
/**
* Save a portlet definition.
*
* @param definition the portlet definition
* @param publisher the person publishing the portlet
* @param categories the list of categories for the portlet
* @param permissionMap a map of permission name -> list of groups who are granted that
* permission (Note: for now, only grant is supported and only for the FRAMEWORK_OWNER perm
* manager)
*/
private IPortletDefinition savePortletDefinition(IPortletDefinition definition, IPerson publisher, List<PortletCategory> categories, Map<ExternalPermissionDefinition, Set<IGroupMember>> permissionMap) {
boolean newChannel = (definition.getPortletDefinitionId() == null);
// save the channel
definition = portletDefinitionDao.savePortletDefinition(definition);
definition = portletDefinitionDao.getPortletDefinitionByFname(definition.getFName());
final String defId = definition.getPortletDefinitionId().getStringId();
final IEntity portletDefEntity = GroupService.getEntity(defId, IPortletDefinition.class);
//The groups service needs to deal with concurrent modification better.
synchronized (this.groupUpdateLock) {
// Delete existing category memberships for this channel
if (!newChannel) {
for (IEntityGroup group : portletDefEntity.getAncestorGroups()) {
group.removeChild(portletDefEntity);
group.update();
}
}
// For each category ID, add channel to category
for (PortletCategory category : categories) {
final IEntityGroup categoryGroup = GroupService.findGroup(category.getId());
categoryGroup.addChild(portletDefEntity);
categoryGroup.updateMembers();
}
// Set groups
final AuthorizationService authService = AuthorizationService.instance();
final String target = PermissionHelper.permissionTargetIdForPortletDefinition(definition);
// Loop over the affected permission managers...
Map<String, Collection<ExternalPermissionDefinition>> permissionsBySystem = getPermissionsBySystem(permissionMap.keySet());
for (String system : permissionsBySystem.keySet()) {
Collection<ExternalPermissionDefinition> systemPerms = permissionsBySystem.get(system);
// get the permission manager for this system...
final IUpdatingPermissionManager upm = authService.newUpdatingPermissionManager(system);
final List<IPermission> permissions = new ArrayList<>();
// add activity grants for each permission..
for (ExternalPermissionDefinition permissionDef : systemPerms) {
Set<IGroupMember> members = permissionMap.get(permissionDef);
for (final IGroupMember member : members) {
final IAuthorizationPrincipal authPrincipal = authService.newPrincipal(member);
final IPermission permEntity = upm.newPermission(authPrincipal);
permEntity.setType(IPermission.PERMISSION_TYPE_GRANT);
permEntity.setActivity(permissionDef.getActivity());
permEntity.setTarget(target);
permissions.add(permEntity);
}
}
// If modifying the channel, remove the existing permissions before adding the new ones
if (!newChannel) {
for (ExternalPermissionDefinition permissionName : permissionMap.keySet()) {
IPermission[] oldPermissions = upm.getPermissions(permissionName.getActivity(), target);
upm.removePermissions(oldPermissions);
}
}
upm.addPermissions(permissions.toArray(new IPermission[permissions.size()]));
}
}
if (logger.isDebugEnabled()) {
logger.debug("Portlet " + defId + " has been " + (newChannel ? "published" : "modified") + ".");
}
return definition;
}
use of org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method convert.
protected ExternalPortletDefinition convert(IPortletDefinition def) {
ExternalPortletDefinition rep = new ExternalPortletDefinition();
rep.setFname(def.getFName());
rep.setDesc(def.getDescription());
rep.setName(def.getName());
rep.setTimeout(BigInteger.valueOf(def.getTimeout()));
rep.setActionTimeout(convertToBigInteger(def.getActionTimeout()));
rep.setEventTimeout(convertToBigInteger(def.getEventTimeout()));
rep.setRenderTimeout(convertToBigInteger(def.getRenderTimeout()));
rep.setResourceTimeout(convertToBigInteger(def.getResourceTimeout()));
rep.setTitle(def.getTitle());
rep.setType(def.getType().getName());
if (def.getLifecycleState().isEqualToOrAfter(PortletLifecycleState.APPROVED)) {
Lifecycle lifecycle = new Lifecycle();
LifecycleEntry approved = new LifecycleEntry();
approved.setUser(getUsernameForUserId(def.getApproverId()));
approved.setValue(getCalendar(def.getApprovalDate()));
lifecycle.setApproved(approved);
if (def.getLifecycleState().isEqualToOrAfter(PortletLifecycleState.PUBLISHED)) {
LifecycleEntry published = new LifecycleEntry();
published.setUser(getUsernameForUserId(def.getPublisherId()));
published.setValue(getCalendar(def.getPublishDate()));
lifecycle.setPublished(published);
}
/* An EXPIRED record in the lifecycle history requires two things:
* - Current lifecycle state >= EXPIRED
* - An expiration date
*/
if (def.getLifecycleState().isEqualToOrAfter(PortletLifecycleState.EXPIRED) && def.getExpirationDate() != null) {
LifecycleEntry expired = new LifecycleEntry();
expired.setUser(getUsernameForUserId(def.getExpirerId()));
expired.setValue(getCalendar(def.getExpirationDate()));
lifecycle.setExpiration(expired);
}
// Maintenance mode is handled via a portlet publishing parameter and not a lifecycle
rep.setLifecycle(lifecycle);
}
final org.apereo.portal.xml.PortletDescriptor portletDescriptor = new org.apereo.portal.xml.PortletDescriptor();
final IPortletDescriptorKey portletDescriptorKey = def.getPortletDescriptorKey();
if (portletDescriptorKey.isFrameworkPortlet()) {
portletDescriptor.setIsFramework(true);
} else {
portletDescriptor.setWebAppName(portletDescriptorKey.getWebAppName());
}
portletDescriptor.setPortletName(portletDescriptorKey.getPortletName());
rep.setPortletDescriptor(portletDescriptor);
final List<ExternalPortletParameter> parameterList = rep.getParameters();
for (IPortletDefinitionParameter param : def.getParameters()) {
final ExternalPortletParameter externalPortletParameter = new ExternalPortletParameter();
externalPortletParameter.setName(param.getName());
externalPortletParameter.setDescription(param.getDescription());
externalPortletParameter.setValue(param.getValue());
parameterList.add(externalPortletParameter);
}
Collections.sort(parameterList, ExternalPortletParameterNameComparator.INSTANCE);
final List<ExternalPortletPreference> portletPreferenceList = rep.getPortletPreferences();
for (IPortletPreference pref : def.getPortletPreferences()) {
final ExternalPortletPreference externalPortletPreference = new ExternalPortletPreference();
externalPortletPreference.setName(pref.getName());
externalPortletPreference.setReadOnly(pref.isReadOnly());
final List<String> value = externalPortletPreference.getValues();
value.addAll(Arrays.asList(pref.getValues()));
//no sorting of preference values, order is specified by the portlet
portletPreferenceList.add(externalPortletPreference);
}
Collections.sort(portletPreferenceList, ExternalPortletPreferenceNameComparator.INSTANCE);
final List<String> categoryList = rep.getCategories();
final IGroupMember gm = GroupService.getGroupMember(def.getPortletDefinitionId().getStringId(), IPortletDefinition.class);
@SuppressWarnings("unchecked") final Iterator<IEntityGroup> categories = GroupService.getCompositeGroupService().findParentGroups(gm);
while (categories.hasNext()) {
IEntityGroup category = categories.next();
categoryList.add(category.getName());
}
Collections.sort(categoryList);
// handle the SUBSCRIBER_ACTIVITY perm separately...
final List<String> groupList = rep.getGroups();
final List<String> userList = rep.getUsers();
exportPermission(def, ExternalPermissionDefinition.SUBSCRIBE, groupList, userList);
// handle other supported perms (currently just BROWSE)
ExternalPermissions externalPermissions = new ExternalPermissions();
for (ExternalPermissionDefinition perm : ExternalPermissionDefinition.values()) {
if (!perm.getExportForPortletDef()) {
continue;
}
ExternalPermissionMemberList members = new ExternalPermissionMemberList();
members.setSystem(perm.getSystem());
members.setActivity(perm.getActivity());
List<String> groups = members.getGroups();
boolean found = exportPermission(def, perm, groups, null);
if (found) {
externalPermissions.getPermissions().add(members);
}
}
if (!externalPermissions.getPermissions().isEmpty()) {
rep.setPermissions(externalPermissions);
}
return rep;
}
use of org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method toExternalPermissionDefinition.
/**
* Check that a permission type from the XML file matches with a real permission.
*
* @param system The name of the permission manager
* @param activity The name of the permission to search for.
* @return the permission type string to use
* @throws IllegalArgumentException if an unsupported permission type is specified
*/
private ExternalPermissionDefinition toExternalPermissionDefinition(String system, String activity) {
ExternalPermissionDefinition def = ExternalPermissionDefinition.find(system, activity);
if (def != null) {
return def;
}
String delim = "";
StringBuilder buffer = new StringBuilder();
for (ExternalPermissionDefinition perm : ExternalPermissionDefinition.values()) {
buffer.append(delim);
buffer.append(perm.toString());
delim = ", ";
}
throw new IllegalArgumentException("Permission type " + system + "." + activity + " is not supported. " + "The only supported permissions at this time are: " + buffer.toString());
}
use of org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method importData.
@Transactional
@Override
public void importData(ExternalPortletDefinition portletRep) {
final PortletDescriptor portletDescriptor = portletRep.getPortletDescriptor();
final Boolean isFramework = portletDescriptor.isIsFramework();
if (isFramework != null && isFramework && "UPGRADED_CHANNEL_IS_NOT_A_PORTLET".equals(portletDescriptor.getPortletName())) {
if (errorOnChannel) {
throw new IllegalArgumentException(portletRep.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and cannot be imported.");
}
logger.warn(portletRep.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and will not be imported.");
return;
}
// get the portlet type
final IPortletType portletType = portletTypeRegistry.getPortletType(portletRep.getType());
if (portletType == null) {
throw new IllegalArgumentException("No portlet type registered for: " + portletRep.getType());
}
final List<PortletCategory> categories = new ArrayList<PortletCategory>();
for (String categoryName : portletRep.getCategories()) {
EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.IS, IPortletDefinition.class);
PortletCategory category = null;
if (cats != null && cats.length > 0) {
category = portletCategoryRegistry.getPortletCategory(cats[0].getKey());
} else {
category = portletCategoryRegistry.getPortletCategory(categoryName);
}
if (category == null) {
throw new IllegalArgumentException("No category '" + categoryName + "' found when importing portlet: " + portletRep.getFname());
}
categories.add(category);
}
final String fname = portletRep.getFname();
final Map<ExternalPermissionDefinition, Set<IGroupMember>> permissions = new HashMap<>();
final Set<IGroupMember> subscribeMembers = toGroupMembers(portletRep.getGroups(), fname);
permissions.put(ExternalPermissionDefinition.SUBSCRIBE, subscribeMembers);
if (portletRep.getPermissions() != null && portletRep.getPermissions().getPermissions() != null) {
for (ExternalPermissionMemberList perm : portletRep.getPermissions().getPermissions()) {
Set<IGroupMember> members = toGroupMembers(perm.getGroups(), fname);
ExternalPermissionDefinition permDef = toExternalPermissionDefinition(perm.getSystem(), perm.getActivity());
if (permissions.containsKey(permDef)) {
permissions.get(permDef).addAll(members);
} else {
permissions.put(permDef, members);
}
}
}
IPortletDefinition def = portletDefinitionDao.getPortletDefinitionByFname(fname);
if (def == null) {
def = new PortletDefinitionImpl(portletType, fname, portletRep.getName(), portletRep.getTitle(), portletDescriptor.getWebAppName(), portletDescriptor.getPortletName(), isFramework != null ? isFramework : false);
} else {
final IPortletDescriptorKey portletDescriptorKey = def.getPortletDescriptorKey();
portletDescriptorKey.setPortletName(portletDescriptor.getPortletName());
if (isFramework != null && isFramework) {
portletDescriptorKey.setFrameworkPortlet(true);
portletDescriptorKey.setWebAppName(null);
} else {
portletDescriptorKey.setFrameworkPortlet(false);
portletDescriptorKey.setWebAppName(portletDescriptor.getWebAppName());
}
def.setName(portletRep.getName());
def.setTitle(portletRep.getTitle());
def.setType(portletType);
}
def.setDescription(portletRep.getDesc());
final BigInteger timeout = portletRep.getTimeout();
if (timeout != null) {
def.setTimeout(timeout.intValue());
}
final BigInteger actionTimeout = portletRep.getActionTimeout();
if (actionTimeout != null) {
def.setActionTimeout(actionTimeout.intValue());
}
final BigInteger eventTimeout = portletRep.getEventTimeout();
if (eventTimeout != null) {
def.setEventTimeout(eventTimeout.intValue());
}
final BigInteger renderTimeout = portletRep.getRenderTimeout();
if (renderTimeout != null) {
def.setRenderTimeout(renderTimeout.intValue());
}
final BigInteger resourceTimeout = portletRep.getResourceTimeout();
if (resourceTimeout != null) {
def.setResourceTimeout(resourceTimeout.intValue());
}
handleLifecycleApproval(def, portletRep.getLifecycle());
handleLifecyclePublished(def, portletRep.getLifecycle());
handleLifecycleExpired(def, portletRep.getLifecycle());
final Set<IPortletDefinitionParameter> parameters = new LinkedHashSet<IPortletDefinitionParameter>();
for (ExternalPortletParameter param : portletRep.getParameters()) {
parameters.add(new PortletDefinitionParameterImpl(param.getName(), param.getValue()));
}
def.setParameters(parameters);
final ArrayList<IPortletPreference> preferenceList = new ArrayList<IPortletPreference>();
for (ExternalPortletPreference pref : portletRep.getPortletPreferences()) {
final List<String> valueList = pref.getValues();
final String[] values = valueList.toArray(new String[valueList.size()]);
final Boolean readOnly = pref.isReadOnly();
preferenceList.add(new PortletPreferenceImpl(pref.getName(), readOnly != null ? readOnly : false, values));
}
def.setPortletPreferences(preferenceList);
savePortletDefinition(def, systemUser, categories, permissions);
}
use of org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method savePortletDefinition.
/*
* (non-Javadoc)
* @see org.apereo.portal.channel.IChannelPublishingService#saveChannelDefinition(org.apereo.portal.portlet.om.IPortletDefinition, org.apereo.portal.security.IPerson, org.apereo.portal.channel.ChannelLifecycleState, java.util.Date, java.util.Date, org.apereo.portal.ChannelCategory[], org.apereo.portal.groups.IGroupMember[])
*/
@Override
public IPortletDefinition savePortletDefinition(IPortletDefinition definition, IPerson publisher, List<PortletCategory> categories, List<IGroupMember> groupMembers) {
Map<ExternalPermissionDefinition, Set<IGroupMember>> permissions = new HashMap<>();
permissions.put(ExternalPermissionDefinition.SUBSCRIBE, new HashSet<>(groupMembers));
IPortletDefinition def = savePortletDefinition(definition, publisher, categories, permissions);
return def;
}
Aggregations