Websphere has thought about external authentication and provided a authentication proxy or a authentication plugin. Such plugin is TAI using this we can authenticate a user and send that userid to websphere container as authenticated user.
External authentication --> TAI interceptor --> success --> Create LTPA token and store it in browser --> websphere container
TAI interceptor :- Using TAI interceptor we can first decide whether to parse request or not. If request is being parsed we can decide whether to send it to was or not.
Usecase :- Integrating tomcat authentication with websphere portal
Step1 :- Create a class which extends TrustAssociationInterceptor , Add websphere portal server to classpath to avoid errors{Methods and significance is explained below}
import java.util.Properties; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.ibm.websphere.security.WebTrustAssociationException; import com.ibm.websphere.security.WebTrustAssociationFailedException; import com.ibm.wsspi.security.tai.TAIResult; import com.ibm.wsspi.security.tai.TrustAssociationInterceptor; /** * A simple custom Trust Association Interceptor. */ public class TomcatInterceptor implements TrustAssociationInterceptor { /* * In this method we can validate whether the request is from trusted * client or not. * */ public boolean isTargetInterceptor(HttpServletRequest req) throws WebTrustAssociationException { // Lets do some validation on the incoming request String username = req.getParameter("username"); // If we got a username the request for TAI only. if (username != null) return true; return false; } /*
* Using this method we can decide to pass request to WAS server ot not */ public TAIResult negotiateValidateandEstablishTrust(HttpServletRequest req, HttpServletResponse resp) throws WebTrustAssociationFailedException { // Validate and establish trust with WebSphere Application Server. TAIResult result = null; String username = req.getParameter("username"); // Create the TAIResult with username we got. result = TAIResult.create(HttpServletResponse.SC_OK, username); // return the TAIResult. return result; } /*
* We can put some initialization codes here */ public int initialize(Properties arg0) throws WebTrustAssociationFailedException { // The TAI initialization code goes here. return 0; } /* * You can return the version of TAI */ public String getVersion() { // The version of TAI we are using. return "1.0"; } /* * Type of TAI */ public String getType() { // The type of TAI. return "Custom TAI 1.0"; } /* * All cleanup code goes here */ public void cleanup() { // The TAI clean up code goes here. } }
Step 2 :- Now you need to export this jar and put it under (C:\IBM\WebSphere\AppServer\lib\ext)
Now we need to enable trust association in portal so login to application server and navigate till this page and click on trust association
Step 3 :- Now download tomcat server and then add it to your rad. Then create a J2EE application with login page and point it to below servlet.
Login page :-
<!DOCTYPE HTML><%@page language="java"
Servlet :-
package com.authentication.login; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class LoginServlet */ @WebServlet("/LoginServlet") public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LoginServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String username = request.getParameter("username"); request.setAttribute("username", username); RequestDispatcher rd = request.getRequestDispatcher("/JSPS/SuccessPage.jsp"); rd.include(request, response); } }
Success Page :-
Step4 :- Now launch the J2ee application then login and click on the link to navigate to portal then user will be navigated to portal without asking for userid and password.
External authentication --> TAI interceptor --> success --> Create LTPA token and store it in browser --> websphere container
TAI interceptor :- Using TAI interceptor we can first decide whether to parse request or not. If request is being parsed we can decide whether to send it to was or not.
Usecase :- Integrating tomcat authentication with websphere portal
Step1 :- Create a class which extends TrustAssociationInterceptor , Add websphere portal server to classpath to avoid errors{Methods and significance is explained below}
import java.util.Properties; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.ibm.websphere.security.WebTrustAssociationException; import com.ibm.websphere.security.WebTrustAssociationFailedException; import com.ibm.wsspi.security.tai.TAIResult; import com.ibm.wsspi.security.tai.TrustAssociationInterceptor; /** * A simple custom Trust Association Interceptor. */ public class TomcatInterceptor implements TrustAssociationInterceptor { /* * In this method we can validate whether the request is from trusted * client or not. * */ public boolean isTargetInterceptor(HttpServletRequest req) throws WebTrustAssociationException { // Lets do some validation on the incoming request String username = req.getParameter("username"); // If we got a username the request for TAI only. if (username != null) return true; return false; } /*
* Using this method we can decide to pass request to WAS server ot not */ public TAIResult negotiateValidateandEstablishTrust(HttpServletRequest req, HttpServletResponse resp) throws WebTrustAssociationFailedException { // Validate and establish trust with WebSphere Application Server. TAIResult result = null; String username = req.getParameter("username"); // Create the TAIResult with username we got. result = TAIResult.create(HttpServletResponse.SC_OK, username); // return the TAIResult. return result; } /*
* We can put some initialization codes here */ public int initialize(Properties arg0) throws WebTrustAssociationFailedException { // The TAI initialization code goes here. return 0; } /* * You can return the version of TAI */ public String getVersion() { // The version of TAI we are using. return "1.0"; } /* * Type of TAI */ public String getType() { // The type of TAI. return "Custom TAI 1.0"; } /* * All cleanup code goes here */ public void cleanup() { // The TAI clean up code goes here. } }
Step 2 :- Now you need to export this jar and put it under (C:\IBM\WebSphere\AppServer\lib\ext)
Now we need to enable trust association in portal so login to application server and navigate till this page and click on trust association
Make sure Enable trust association is checked. Then click on Interceptors
Click on new and add your interceptor
Please enter your interceptor name in Interceptor class name field
Click save and then restart the server
Step 3 :- Now download tomcat server and then add it to your rad. Then create a J2EE application with login page and point it to below servlet.
Login page :-
<!DOCTYPE HTML><%@page language="java"
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>LoginPage</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<h1> Login to tomcat application </h1>
<form action="<%=request.getContextPath()%>/LoginServlet" method="post">
Username :- <input type="text" name="username" />
Password :- <input type="password" name="password">
<input type="submit" value="submit">
</form>
</body>
</html>
package com.authentication.login; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class LoginServlet */ @WebServlet("/LoginServlet") public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LoginServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String username = request.getParameter("username"); request.setAttribute("username", username); RequestDispatcher rd = request.getRequestDispatcher("/JSPS/SuccessPage.jsp"); rd.include(request, response); } }
Success Page :-
<!DOCTYPE HTML><%@page language="java"
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>SuccessPage</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<!-- Pass username for authentication !-->
<a href="https://wportal8.atech.com:10029/wps/myportal?username=${username}">Navigate to portal</a>
</body>
</html>
Step4 :- Now launch the J2ee application then login and click on the link to navigate to portal then user will be navigated to portal without asking for userid and password.