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

    Programmatic login

    lehd Newbie

      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.


        • 1. Re: Programmatic login
          Balazs Kerekes Newbie

          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" %>
          <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">
           <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>
           <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>

          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);
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          <style type="text/css">
          body {
           width: 100%;
           margin: 0;
           color: #fff;
           background:url(/portal-core/images/login/login_bg.gif) repeat-x;
           height: 29px;
          #header_right {
           height: 29px;
           width: 291px;
           padding: 0px;
           margin: 0px;
          #login-container {
          #login {
           margin:0 auto;
           width: 320px;
           height: 250px;
           font-family: "Verdana";
           font-size: 10px;
          #username {
           border: 1px solid #18457d;
          #password {
           border: 1px solid #18457d;
          #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 */
           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 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">
           <td><label for="username" class="loginLabel"><%= userString%>:</label></td>
           <td><input type="text" name="j_username" id="username" size="25" value=""/></td>
           <td><label for="password" class="loginLabel"><%= passwordString%>:</label></td>
           <td><input type="password" name="j_password" id="password" size="25" value=""/></td>
           <div id="login_btn">
           <button id="loginButton" type="submit"></button>

          • 2. Re: Programmatic login
            Vipindas V G Newbie


            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 :)