Thursday, September 11, 2008

Ticket Based Authentication for Documentum-Helps to Implement Single Sign On

I feel ticket based authentication for documentum can help in implementing single signon process from another application B. An intermediate servlet between Documentum and that application can do the trick. The steps are as follows:
1.Create a super user account in documentum(if not already present).
1. Create user accounts with identical username in documentum as present in application B.(You can use jobs for that)
2.Keep the Documentum super user password encrypted in a properties file.
3. Fetch the Username of the user logged into the application B using application B’s API into the servlet.
4.Get the documentum super user session in the servlet.
5.Use documentum super user session to get the documentum login ticket of the user(username fetched using app B's API) logged in to the application B.
The servlet will then launch the webtop using this login ticket.

The servlet code should be like this:
public class SSOServlet extends HttpServlet
{
IDfSession session=null;
IDfSessionManager sessMgr=null;
private String superUserName="admin"; //super user name is hardcoded(can be kept in properties file)
private String superUserPwd="adminpwd"; //super user password is hardcoded(can be kept in properties file)

private String username="test_user ";//username should come for application B API

private String docbaseName="Test_DocBase";
private IDfSession getDfSession() throws DfException
{
IDfClientX moClientX =new DfClientX();
IDfClient client = moClientX.getLocalClient();
//create an IDfLoginInfo object named "loginInfoObj"
IDfLoginInfo loginInfoObj = moClientX.getLoginInfo();
loginInfoObj.setUser(superUserName);
loginInfoObj.setPassword(superUserPwd);
loginInfoObj.setDomain("");
sessMgr= client.newSessionManager();
sessMgr.setIdentity(docbaseName, loginInfoObj);
session = sessMgr.getSession(docbaseName);
return session;
}

public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
PrintWriter out = response.getWriter();
try
{
String loginTicket=getDfSession().getLoginTicketForUser(username);
String url="/webtop/component/main?ticket="+loginTicket+" &username="+username+" &docbase="+ docbaseName;
response.sendRedirect(url);
}
catch(DfException dfe)
{
out.println("Inside Exception");
dfe.printStackTrace();
}
}
}

This servlet should be invoked from application B. The servlet will launch the webtop.

Wednesday, July 30, 2008

Tiff to PDF conversion Using Java

Recently I had converted tiff to pdf using java and IText API.Both the jar as well
as source code can be found in the following urls:
http://www.lowagie.com/iText/download.html
http://itextdocs.lowagie.com/tutorial/objects/images/tiff/index.php

Thursday, July 10, 2008

Solution to a coding puzzle .

Recently I came across a coding puzzle posted in Cedric Beust's weblog(http://beust.com/weblog/).The puzzle is:

Write a counter function that counts from 1 to max but only returns numbers whose digits don't repeat.

For example, part of the output would be:

8, 9, 10, 12 (11 is not valid)
98, 102, 103 (99, 100 and 101 are not valid)
5432, 5436, 5437 (5433, 5434 and 5435 are not valid)
Also:
Display the biggest jump (in the sequences above, it's 4: 98 -> 102)
Display the total count of numbers
Give these two values for max=10000

Though I know that my solution is not that good because I am converting the numbers to string for solving the problem, but still its working....Please post a better approach if you have any......


public class Puzzle
{
//Method for comparing digits of a number with each other
private boolean compareDigits(int number)
{
String digitString=null; //holds string representation of numbers.
digitString=new Integer(number).toString();
boolean flag=true;
for(int strcount=0;strcount<digitString.length();strcount++)
{
for(int temp=strcount+1;temp<digitString.length();temp++)
{
if(digitString.substring(strcount,strcount+1).equalsIgnoreCase(digitString.substring(temp,temp+1)))
{
flag=false;
}
}
}
return flag;
}


public static void main(String []args)
{
int max=new Integer(args[0]).intValue();//holds the maximum number
int counter=0; //holds the count of numbers printed
int biggestJump=0;
int prevInteger=0;
Puzzle puzzleObj=new Puzzle();
for(int num=1;num<=max;num++)
{
boolean isPrintable=puzzleObj.compareDigits(num); //isPrintable is true if the number doesn't have any repeating digit
if(isPrintable)
{
if(biggestJump<(num-prevInteger))
{
biggestJump=num-prevInteger;
}
prevInteger=num;
System.out.println(num);
counter++;
}


}
System.out.println("Total count of numbers is:"+counter);
System.out.println("Biggest Jump="+biggestJump);

}

}

Tuesday, June 24, 2008

About keeping PCs ON while leaving from office

I have seen many people keeping their computers ON while leaving for the day. A lot of electricity can be saved if we all shut down our PCs before leaving. So its my humble request to all of you people to shutdown your PCs before leaving for home.We can do this small thing.Isn't it??

Thursday, April 17, 2008

Parsing XML present within Documentum Server

Here is the Java method for parsing an XML file present within documentum. In this case JDOM has been used for the parsing purpose . Other Document parsers can also be used.

/*The argument of the method is the documentum session object and r_object_id of the xml document. The method returns a org.jdom.Document object which can then be used to parse the XML file (ref: http://www.jdom.org/) .*/

private Document parseXML(IDfSession losession,String r_object_id)
{
IDfSysObject xmlObj =null;
Document document=null;
try
{
xmlObj =(IDfSysObject) losession.getObject(new DfId(r_object_id));
System.out.println("objectname= "+xmlObj.getObjectName());
ByteArrayInputStream bis=xmlObj.getContent();
/*getContent() method returns a ByteArrayInputStream object of the file present in
content server. This method is also helpful in reading files having other extensions. */
SAXBuilder builder = new SAXBuilder();
document = builder.build(bis);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
return document;
}
}