3 Replies Latest reply on Feb 2, 2007 2:23 PM by kerekesb

    Programmatic login

    lehd

      Hi all.

      I need to implement the following scenario:
      there is a login portlet with 2 fields for username and password and login button. Button has action url which triggers action in the portlet which makes real authentication. I dont want to use form-based authentication.
      Any ideas would be very helpful. I know the topic is not so easy but maybe somebody already has a solution.

      Thx

        • 1. Re: Programmatic login
          kerekesb

          This is our solution:

          This is our login page:

          <%@ page language="java" extends="org.jboss.portal.core.servlet.jsp.PortalJsp" %>
          <%@ taglib uri="/WEB-INF/portal-lib.tld" prefix="n" %>
          <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
          <%@ page isELIgnored ="false" %>
          <portlet:defineObjects/>
          
          <div id="auth">
           <div id="infotecPortal"><div id="IPicon"></div></div>
           <div class ="clear"></div>
           <form method="POST" action="/portal/auth/enlogin" id="login-form" name="loginform" class="formStyle">
           <table id="loginTable" cellspacing="0">
           <tr>
           <td rowspan="2"><div id="loginLeft"></div></td>
           <td><div id="loginLeftUserIcon"></div></td>
           <td><div id="LoginFormDivUser"><input name="j_username" tabindex="1" id="username" type="text" size="24" onfocus="this.value=''" onblur="checkLoginBox()" class="formInputLogin" value="Account"></div></td>
           <td><div id="loginRightUserIcon"></div></td>
           <td rowspan="2" id="loginTdBtn"><div id="loginSubmit"><button id="sbtn" class="sbtnClass" tabindex="3" type="submit" onmouseover="loginBtnOver()" onmouseout="loginBtnOut()"></button></div></td>
           </tr>
           <tr>
           <td><div id="loginLeftPassIcon"></div></td>
           <td><div id="LoginFormDivPass"><input name="j_password" tabindex="2" id="password" type="password" hidden="true" size="24" onfocus="this.value=''" onblur="checkPassBox()" class="formInputLogin" value="Password"></div></td>
           <td><div id="loginRightPassIcon" ></div></td>
          
           </tr>
           </table>
           </form>
          </div>
          


          And this is the modified form based login page in portal-server-war:

          <%
           String contextPath = request.getContextPath();
          
           String username = request.getParameter("j_username");
           String password = request.getParameter("j_password");
          
           if (username != null && password != null && !username.equals("null")) {
           String url = "j_security_check?j_username=" + username + "&j_password=" + password;
           String redirectUrl = response.encodeRedirectURL(url);
           response.sendRedirect(redirectUrl);
           }
          %>
          
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html>
          <head>
          <style type="text/css">
          body {
           margin:0px;
           padding:0px;
          }
          #Login_header{
           width: 100%;
           margin: 0;
           color: #fff;
           background:url(/portal-core/images/login/login_bg.gif) repeat-x;
           height: 29px;
           overflow:hidden;
          }
          #header_right {
           background:url(/portal-core/images/login/login_right.jpg);
           height: 29px;
           width: 291px;
           padding: 0px;
           margin: 0px;
           float:right;
          }
          #login-container {
           margin:0;
           margin-top:50px;
           padding:0;
          }
          #login {
           margin:0 auto;
           padding:0;
           width: 320px;
           height: 250px;
           font-family: "Verdana";
           font-size: 10px;
          }
          #username {
           border: 1px solid #18457d;
           color:#18457d;
           width:200px;
          }
          #password {
           border: 1px solid #18457d;
           color:#18457d;
           margin-top:10px;
           width:200px;
          }
          #loginButton {
           width: 81px;
           height: 17px;
           padding: 0px 0 0;
           margin: 15px 0px 0px 200px;
           border: 0;
           background: transparent url(/portal-core/images/login/belepes_gomb.jpg) no-repeat top left;
           overflow: hidden;
           vertical-align: middle;
           cursor: pointer; /* hand-shaped cursor */
           cursor: hand; /* IE 5.x */
          }
          </style>
          </head>
          
          <%
           String loginString = "Login";
           String userString = "Username";
           String passwordString = "Password";
          %>
          <body id="body" style="background:#e7e6e7;" OnLoad="document.loginform.j_username.focus();">
           <div id="Login_header">
           <div id="header_right"></div>
           </div>
           <div id="login-container">
           <div id="login">
           <fieldset><legend><%= loginString%></legend>
           <form method="POST" action="j_security_check" name="loginform" id="loginForm">
          
           <table id="loginTable" cellspacing="0">
           <tr>
           <td><label for="username" class="loginLabel"><%= userString%>:</label></td>
           <td><input type="text" name="j_username" id="username" size="25" value=""/></td>
           </tr>
           <tr>
           <td><label for="password" class="loginLabel"><%= passwordString%>:</label></td>
           <td><input type="password" name="j_password" id="password" size="25" value=""/></td>
           </tr>
           </table>
           <div id="login_btn">
           <button id="loginButton" type="submit"></button>
           </div>
           </form>
           </fieldset>
           </div>
           </div>
          
          </body>
          </html>
          


          • 2. Re: Programmatic login
            vipinmpd08



            Hai

            Iam also working in Jboss portal

            It was very informative

            But i havn't get in when the sending method is "POST"

            and i tried it with "GET" and it seems to be working

            whats wrong

            Thanks :)

            • 3. Re: Programmatic login
              kerekesb