Showing posts with label oracle. Show all posts
Showing posts with label oracle. Show all posts

Friday, November 4, 2011

Custom Oracle WebCenter Portal Navigation Filter

When you work with WebCenter Portal navigation model you do not have the possibility to set the security there or to define which element which user or role for example is able to see it. You can go even farther and for example define some navigation model, which should be rendered based on ID naming convention.

To solve this issue in WebCenter you do have the possibility to develop custom navigation filter. This filter extends exactly the same interface like the custom catalog, this is the CatalogDefinitionFilter interface. This is the example code of how to do it:

import java.util.Hashtable;
 
import oracle.adf.rc.catalog.CatalogElement;
import oracle.adf.rc.spi.plugin.catalog.CatalogDefinitionFilter;
 
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
 
import oracle.adf.share.ADFContext;
import oracle.adf.share.security.SecurityContext;
 
public class NavigationFilter implements CatalogDefinitionFilter {
    public NavigationFilter() {
        super();
    }
 
    public boolean includeInCatalog(CatalogElement catalogElement,
                                    Hashtable hashtable) {
 
        //        ExternalContext ectx =
        //            FacesContext.getCurrentInstance().getExternalContext();
 
        System.out.println("----!!!---Custom navigation filter");
        System.out.println("----!!!---Custom filter value: " + catalogElement.getId());
        
        if ("home".equalsIgnoreCase(catalogElement.getId()) || "pages".equalsIgnoreCase(catalogElement.getId())) {
          System.out.println("----!!!---This is the home page");  
          return true;
        }
 
 
        if (isAuthenticated()) {
            System.out.println("User is authenticated, his name is: " +
                               getCurrentUser());
 
 
            for (String role :
                 ADFContext.getCurrent().getSecurityContext().getUserRoles()) {
 
                System.out.println("role " + role);
 
            }
 
            SecurityContext sec = ADFContext.getCurrent().getSecurityContext();
            if (sec.isUserInRole("baRole")) {
                System.out.println("--!! Yes USER is in ROLE");
                return true;
            }
        }
 
        System.out.println("----!!!--- Non of the above get out");
        return false;
    }
 
    // is the user authenticated
 
    public boolean isAuthenticated() {
        return ADFContext.getCurrent().getSecurityContext().isAuthenticated();
    }
 
    // get current user
 
    public String getCurrentUser() {
        return ADFContext.getCurrent().getSecurityContext().getUserName();
    }
}

Now this example of custom filter shows you some technics you can use inside, to choose if some navigation is able to render or not. For example using this you can approve if the user is authenticated



public boolean isAuthenticated() {
    return ADFContext.getCurrent().getSecurityContext().isAuthenticated();
}

or you can check if the user has the specific role to load this navigation model:



SecurityContext sec = ADFContext.getCurrent().getSecurityContext();
if (sec.isUserInRole("baRole")) {
    System.out.println("--!! Yes USER is in ROLE");
    return true;
}

Also inside this filter you have access to the ID’s of the elements into the navigation model:


image


 


so you can also check for example if specific ID should be rendered or not:



if ("home".equalsIgnoreCase(catalogElement.getId()) || "pages".equalsIgnoreCase(catalogElement.getId())) {
  return true;
}

Knowing this you can bind for example security with element ID’s, or you can render navigation model element depending on the context path for example.


How to use this filter? Very simple, inside your navigation model put the name of the Navigation Filter class you implemented: <namespace>.CustomNavigationFilter, like shown bellow.


image

Tuesday, August 16, 2011

Fix not enough temp space when try to install Oracle WebTier

Oracle WebTier installer requires 80MB of free temp space to be able to install the Oracle WebTier components. When you try to start the installer if you do not have enough temp space you could get a error or info message that installer check failed and you would not be able to proceed with the installation. To fix this issue you have to increase your temp space. You can do it like this:

  • change to root

su – root

  • make new folder for the temporary files

mkdir /u01/tmp

  • change the owner which you will use to install the product, in my case user is oracle and the group oinstall.

chown oracle:oinstall /u01/tmp

  • change the read-write settings

chmod 1777 /u01/tmp

  • export the new path so that the installer can use it

export TEMP=/u01/tmp

export TMPDIR=/u01/tmp

 

Now you can start the installer: ./runInstaller

Later you can remove the folder like this:

su – root

unset TEMP

unset TMPDIR

rmdir /u01/tmp

Friday, July 1, 2011

Oracle WCI Multilanguage Portlets

One of the cool things with the Oracle WCI Portal (aka BEA ALUI, Plumtree) is that it ships with the source code of the UI, which gives you the opportunity to re-write the UI. Using this you can also modify some of the basic portal functionalities like for example how the portlets are loaded. You can find the class responsible for loading the portlet in the namespace com.plumtree.portalpages.browsing.myportal and the name of the class is MyPortalContentView.

Now let’s say you do have a use case where the user is able to switch the language inside the portal and you do want to load the portlets depending on the user current language. You can localize the names of the portlet by going to the portlet properties and names and then select Support Localized Names, like shown on the screen bellow:

image

For this example I create 3 community links portlets and localized them on different languages. Now I want to change the portal code to load only the portlets which have localized name in the current user language. To do so I have to override the MyPortalContentView. Here is the code for how to do it:

1 import com.plumtree.openlog.OpenLogService;
2 import com.plumtree.openlog.OpenLogger;
3 import com.plumtree.portalpages.browsing.myportal.IMyPortalModelRO;
4 import com.plumtree.portalpages.browsing.myportal.MyPortalContentView;
5 import com.plumtree.portaluiinfrastructure.statichelpers.PTDebugHelpers;
6 import com.plumtree.server.IPTGadget;
7 import com.plumtree.server.IPTSession;
8 import com.plumtree.uiinfrastructure.activityspace.AActivitySpace;
9 import com.plumtree.uiinfrastructure.activityspace.IModel;
10 import com.plumtree.uiinfrastructure.activityspace.IModelRO;
11 import com.plumtree.xpshared.htmlelements.HTMLElementCollection;
12
13 /**
14 * Override the standard portal container view, show now only portlets localized to the current user language.
15 *
16 * @author L.Pelov
17 */
18 public class MyAppPortalContentView extends MyPortalContentView {
19
20 private static OpenLogger log = OpenLogService.GetLogger(OpenLogService
21 .GetComponent(PTDebugHelpers.COMPONENT_PORTAL_BROWSING),
22 "mydemo.portalpages.browsing.myportal.MyAppPortalContentView");
23
24 /**
25 * This function checks if portlet is localized to the current user language
26 *
27 * @param portletIndex
28 * @return true if the portlet is localized to current user language, otherwise false
29 */
30 protected boolean isPortletLocalized(int portletIndex) {
31
32 int iPortletID = m_asModel.GetPortletIDFromIndex(portletIndex);
33
34 // opens the portlet without to lock it!
35 IPTGadget portlet = (IPTGadget) ((IPTSession) m_asOwner.GetUserSession()).GetGadgets().Open(
36 iPortletID, false);
37
38 // get the current local language
39 String currLocale = m_asOwner.GetLocale();
40
41 if (currLocale.indexOf(portlet.GetPrimaryLang()) > -1) {
42 // isLocalized = true;
43 return true;
44 }
45 else {
46 boolean isLocales = portlet.GetIsLocalized();
47 if (isLocales) {
48 Object[][] arLocalNames = portlet.GetLocalizedNames();
49
50 // Get the available languages
51 if (arLocalNames != null && arLocalNames[0] != null && arLocalNames.length == 2) {
52 for (int cnt = 0; cnt < arLocalNames[0].length; cnt++) {
53 if (arLocalNames[0][cnt] != null) {
54 if (currLocale.indexOf(arLocalNames[0][cnt].toString()) > -1) {
55 // isLocalized = true;
56 // break;
57 return true;
58 }
59 }
60 }
61 }
62 }
63 }
64
65 return false;
66 }
67
68 /**
69 * @param nColumnID
70 * The ID of the column this portlet is currently in.
71 * @param nPortletIndex
72 *
73 * @return a HTMLElementCollection containing the entire portlet including the portlet header and content.
74 */
75 public HTMLElementCollection DisplaySinglePortlet(int nColumnID, int portletIndex) {
76
77 // if this portlet is not localized then just exit
78 if (!this.isPortletLocalized(portletIndex)) {
79 return new HTMLElementCollection();
80 }
81
82 return super.DisplaySinglePortlet(nColumnID, portletIndex);
83
84 }
85
86 /**
87 * Displays portlet content like the DisplaySinglePortlet function, but it is most used by the PTTAGs
88 *
89 * @param nColumnID
90 * The ID of the column this portlet is currently in.
91 * @param nPortletIndex
92 *
93 * @return a HTMLElementCollection containing the portlet body/content.
94 */
95 public HTMLElementCollection DisplaySinglePortletContent(int nColumnID, int portletIndex) {
96 // L.Pelov - make sure for later if you use Adaptive Tags that they will work in the same way
97 // if this portlet is not localized then just exit
98 if (!this.isPortletLocalized(portletIndex)) {
99 return new HTMLElementCollection();
100 }
101
102 return super.DisplaySinglePortletContent(nColumnID, portletIndex);
103 }
104
105 /** Parent Activity Space */
106 private AActivitySpace m_asOwner;
107
108 /** Read Only Model for MyPortal */
109 private IMyPortalModelRO m_asModel;
110
111 /**
112 * @see com.plumtree.uiinfrastructure.activityspace.IManagedObject#Create()
113 */
114 public Object Create() {
115 // L.Pelov - create from the subclass, not from the main one, to make sure that the original view will
116 // be replaced!
117 return new MyAppPortalContentView();
118 }
119
120 /**
121 * @see com.plumtree.xpshared.activityspace.IView#GetName()
122 */
123 public String GetName() {
124 return STR_MVC_CLASS_NAME;
125 }
126
127 /**
128 * @see com.plumtree.xpshared.activityspace.IView#Init(IModel, AActivitySpace)
129 */
130 public void Init(IModelRO model, AActivitySpace parent) {
131 log.Info("Init MyAppPortalContentView()");
132
133 m_asModel = (IMyPortalModelRO) model;
134 m_asOwner = parent;
135
136 // L.Pelov - IMPORTANT: you have to init also the main view otherwise you will get
137 // NullPointerException!
138 super.Init(model, parent);
139 }
140
141 }
142

Now several changes are made here. I add new function calls isPortletLocalized() which checks if portlet has been localized to current user language. If YES then the portlet show the portlet, if not then skip it.


Also as you can see from the code and I just override the function but after I check the if portlet should be load and call again the subclass method. This ensures that after you upgrade portal, even if it’s new functionality into the original method this code should work, except of course the Portal Server API has been change. It is of course best practices of course to test the code again when you upgrade to make sure that everything works well.


cheers