Mitkees & Webcenter

Into the charm of Oracle Webcenter and ADF

Monthly Archives: April 2012

Adding the new custom attribute to Webcenter spaces User Profile?:-


First add new custom attribute to LDAP:-

1         Click Run from Start menu and type ‘mmc’.

2         Click Fileà Add à Add to Active Directory Schema

3         Right Click on Attributes à New à Attribute.

4         Then add this attribute to the “User” Class under Classes.

5         Now, you can see the new attribute in the ADSI for each user object.

Image

  • We can do that by the “Custom Oracle Webcenter Spaces Application – Profile Attributes Project”.
  • There are two java classes under this project:-
  1. CustomProfileImpl.java: This class is used to override the value of an existing attribute or make it come from other data source: To override the existed attribute just add the code to this class as per the following

–          We can use JSFUtils.java class to make personalized view for each user (each user can see his image from a specific data source).

  1. The Second Class (ExtendedProfileAttributes.java): This class is used to add a new custom attribute to user profile

–          First, We add a new attribute to the class and generate its assessors (getter and setter)

–          Then Add your code in the getter Property to get the value of the attribute in the read-only mode (while you are viewing your profile as a spaces user) and add your code in the Setter Property to set the value the user enters in the edit mode of the task flow to a specific data source (Active Directory).

–          Add JSFUtils.java to the ProfileAttributes project in the same package as ExtendProfileAttributes.java class (custom.webcenter.spaces) to be able to get or set values to expression language used by webcenter.

–          Add  . properties file to the ProfileAttributes project and add the values of the data source you are connecting to as per the following example:-

#This File contain the LDAP Configurations

INITIAL_CONTEXT_FACTORY = com.sun.jndi.ldap.LdapCtxFactory

SECURITY_AUTHENTICATION = simple

SECURITY_PRINCIPAL= cn=orcladmin

# SECURITY_PRINCIPAL= BPEL_TEST@sfdproject.com

SECURITY_CREDENTIALS = welcome1

PROVIDER_URL = ldap://myldap:port

TokenGroups = java.naming.ldap.attributes.binary

UserBase = dc=sfdproject, dc=com

username = sAMAccountName

testAttribute= testAttribute

–          In the getter property (which will be called in the view mode) write the following code:-

try {

String spaceUser =(String)JSFUtils.resolveExpression("#{securityContext.userName}");

System.out.println("This is the Extend constructor: "+spaceUser);

if(spaceUser !=null && spaceUser != "" && !spaceUser.toLowerCase().equals("anonymous"))
{connectLDAP(spaceUser);}

}

catch (Exception e) {

e.printStackTrace();

}

public void connectLDAP(String name) throws NamingException {

bundle = ResourceBundle.getBundle(Path of your property file in the ProfileAttributes project);

Hashtable<String, String> env = new Hashtable<String, String>();

env.put(Context.INITIAL_CONTEXT_FACTORY,

bundle.getString("INITIAL_CONTEXT_FACTORY"));

env.put(Context.PROVIDER_URL, bundle.getString("PROVIDER_URL"));

env.put(Context.SECURITY_PRINCIPAL,
bundle.getString("SECURITY_PRINCIPAL"));

env.put(Context.SECURITY_CREDENTIALS,

bundle.getString("SECURITY_CREDENTIALS"));

LdapContext ctx = (LdapContext)new InitialLdapContext(env, null);

DirContext dtx = (DirContext)ctx.lookup(bundle.getString("UserBase")); // UserBase is a key in the property file

SearchControls ctls = new SearchControls();

ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

String filter = "(sAMAccountName=" + name + ")";

NamingEnumeration e = dtx.search("", filter, ctls);

if (e.hasMore()) {
SearchResult entry = (SearchResult)e.next();

answer = entry.getAttributes();

//ctx.getAttributes("cn=" + name + "," + bundle.getString("UserBase")); //ou=OrgUnit1,

System.out.println("answer.get(\"manager\"): " + answer.get("manager"));

this.testAttribute = answer.get("testAttribute").toString();

ctx.close();

}

}

