Version 5

    A user is defined in the database by a table JBP_USERS(JBP_UID,JBP_UNAME,...) to contain the user profile. When using a table the constraint is that the set of the attributes is fixed. In order to circumvent that there is a second table JBP_USER_PROP(JBP_UID,JBP_NAME,JBP_VALUE) that contains additional properties for a given user.

     

    Example

     

    For instance if we have in the tables

     

    JBP_USERS:

    (3,admin,admin@portal.com,...)

     

    JBP_USER_PROP:

    (3,portal.user.locale,fr)

    (3,portal.user.signature,Signature of admin)

     

    Then the set of attributes for this user seen from a portlet point of view is :

     

    • user.name.nickName : admin

    • user.business-info.online.email : admin@portal.com

    • portal.user.locale : fr

    • portal.user.signature : Signature of admin

     

    In the portlet

     

    Among all the fields of the JBP_USERS, 4 are mapped to portlet user attributes :

     

    • user.name.nickName on the field userName

    • user.business-info.online.email on the field realEmail

    • user.name.given on the field givenName

    • user.name.family on the field familyName

     

    For the JBP_USER_PROP table, every entry in this table is available in the portlet.

     

    The condition to have this possible, of course, is to declare their properties in the portlet.xml file :

     

    <portlet-app>
       ...
       <user-attribute>
          <name>user.name.nickName</name>
       </user-attribute>
       <user-attribute>
          <name>user.business-info.online.email</name>
       </user-attribute>
       <user-attribute>
          <name>user.name.given</name>
       </user-attribute>
       <user-attribute>
          <name>user.name.family</name>
       </user-attribute>
       <user-attribute>
          <name>portal.user.locale</name>
       </user-attribute>
       <user-attribute>
          <name>portal.user.signature</name>
       </user-attribute>
       <user-attribute>
          <name>portal.user.last-login-date</name>
       </user-attribute>
       ...
    </portlet-app>

     

    How can I modify the values ?

     

    The map you get in the portlet is not mutable. If you want to modify the values then you need to use a specific API that gives you access to the user database. This service is called UserModule.

     

    It is possible to inject this service in the portlet context of the war file, in jboss-portlet.xml :

     

    <portlet-app>
       ...
       <portlet>
          <portlet-name>MyPortlet</portlet-name>
          <transaction>
             <trans-attribute>Required</trans-attribute>
          </transaction>
       </portlet>
       ...
       <service>
          <service-name>UserModule</service-name>
          <service-class>org.jboss.portal.core.modules.UserModule</service-class>
          <service-ref>:service=Module,type=User</service-ref>
       </service>
       ...
    </portlet-app>

     

    Also in that example we ask the portal to propagate the portal transaction to our portlet in order to be able to modify data in the scope of the same request.

     

    Then in your portlet it is possible to user it like that :

     

    // Get the current user
    UserModule module = (UserModule)getPortletContext().getAttribute("UserModule");
    String userName = req.getRemoteUser();
    if (userName != null}
    {
       User user = module.findUserByUserName(userName);
       PropertyMap pmap = user.getProperties();
       pmap.put("user.business-info.online.email", "julien@jboss.com");
    }
    

     

    For more details, the UserPortlet is a good example.