Hello
I have a class that takes username and password parameter and vaildates them with a back-end db table, if all is Ok, return a token (String token = "blaa")
I want to save this token in a soap header so it accessible to all client web services - Can someone show me how to do this?
Also i need to make sure the otoken is still valid, check the timestamp in a back-end table. Bring up awarning id it is about to expire so it can be renewed, can someone help meout here as well
Thanks for any help
Here's my code:
I have a class that takes username and password parameter and vaildates them with a back-end db table, if all is Ok, return a token (String token = "blaa")
I want to save this token in a soap header so it accessible to all client web services - Can someone show me how to do this?
Also i need to make sure the otoken is still valid, check the timestamp in a back-end table. Bring up awarning id it is about to expire so it can be renewed, can someone help meout here as well
Thanks for any help
Here's my code:
Code:
public class LoginHandler extends HttpServlet
{
String sqlResults = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
PreparedStatement ps = null;
ResultSetMetaData rsmd = null;
public String validateUser (String userName, String password)
{
// pass userName and password values back to db to see if they exist
// connect to ConnectionFactory
String sql = "SELECT * FROM tblUsers WHERE userName = '"+userName+"' AND password = '"+password+"'";
try
{
conn = ConnectionFactory.getConection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
ps = conn.prepareStatement(sql);
// iterate through recordset and get data
if (rs.next())
{
sqlResults = rs.getString("userName");
}
}
catch (Exception e)
{
System.out.println("unsuccessful");
e.printStackTrace();
}
finally
{
ConnectionFactory.closeStatement(stmt);
ConnectionFactory.closeConnection(conn);
}
return sqlResults;
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// get userName and password entered by user
String userName = request.getParameter("userName");
String password = request.getParameter("password");
// get application Id from calling web service
String applicationId = request.getParameter("applicationId");
// call validateUser method to validate userName and password
String validateUserName = validateUser(userName, password);
if (validateUserName == null)
{
// redirect to login page
// either typo error or not registered
}
else
{
//HttpSession session = request.getSession(true);
//String sessionId = session.getId();
//session.setAttribute("sessionId", sessionId);
// get a unique user id
String uniqueUserId = WebServiceToken.getUniqueId();
// set expiry date 7 days from now
Calendar expiryDate = Calendar.getInstance();
expiryDate.roll(Calendar.DATE, 7);
applicationId = "wsAppTest";
// insert token details
WebServiceToken.setTokenDetails(userName, uniqueUserId, expiryDate, applicationId);
// return a token and use in the calling web service
String token = WebServiceToken.getToken(uniqueUserId, applicationId);
// we have a tokem put this token in SOAP header
}
}
}