–          In the setter property (which will be called in the edit mode) write the following code:-

try {

String spaceUser = (String)JSFUtils.resolveExpression("#{securityContext.userName}");
System.out.println("This is the Extend constructor: "+spaceUser);

if(spaceUser !=null &&; spaceUser != "" && !spaceUser.toLowerCase().equals("anonymous") )

{

System.out.println("The new value entered by user: "+ testAttribute);

connectLDAP1(spaceUser,testAttribute);

}

}

catch(Exception e) {

e.printStackTrace();

}

public void connectLDAP1(String name,String newValue) throws NamingException {

bundle = ResourceBundle.getBundle("invokeprops//LDAP");

System.out.println("The new value entered by user: "+ newValue);

Hashtable<String, String> env = new Hashtable<String, String>();

env.put(Context.INITIAL_CONTEXT_FACTORY,

bundle.getString("INITIAL_CONTEXT_FACTORY"));

env.put(Context.PROVIDER_URL, bundle.getString("PROVIDER_URL"));

env.put(Context.SECURITY_PRINCIPAL,bundle.getString("SECURITY_PRINCIPAL"));

env.put(Context.SECURITY_CREDENTIALS,

bundle.getString("SECURITY_CREDENTIALS"));

LdapContext ctx = (LdapContext)new InitialLdapContext(env, null);

DirContext dtx = (DirContext)ctx.lookup(bundle.getString("UserBase"));

SearchControls ctls = new SearchControls();

ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

String filter = "(sAMAccountName=" + name + ")";

NamingEnumeration e = dtx.search("", filter, ctls);

if (e.hasMore()) {

SearchResult entry = (SearchResult)e.next();

answer = entry.getAttributes();

//ctx.getAttributes("cn=" + name + "," + bundle.getString("UserBase")); //ou=OrgUnit1,

System.out.println("answer.get(\"manager\"): " + answer.get("manager"));

//  answer.put("testAttribute", newValue);

ModificationItem[] mods = new ModificationItem[1];

mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,

new BasicAttribute("testAttribute", newValue));

dtx.modifyAttributes("cn=legalm,cn=users", mods);

ctx.close();

}

}
  • Then, deploy WebcenterSpacesSharedLibExtension project using the Ant Apache after adding the jar of the ProfileAttributes Project to the War of the WebcenterSpacesSharedLibExtension project as per the next image

Image

  • Then, Log in to the spaces with administrator user and navigate to the Resources of the group space you need to add the new attribute to, then choose the resource catalog you need and AddàNew Component and write this code down (in this example the added attribute called testAttribute).

Image<af:panelLabelAndMessage xmlns:af=”http://xmlns.oracle.com/adf/faces/rich&#8221; label=”Project ” labelStyle=”font-weight:bold;” id=”#”><af:inputText value=”#{wcProfileCustomAttribute[(pageFlowScope.userId == null ? securityContext.userName : pageFlowScope.userId)].testAttribute}” simple=”true” columns=”40″ maximumLength=”50″ shortDesc=”Enter project details” id=”#”/></af:panelLabelAndMessage>

Image
  • We may need to add two components (one for read only mode with <af:outputText> and the other for the edit mode as per the above code).
  • Navigate to the User Profile page (My Profile) from the system pages of the personal space
  • In the About tab you have many task flow, you choose the task flow you need and add your component to it (you must view the source to add your component to a specified task flow) Image
  • Click on the task flow you need to add your component to and a message displayed says that all instances of the task flow will be affected (click Edit)    Image
  • After Clicking on edit, the source of the task flow appeared , choose the place you need to add the component to and click on Add content   Image
  • Choose your component and click Save and Close.

ENJOY THE MAGIC

Advertisements
%d bloggers like this: