home *** CD-ROM | disk | FTP | other *** search
/ ftp.rsa.com / 2014.05.ftp.rsa.com.tar / ftp.rsa.com / pub / partner_engineering / ClearTrust / Verity / ticket.jsp < prev   
Text File  |  2014-05-02  |  10KB  |  322 lines

  1. <%
  2.     /*
  3.        I18N Code: The charset needs to be changed appropriately based on the
  4.         charset that you want to see the output in. You can get the list of charsets
  5.         from the following link. 
  6.         http://java.sun.com/j2se/1.3/docs/guide/intl/encoding.doc.html
  7.     */
  8. %>
  9. <%@ page contentType='text/html; charset=iso-8859-1'%>
  10. <%@ page language="java" %>
  11. <%@ page import="java.util.*" %>
  12. <%@ page import="java.net.*" %>
  13. <%@ page import="com.verity.search.VSearch" %>
  14. <%@ include file="../common/cookies.jnc" %>
  15.  
  16. <HTML>
  17. <HEAD>
  18.         <title>K2 Authentication.</title>
  19.         <link rel="stylesheet" href="common/site.css">
  20.         <style media="screen" type="text/css">
  21.         <!-- a { color: #ad0010; text-decoration: none }
  22. a:hover { color: #ad0010; text-decoration: underline }
  23.         -->
  24.         </style>
  25. </HEAD>
  26. <%
  27. // <Bruce Bordelon>
  28. //  added a focus function call to put the cursor into the user name input box
  29. %>
  30. <BODY bgcolor="#ffffff" onload="if(document.ticket && document.ticket.user){document.ticket.user.focus();}else{document.ticketclose.close.focus();}">
  31. <%
  32. // </Bruce Bordelon>
  33.     String serverSpec = request.getParameter("serverSpec");
  34.     if (serverSpec == null || serverSpec.equals("")){
  35.         serverSpec = (String)System.getProperty("VERITY_K2_HOSTPORT");
  36. // <Bruce Bordelon>
  37. //  also check the context configuration for the VERITY_K2_HOSTPORT property
  38.         if (serverSpec == null || serverSpec.equals(""))
  39.           serverSpec = (String)getServletConfig().getServletContext().getInitParameter("VERITY_K2_HOSTPORT");
  40. // </Bruce Bordelon>
  41.     }
  42.     if (serverSpec == null){
  43. %>        <i><FONT color="red"><b>Error: Failed to obtain serverspec.</i></b></head>
  44.             <body><FONT color="red"><br>Unable to determine the serverSpec from the
  45.             environment variable VERITY_K2_HOSTPORT.<br> Please set this env variable
  46.             to point to the proper K2 Broker/Server serverspec.
  47.             </body>
  48.         </html>
  49.  
  50. <%        return;
  51.     }
  52.  
  53.     String errorStr = null;
  54.     
  55.     String username, passwd, domain, ticket;
  56.     HttpSession sess = request.getSession(true);
  57.     String logout = request.getParameter("logout");
  58.     if( logout != null )
  59.     {
  60.         VSearch s0 = new VSearch();
  61.         s0.setServerSpec(serverSpec);
  62.  
  63.         // I18N code: Set the charmap for the VSearch object. This will cause VDK
  64.         // to input and output data in this charset.
  65.         s0.setCharMap("1252");     
  66.                 
  67.         s0.k2Logoff((String)sess.getAttribute("ticket"));
  68.         sess.setAttribute("ticket", "");
  69.         response.addCookie(new Cookie("SAMPLE_TEMPLATES_LOGGEDON","")); // clear the ticket cookie
  70. %>
  71.         <table border="0" cellpadding="0" cellspacing="0" width="100%">        
  72.             <tr>            
  73.                 <td></td>            
  74.                 <td align="right" rowspan="2">                
  75.                     <div align="right">                        
  76.                     <a href="http://www.verity.com"><IMG border=0 height=66 src="../images/verity_logo.gif" vspace=7 width=133></a></div>                
  77.                 </td>            
  78.             </tr>            
  79.             <tr>            
  80.                 <td align="left" valign="bottom">                
  81.                     <table border="0" cellpadding="0" cellspacing="0">                    
  82.                         <tr>                        
  83.                             <td></td>                        
  84.                             <td></td>                        
  85.                             <td></td>                            
  86.                             <td></td>                            
  87.                             <td></td>                        
  88.                         </tr>                    
  89.                     </table>                
  90.                 </td>            
  91.             </tr>        
  92.         </table>        
  93.         <table border="0" cellpadding="0" cellspacing="2" bgcolor="black" width="100%">        
  94.             <tr>            
  95.                 <td>                
  96.                     <table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="#f2f2f2">                    
  97.                         <tr>    
  98.                             <td bgcolor="#f2f2f2"  valign="top"><b>Successfully Logged Off</b></td>
  99.                         </tr>
  100.                         <tr>    
  101.                             <td bgcolor="#f2f2f2"  valign="top"><br><br><br><br><br></td>
  102.                         </tr>
  103.                         <tr>
  104. <%
  105. // <Bruce Bordelon>
  106. //  added a focus function call to put the cursor into the user name input box
  107. %>
  108. <form name="ticketclose">
  109.                             <td  bgcolor="#f2f2f2" align="center" valign="top"><input type=button name=close value="Close" onClick="window.opener.location.href = window.opener.location.href; window.close();"></td>
  110. </form>
  111. <%
  112. // <Bruce Bordelon>
  113. %>
  114.                         </tr>                                
  115.                     </table>
  116.                 </td>
  117.             </tr>
  118.         </table>
  119.         </BODY>
  120.         </HTML>
  121. <%
  122.     }
  123.     else
  124.     {
  125.     if (request.getParameter("submit") != null) { //form is submitted.
  126.         try {
  127.             VSearch s0 = new VSearch();
  128.             s0.setServerSpec(serverSpec);
  129.             
  130.             String userParam=null;
  131.             String ct_user = request.getHeader("HTTP_CT_REMOTE_USER");
  132.             s0.setK2UserName(ct_user);
  133.             userParam = "HTTP_CT_REMOTE_USER;="+ct_user;
  134.             s0.addUserParamCredential(userParam);
  135.             sess.putValue("user",ct_user);
  136.             
  137.             
  138.  
  139.             // I18N code: Set the charmap for the VSearch object. This will cause VDK
  140.             // to input and output data in this charset.
  141.             s0.setCharMap("1252");     
  142.  
  143.             ticket = s0.k2Login();
  144.     
  145.             // Put the ticket as session variable
  146.             sess.setAttribute("ticket", ticket);
  147.             sess.setAttribute("user",ct_user);
  148.             
  149.             response.addCookie(new Cookie("SAMPLE_TEMPLATES_LOGGEDON","LoggedOn")); // set the ticket cookie
  150.  
  151.             // successfully obtained the ticket. so close the window            
  152. %>
  153.             <table border="0" cellpadding="0" cellspacing="0" width="100%">        
  154.                 <tr>            
  155.                     <td></td>            
  156.                     <td align="right" rowspan="2">                
  157.                         <div align="right">                        
  158. <%
  159. // <Bruce Bordelon>
  160. //  changed reference to /verity_templates to request.getContextPath()
  161. //  so that contexts could be arbitrary
  162. %>
  163.                         <a href="http://www.verity.com"><IMG border=0 height=66 src="<%=request.getContextPath()%>/images/verity_logo.gif" vspace=7 width=133></a></div>                
  164. <%
  165. // </Bruce Bordelon>
  166. %>
  167.                     </td>            
  168.                 </tr>            
  169.                 <tr>            
  170.                     <td align="left" valign="bottom">                
  171.                         <table border="0" cellpadding="0" cellspacing="0">                    
  172.                             <tr>                        
  173.                                 <td></td>                        
  174.                                 <td></td>                        
  175.                                 <td></td>                            
  176.                                 <td></td>                            
  177.                                 <td></td>                        
  178.                             </tr>                    
  179.                         </table>                
  180.                     </td>            
  181.                 </tr>        
  182.             </table>        
  183.             <table border="0" cellpadding="0" cellspacing="2" bgcolor="black" width="100%">        
  184.                 <tr>            
  185.                     <td>                
  186.                         <table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="#f2f2f2">                    
  187.                             <tr>    
  188.                                 <td bgcolor="#f2f2f2"  valign="top"><b>Successfully authenticated with K2 Ticket</b></td>
  189.                             </tr>
  190.                             <tr>    
  191.                                 <td bgcolor="#f2f2f2"  valign="top"><br><br><br><br><br></td>
  192.                             </tr>
  193.                             <tr>
  194. <%
  195. // <Bruce Bordelon>
  196. //  added a focus function call to put the cursor into the user name input box
  197. %>
  198. <form name="ticketclose">
  199.                                 <td  bgcolor="#f2f2f2" align="center" valign="top"><input type=button name=close value="Close" onClick="window.opener.location.href = window.opener.location.href; window.close();"></td>
  200. </form>
  201. <%
  202. // <Bruce Bordelon>
  203. %>
  204.                             </tr>                                
  205.                         </table>
  206.                     </td>
  207.                 </tr>
  208.             </table>
  209.         </BODY>
  210.     </HTML>        
  211. <%
  212.             
  213.         } catch (Exception e){
  214.             String errString = e.toString();
  215.             System.out.println("Got an exception" + errString);
  216.             if ((errString.indexOf("connection refused") >= 0) ||
  217.                 (errString.indexOf("Connection refused") >= 0) ||
  218.                 (errString.indexOf("Connection Refused") >= 0)) {
  219.                 errorStr = "<b>Login error: unable to connect to K2Server/Broker.</b>";
  220.             } else if (errString.indexOf("-303") >= 0) {
  221.                 errorStr = "<b>Incorrect username and password</b>";
  222.             } else if (errString.indexOf("-304") >= 0) {
  223.                 errorStr = "<b>Login error: No user credentials available (-304)<b>";
  224.             } else if (errString.indexOf("-305") >= 0) {
  225.                 errorStr = "<b> Login error: call to K2Ticket failed (-305)<b>";
  226.             } else if (errString.indexOf("-306") >= 0) {
  227.                 errorStr = "<b>Login error: K2Ticket server is not available (-306)<b>";
  228.             } else if (errString.indexOf("-1012") >= 0) {
  229.                 errorStr = "<b>Login error: -1012</b>";
  230.             } else if (errString.indexOf("-314") >= 0) {
  231.                 errorStr = "<b>Ticket error: ticket has expired (-314)<b>";
  232.             } else if (errString.indexOf("-80") >= 0) {
  233.                 errorStr = "<b>Ticket error: ticket is invalid (-80)<b>";
  234.             } else if (errString.indexOf("-14") >= 0) {
  235.                 errorStr = "<b>Ticket error: ticket is null (-14)<b>";
  236.             } else {
  237.                 errorStr =  errString ;
  238.             }        
  239.         }
  240.     }
  241.     
  242.     if ((errorStr != null) || (request.getParameter("submit") == null)){
  243. %>
  244.     <table border="0" cellpadding="0" cellspacing="0" width="100%">        
  245.         <tr>            
  246.             <td></td>            
  247.             <td align="right" rowspan="2">                
  248.                 <div align="right">                        
  249. <%
  250. // <Bruce Bordelon>
  251. //  changed reference to /verity_templates to request.getContextPath()
  252. //  so that contexts could be arbitrary
  253. %>
  254.                 <a href="http://www.verity.com"><IMG border=0 height=66 src="<%=request.getContextPath()%>/images/verity_logo.gif" vspace=7 width=133></a></div>                
  255. <%
  256. // </Bruce Bordelon>
  257. %>
  258.             </td>            
  259.         </tr>            
  260.         <tr>            
  261.             <td align="left" valign="bottom">                
  262.                 <table border="0" cellpadding="0" cellspacing="0">                    
  263.                     <tr>                        
  264.                         <td></td>                        
  265.                         <td></td>                        
  266.                         <td></td>                            
  267.                         <td></td>                            
  268.                         <td></td>                        
  269.                     </tr>                    
  270.                 </table>                
  271.             </td>            
  272.         </tr>        
  273.     </table>        
  274.     <table border="0" cellpadding="0" cellspacing="2" bgcolor="black" width="100%">        
  275.         <tr>            
  276.             <td>                
  277.                 <table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="#f2f2f2">                    
  278. <%                if (errorStr != null){
  279. %>
  280.                     <tr>    
  281.                         <td bgcolor="#f2f2f2" valign="top"  colspan="2"><b><%=errorStr%></b></td>
  282.                     </tr>
  283. <%                }  %>
  284. <%
  285.                 // Check if a session timeout has occured, if it has, display a warning
  286.                 Cookie objCookieLoggedOn = getCookie(request.getCookies(),"SAMPLE_TEMPLATES_LOGGEDON");
  287.                 
  288.                 if (objCookieLoggedOn != null && !objCookieLoggedOn.getValue().equals("")) {
  289. %>
  290.                     <tr>    
  291.                         <td bgcolor="#f2f2f2" valign="top"  colspan="2"><b>Session time out, please login again.</b></td>
  292.                     </tr>
  293. <%
  294.                     objCookieLoggedOn.setValue("");
  295.                     response.addCookie(objCookieLoggedOn); // clear the ticket cookie, the only way they can get here if they're logged in is if they logout or a timeout occured
  296.                 }
  297. %>
  298.                     <tr>    
  299.                         <td bgcolor="#f2f2f2"  valign="top" colspan="2"><b>Retrieve K2 ticket</b></td>
  300.                     </tr>
  301.                     <form name="ticket" method="post" action="ticket.jsp">
  302.                         <input type=hidden name=serverSpec value=<%=serverSpec%>>
  303.                     <tr>
  304.                         <b>Retrieve K2 ticket</b>
  305.                     </tr>
  306.  
  307.                     <tr>
  308.                         <td bgcolor="#f2f2f2" valign="top" colspan=2 align="center">
  309.                             <input type="submit" name="submit" value="Submit">
  310.                             <input type="button" name="close" value="Cancel" onClick="window.close();">
  311.                         </td>
  312.                     </tr>
  313.                     </form>
  314.                 </table>
  315.             </td>
  316.         </tr>
  317.     </table>
  318. </BODY>
  319. </HTML>
  320. <% }  %>
  321. <% }  %>
  322.