myblogspace sriram

Tuesday May 27, 2008

Here we'll breifly discuss abput creating roles in Glassfish-v2 and using those roles in a portlet. This portlet will be deployed on portlet container

Creating user and role in Glassfish-v2

=============================

1)Login to admin console at http://localhost:8080/portletdriver/dt

2)Goto Configuration->security->admin-realms->Manage users

3)Provide a user name and Group/role eg user name:ed group:role1 eg user name:mary group:role2

4)click save

Now we have sucessfully created an user and grouped him or given him a role.Out task now is to create a portlet that will use these roles . All portlets that make use of roles needs to supllied with a roles file. We'll now make the roles file

Create a roles.txt file with the following name value pair 

role1=EMPLOYEE role2=MANAGER

Creating a portlet .xml and web.xml that has the role informations 

Portlet.xml 

<security-role-ref>

<role-name>employee</role-name>
<role-link>EMPLOYEE</role-link>
</security-role-ref>
<security-role-ref>
<role-name>manager</role-name>
<role-link>MANAGER</role-link>
</security-role-ref>

Web.xml

<security-role>

<role-name>EMPLOYEE</role-name>
</security-role>
<security-role>
<role-name>MANAGER</role-name>
</security-role>

Create a portlet that uses the role info 

1)You can create a simple portlet through netbeans and portal pack 2)In the doView() of the portlet created paste the following

writer.prinln("Employee"+req.isUserInRole(employee)); writer.println("Manager"+req.isUserInRole(manager));

Login in as mary or ed

1)Deploy the portlet.war in portlet container along with the roles.txt

You can either use the admin tab in portlet container to specify the war file and roles files or You can use the following CLI

ant deploy-portlet -Dportlet-war= -Droles-file=

2)Now when used "ed" logs in to the OSPC(open source portlet container) he'll see the follwoing output for the portlet

Employee:true Manager:false

Comments:

Sriram , thanks for this nice blog. I am using Sun Portal Sever 7.2 and I have to implement the portlet-role mapping.
I've created the roles in Access Manager 7.1
and used a role.properties while deploying the .war file.
The portlet.xml and the web.xml is modified as suggested by you.
My intention is to hide a portlet for a user who does not belong to a role.
Whatever you suggested will that hold good for this scenario also?

Posted by Deb on September 11, 2008 at 10:27 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed