Difference between revisions of "Using credentials in Portlets and Servlets"

From Gcube Wiki
Jump to: navigation, search
(Imports)
(Sample Code)
Line 35: Line 35:
 
#'''''UserInfo''''' class, which is defined in package '''''org.diligentproject.dvos.portal''''', is a [http://en.wikipedia.org/wiki/Singleton_pattern singleton]. So, if you want to retrieve the instance of this class, you must call the '''''getInstance()''''' method.
 
#'''''UserInfo''''' class, which is defined in package '''''org.diligentproject.dvos.portal''''', is a [http://en.wikipedia.org/wiki/Singleton_pattern singleton]. So, if you want to retrieve the instance of this class, you must call the '''''getInstance()''''' method.
 
===Sample Code===
 
===Sample Code===
<pre><nowiki>//Retrieving UserInfo instance:
+
<code border='1'><span style="color:green">//Retrieving UserInfo instance:</span><br>
UserInfo userInfo = UserInfo.getInstance();
+
UserInfo userInfo = UserInfo.getInstance();<br>
//Retrieving current tab info:
+
<span style="color:green">//Retrieving current tab info:</span><br>
String currentTab = userInfo.getCurrentTab(session.getId());
+
String currentTab = userInfo.getCurrentTab(session.getId());<br>
ExtendedGSSCredential credential = null;  
+
ExtendedGSSCredential credential = null; <br>
try { //Retrieving credential:
+
try { <span style="color:green">//Retrieving credential:</span><br>
    credential = userInfo.getCredentials(session);
+
&nbsp;&nbsp;&nbsp;&nbsp;credential = userInfo.getCredentials(session);<br>
}
+
}<br>
catch (Exception e) {
+
catch (Exception e) {<br>
    e.printStackTrace();
+
&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br>
}
+
}<br>
//Initializing DHLSClient:
+
<span style="color:green">//Initializing DHLSClient:</span><br>
DISHLSClient.init(System.getProperty("GLOBUS_LOCATION") + "/etc/org_diligentproject_keeperservice_hnm/" + "DISQueries.xml");
+
DISHLSClient.init(System.getProperty("GLOBUS_LOCATION") + "/etc/org_diligentproject_keeperservice_hnm/" + "DISQueries.xml");<br>
</nowiki></pre>
+
</code>
 +
 
 
===Imports===
 
===Imports===
 
<code>'''import''' org.diligentproject.dvos.portal.UserInfo; <span style="color:green">//In gridsphere-portal-2.2.jar</span><br>
 
<code>'''import''' org.diligentproject.dvos.portal.UserInfo; <span style="color:green">//In gridsphere-portal-2.2.jar</span><br>

Revision as of 16:37, 25 May 2007

How to use DILIGENT credentials in a Portlet / Servlet

Pre-development Actions

Patching GridSphere

In order to use credentials you have first to patch gridSphere so as to enable it to consume DILIGENT Credentials.
(info to be added...)

Using Credentials API

Available Methods

ExtendedGSSCredential getCredentials(PortletSession session)

  • You should use this method if you want to retrieve the credential from the portlet.
  • It returns a grid credential that you should pass to DIS or every other service that you want to use.

ExtendedGSSCredential getCredentials(HttpSession session)

  • You should use this method if you want to retrieve the credential from the servlet.
  • It returns a grid credential that you should pass to DIS or every other service that you want to use.

String getHttpScheme(String sessionID)

  • It takes as parameter the sessionID.
  • It returns the schema that the user uses in order to communicate with the portal (http / https).

String getCurrentTab(String sessionID)

  • It takes as parameter the sessionID.
  • It returns the name of user's current tab.

HashMap<String, String> getUserInfo(String sessionID)

  • It takes as parameter the sessionID.
  • It returns a HashMap with all the userInfo

String getDN(String sessionID)

  • It takes as parameter the sessionID.
  • It returns the DN of the user credential.

String getCA(String sessionID)

  • It takes as parameter the sessionID.
  • It returns the CA of the user credential.

String getCN(String sessionID)

  • It takes as parameter the sessionID.
  • It returns the CN of the user credential.

Useful Information

  1. The names of the tabs must be in the form of: /diligent/<VO name>/<DL name>. Otherwise the credential which will be retrieved won't be valid.Tab name.PNG
  2. UserInfo class, which is defined in package org.diligentproject.dvos.portal, is a singleton. So, if you want to retrieve the instance of this class, you must call the getInstance() method.

Sample Code

//Retrieving UserInfo instance:
UserInfo userInfo = UserInfo.getInstance();
//Retrieving current tab info:
String currentTab = userInfo.getCurrentTab(session.getId());
ExtendedGSSCredential credential = null;
try { //Retrieving credential:
    credential = userInfo.getCredentials(session);
}
catch (Exception e) {
    e.printStackTrace();
}
//Initializing DHLSClient:
DISHLSClient.init(System.getProperty("GLOBUS_LOCATION") + "/etc/org_diligentproject_keeperservice_hnm/" + "DISQueries.xml");

Imports

import org.diligentproject.dvos.portal.UserInfo; //In gridsphere-portal-2.2.jar
import org.diligentproject.informationservice.dishlsclient.impl.DISHLSClient; // In dishlsclient jar-file
import org.gridforum.jgss.ExtendedGSSCredential; // In ws-core libraries