Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "/Stardust/KnowledgeBase/Customization/Portal/Role Based Stardust UI Customization Using Spring Bean Post-processor"

m
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Introduction ==
+
#REDIRECT [[Stardust/Knowledge Base/Customization/Portal/Role Based Stardust UI Customization Using Spring Bean Post-processor]]
In this article, we will see how you can customize access permission to the Stardust Portal UI components using spring bean post processor approach.
+
 
+
In the portal, perspectives, launch panels, and views are implemented and controlled by spring backing beans. The spring backing beans take care of UI component visibility (like launch panel links) and role based access permissions.
+
 
+
If you need to change the default UI access policy, you can use spring bean post processor and change access
+
*permissions by changing UI component backing beans as per your need. For example, you can change the things like:
+
*Make the ‘my documents’ launch panel not to be accessible to X role;
+
 
+
Restrict the process details view to be visible for Role Y and so on
+
Now let us see all this in action with illustrative example;
+
 
+
 
+
== Spring Bean Post-processor ==
+
As you know once we create a class implementing spring’s BeanPostProcessor and defines it as a bean in spring context file. The post process has two call back methods, one before bean initialization and second after bean initialization.
+
 
+
The spring framework will invoke your post processor for every bean in the given spring context during context initialization.
+
 
+
In this case, we will use the bean post processors after initialization method to access initialized Stardust Portal UI beans and change default access permissions as per our needs.
+
 
+
The following section shows how to customize UI access with few select use cases and code snippets.
+
 
+
 
+
== Customizing Perspective Access Permissions ==
+
By default, Business Control Center perspective is available all roles. But you want to change this and hide BCC perspective to a role, say “RoleX”.  This can be achieved using bean post process as shown in the follow code snippets;
+
 
+
<source lang="Java">
+
package com.test;
+
 
+
import org.springframework.beans.BeansException;
+
import org.springframework.beans.factory.config.BeanPostProcessor;
+
 
+
import com.infinity.bpm.portal.common.PerspectiveDefinition;
+
import com.infinity.bpm.portal.common.PerspectiveExtension;
+
 
+
public class PortalUIPostProcessor implements BeanPostProcessor{
+
 
+
@Override
+
public Object postProcessAfterInitialization(Object bean, String beanId)
+
throws BeansException {
+
+
if (bean instanceof PerspectiveExtension
+
&& beanId.equals("ippBccPerspective")) {
+
PerspectiveDefinition bccPerspective = (PerspectiveDefinition) bean;
+
bccPerspective.setExcludeRoles("RoleX");
+
}
+
return bean;
+
}
+
 
+
@Override
+
public Object postProcessBeforeInitialization(Object bean, String arg1)
+
throws BeansException {
+
// TODO Auto-generated method stub
+
return bean;
+
}
+
}
+
 
+
</source>
+
 
+
 
+
== Restricting Select Common Views ==
+
There are common views, meaning available from multiple perspective of the Stardust portal. Thus they are shared. Common views example are document view, document search view, and process instance details view.
+
+
Now, consider that we want to restrict the document and document search views to “RoleX”. The code snippets below show how.
+
 
+
<source lang="Java">
+
package com.test;
+
 
+
import java.util.List;
+
 
+
import org.springframework.beans.BeansException;
+
import org.springframework.beans.factory.config.BeanPostProcessor;
+
 
+
import com.infinity.bpm.portal.common.PerspectiveExtension;
+
import com.infinity.bpm.portal.common.ViewDefinition;
+
import com.infinity.bpm.portal.common.ViewsExtension;
+
 
+
public class PortalUIPostProcessor implements BeanPostProcessor {
+
 
+
@Override
+
public Object postProcessAfterInitialization(Object bean, String beanId)
+
throws BeansException {
+
 
+
if (bean instanceof PerspectiveExtension
+
&& beanId.equals("ippViewsCommonPerspective")) {
+
List<ViewsExtension> viewsExtensions = ((PerspectiveExtension) bean)
+
.getViewsExtensions();
+
for (ViewsExtension viewExtn : viewsExtensions) {
+
List<ViewDefinition> views = viewExtn.getElements();
+
for (ViewDefinition view : views) {
+
if (view.getName().equals("documentView")
+
                                          || view.getName().equals("documentSearchView")) {
+
//Here, documentView and documentSearchView are view names.
+
                                                //You must know the Stardust Portal
+
//view names.
+
view.setExcludeRoles(view.getExcludeRoles() + ",RoleX");
+
// setExcludeRoles takes comma separated list of roles
+
}
+
}
+
}
+
}
+
return bean;
+
}
+
 
+
@Override
+
public Object postProcessBeforeInitialization(Object bean, String arg1)
+
throws BeansException {
+
// TODO Auto-generated method stub
+
return bean;
+
}
+
}
+
</source>
+
 
+
'''Note that links to these views remain active in the portal. But when you click on them, you get a custom message saying, you do not have access to the given view, and the use is restricted to the view.'''
+
 
+
 
+
== Restricting Perspective Launch Panel Access ==
+
Now, we will see how to restrict access to launch panels for the given perspective. Consider that we want to restrict '''RoleX''' users from accessing management views launch panel of the BCC perspective. Here is the code snippet that does it.
+
<source lang="Java">
+
package com.test;
+
 
+
import java.util.Iterator;
+
 
+
import org.springframework.beans.BeansException;
+
import org.springframework.beans.factory.config.BeanPostProcessor;
+
 
+
import com.infinity.bpm.portal.common.LaunchPanel;
+
import com.infinity.bpm.portal.common.PerspectiveDefinition;
+
 
+
public class PortalUIPostProcessor implements BeanPostProcessor {
+
 
+
@Override
+
public Object postProcessAfterInitialization(Object bean, String beanId)
+
throws BeansException {
+
 
+
if (bean instanceof PerspectiveDefinition) {
+
PerspectiveDefinition perspectiveBean = (PerspectiveDefinition) bean;
+
for (Iterator<LaunchPanel> _iterator = perspectiveBean
+
.getLaunchPanels().iterator(); _iterator.hasNext();) {
+
LaunchPanel launchPanel = _iterator.next();
+
if(launchPanel.getName().equals("managementViews"))
+
launchPanel.setExcludeRoles(launchPanel.getExcludeRoles()
+
+ ",RoleX");
+
}
+
}
+
return bean;
+
}
+
 
+
@Override
+
public Object postProcessBeforeInitialization(Object bean, String arg1)
+
throws BeansException {
+
// TODO Auto-generated method stub
+
return bean;
+
}
+
}
+
 
+
</source>
+

Latest revision as of 20:23, 10 March 2014

Back to the top