• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cookie is not getting generated - please help me

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a struts2 webapplication which i am integrating with another forum webapplication.When the user logs into the Struts2 application, i want to maintani his session in forum also and forum should not ask him to login again.For thsi i am using a cookie which is not at all getting generated.
I changed the code in Jsp and installed the Web developer toolbar. The cookie is not at all coming when i enter Jforum application from Main application. I have 2 separate wars. I am highly puzzled what else i have to do? Please find the jsp,Util class files.
I am not doing cookie.setDomain(domain); is it causing the issue?



Header.jsp[/u]:

This is my main application URL from where i will move to Jforum after clicking a link in this jsp

http://localhost:8080/MyOwnBriefcase-0.0.1/public/welcome.action

This is my Jforum URL which i get when the user moves to Jforum from main application

http://localhost:8080/jforum/forums/list.page

----------------------------------------------------------------
I have the following code in jsp where cookie is formed and then the user clicks on the hiper link. Is this not the way???


<authz:authorize ifAnyGranted="ROLE_ADMIN,ROLE_EMPLOYER,ROLE_EMPLOYEE">
<%
User userObj = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = userObj.getEmail();
String password = userObj.getPassword();
String encrypted = CookieUtil.makeSSOCookieValue(username, password);
Cookie cookie = new Cookie("sso-auto-login", encrypted);
cookie.setMaxAge(120000); // 10 hours in seconds (can be -1 for session).
//cookie.setDomain(domain); // Full qualified server domain.
cookie.setPath("/");
response.addCookie(cookie);
%>
<a href="http://localhost:8080/jforum/" cssClass="thf_line">COOKIE FORUMS</a>
</authz:authorize> </div>

------------------------------------------------------------
CookieUtil:[u]

package com.mob.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class CookieUtil {
static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmm");
static final String md5Salt = "someWeirdStringSharedByTheApps";
/**
* Makes the MD5 token used for authentication in cookies.
*
* @param userName The user id used for encryption.
* @param email The user's email (or "" if none).
* @param groupInfo The category of groups the user is to be allowed
* access to.
* @param timestamp A yyyyddMMhhmm representation of when the cookie
* was created.
* @return The hex string representation of the MD5 digested string.
* @exception NoSuchAlgorithException If for some reason, MD5 is
* not available?
*/
protected static String makeMD5Token (String userName, String password,
String timestamp )
throws NoSuchAlgorithmException {
MessageDigest md;
byte[] sig;
String plainText;
StringBuffer encryptedText = new StringBuffer();
plainText = md5Salt + "/" + userName + "/"+ password +
"/" + timestamp;
md = MessageDigest.getInstance("MD5");
sig = md.digest(plainText.getBytes());
for ( int i = 0; i < sig.length; i++ ) {
encryptedText.append(Integer.toString(( sig[i] & 0xff ) +
0x100, 16 ).substring(1));
}
return encryptedText.toString();
}


public static String makeSSOCookieValue(String userName, String password)
throws NoSuchAlgorithmException
{
String timestamp = dateFormatter.format(new Date());
return userName + "/" + password + "/" +
makeMD5Token(userName, password, timestamp );
}
}

------------------------------------------------------


Thanks
Greg
 
reply
    Bookmark Topic Watch Topic
  • New Topic