Author: chathura
Date: Thu Jan 17 03:47:06 2008
New Revision: 12405

Log:


AJAXified the user log in. Now if the user is not authenticated it is displayed 
on top of the login box. All messages are sent using ajax!



Modified:
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/UserUtil.java
   trunk/registry/modules/webapps/src/main/webapp/admin/header.jsp
   trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   Thu Jan 17 03:47:06 2008
@@ -92,18 +92,20 @@
 
             if (command.equals("/signin")) {
 
-                SignInAction signInAction = new SignInAction();
-                signInAction.setUserName(request.getParameter("userName"));
-                signInAction.setPassword(request.getParameter("password"));
+                //SignInAction signInAction = new SignInAction();
+                //signInAction.setUserName(request.getParameter("userName"));
+                //signInAction.setPassword(request.getParameter("password"));
+                //
+                //try {
+                //    signInAction.execute(request);
+                //} catch (Exception e) {
+                //    setErrorMessage(request, e.getMessage());
+                //    e.printStackTrace();
+                //}
+                //
+                //response.sendRedirect("/wso2registry/web" + path);
 
-                try {
-                    signInAction.execute(request);
-                } catch (Exception e) {
-                    setErrorMessage(request, e.getMessage());
-                    e.printStackTrace();
-                }
-
-                response.sendRedirect("/wso2registry/web" + path);
+                UserUtil.signIn(request, response);
 
                 //forwardToResources(request, response, path);
 

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/UserUtil.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/UserUtil.java
      (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/UserUtil.java
      Thu Jan 17 03:47:06 2008
@@ -19,7 +19,9 @@
 import org.wso2.registry.RegistryException;
 import org.wso2.registry.RegistryConstants;
 import org.wso2.registry.Registry;
+import org.wso2.registry.jdbc.realm.RegistryRealm;
 import org.wso2.registry.web.UIConstants;
+import org.wso2.registry.web.ConsoleConstants;
 import org.wso2.registry.web.actions.UserDetailsAction;
 import org.wso2.registry.secure.SecureRegistry;
 import org.wso2.usermanager.Realm;
@@ -28,11 +30,59 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.ServletException;
+import javax.servlet.ServletContext;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.Map;
 
 public class UserUtil {
 
+    public static void signIn(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
+
+        String userName = request.getParameter("userName");
+        String password = request.getParameter("password");
+
+        PrintWriter writer = response.getWriter();
+
+        try {
+
+            if (userName.equals(RegistryConstants.SYSTEM_USER)) {
+                String msg = "ERROR: Users are not allowed to log in as the 
system user.";
+                writer.write(msg);
+                writer.flush();
+                return;
+            }
+
+            RegistryRealm realm = (RegistryRealm) 
request.getSession().getServletContext().
+                        getAttribute(RegistryConstants.REGISTRY_REALM);
+
+            if (realm.getAuthenticator().authenticate(userName, password)) {
+
+                ServletContext context =
+                        request.getSession().getServletContext();
+                Registry jdbcRegistry =
+                        (Registry) 
context.getAttribute(RegistryConstants.REGISTRY);
+
+                SecureRegistry secureRegistry =
+                        new SecureRegistry(userName, password, jdbcRegistry, 
realm);
+                
request.getSession().setAttribute(ConsoleConstants.USER_REGISTRY, 
secureRegistry);
+
+                writer.write("SUCCESS: User authenticated.");
+                writer.flush();
+                return;
+
+            } else {
+                writer.write("ERROR: Could not authenticate user " + userName);
+                writer.flush();
+                return;
+
+            }
+
+        } catch (Exception e) {
+            response.getWriter().write("ERROR: " + e.getMessage());
+        }
+    }
+
     public static boolean isAdmin(HttpServletRequest request, String userName) 
throws RegistryException {
 
         if (RegistryConstants.ADMIN_USER.equals(userName)) {

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/header.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/header.jsp     
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/header.jsp     Thu Jan 
17 03:47:06 2008
@@ -5,45 +5,47 @@
 </div>
 <div class="popup" id="popup" style="display:none;">
 
-       <table cellpadding="0" cellspacing="0" border="0" 
style="width:100%;border-bottom:solid 1px #989898;">
-               <tr>
-                       <td align="left" style="width:8px;"><img 
src="/wso2registry/admin/images/login-box-left.gif" /></td>
-                       <td align="left" class="login-menu" >Login</td>
-                       <td align="right" 
style="padding-right:0px;width:8px;"><img 
src="/wso2registry/admin/images/login-box-right.gif" /></td>
-               </tr>
-       </table>
-
-
-     <div id="loginBox" class="popup-bot">
-
-               <form action="/wso2registry/system/signin" method="post">
-                 <table class="form-table" border="0" cellspacing="0" 
cellpadding="0" style=" width:100%">
-                   <tr>
-                     <td>User Name:</td>
-                     <td><input type="text" name="userName" id="userName" 
/></td>
-                   </tr>
-                   <tr>
-                     <td>Password:</td>
-                     <td><input type="password" name="password" id="password" 
/></td>
-                   </tr>
-                   <tr>
-                     <td></td>
-                     <td>
-                       <input id="signin" type="submit" class="button" 
value="Sign In"/> <input type="button" class="button" value="Cancel" 
onclick="showHideCommon('popup-main'); showHideCommon('popup');" 
style="margin-left:10px;" />
-                     </td>
-                   </tr>
+    <table cellpadding="0" cellspacing="0" border="0" 
style="width:100%;border-bottom:solid 1px #989898;">
+        <tr>
+            <td align="left" style="width:8px;"><img 
src="/wso2registry/admin/images/login-box-left.gif" /></td>
+            <td align="left" class="login-menu" >Login</td>
+            <td align="right" style="padding-right:0px;width:8px;"><img 
src="/wso2registry/admin/images/login-box-right.gif" /></td>
+        </tr>
+    </table>
+
+
+    <div id="loginBox" class="popup-bot">
+
+        <div id="loginMessage"></div>
+
+        <form>
+            <table class="form-table" border="0" cellspacing="0" 
cellpadding="0" style=" width:100%">
+                <tr>
+                    <td>User Name:</td>
+                    <td><input type="text" name="userName" id="userName" 
/></td>
+                </tr>
+                <tr>
+                    <td>Password:</td>
+                    <td><input type="password" name="password" id="password" 
/></td>
+                </tr>
+                <tr>
+                    <td></td>
+                    <td>
+                        <input id="signin" type="button" class="button" 
value="Sign In" onclick="login();"/> <input type="button" class="button" 
value="Cancel" onclick="showHideCommon('popup-main'); showHideCommon('popup');" 
style="margin-left:10px;" />
+                    </td>
+                </tr>
 
-                 </table>
-               </form>
+            </table>
+        </form>
 
 
-     </div>
+    </div>
 </div>
 
 <!-- The login popup box -->
 
 <div class="header">
-<%
+    <%
         String path = (String) 
request.getSession().getAttribute(UIConstants.PATH_ATTR);
         String webPath = "/wso2registry/web";
         if (path != null) {
@@ -63,90 +65,90 @@
             isLogged = isLoggedObject.booleanValue();
         }
     %>
-               <table cellpadding="0" cellspacing="0" border="0" 
style="width:100%">
-                       <tr>
-                               <td valign="top" ><img 
src="/wso2registry/admin/images/logo.jpg" style="margin:0px padding:0px;"/></td>
-                               <td align="right" style="padding-top:5px;">
-
-                                       <table cellpadding="0" cellspacing="0" 
border="0" class="search-table">
-                                               <tr>
-                                                       <td>
-                                                               <a 
href="/wso2registry/system/search/advanced/new" 
class="advanced-search">Advanced Search <img 
src="/wso2registry/admin/images/icon-go.gif" border="0" /></a>
-                                                       </td>
-
-                                                       <form 
action="/wso2registry/system/search" method="get" style="display:inline;" 
name="searchForm">
-                                                       <td>
-                                                               <input 
type="text" name="criteria" class="input-text" />
-                                                       </td>
-                                                       <td valign="bottom">
-                                                               <a href="#" 
onclick="document.searchForm.submit();" title="Search"><img 
src="/wso2registry/admin/images/icon-search.gif" border="0" style="margin:0px 
padding:0px;"/></a><!-- input type="submit" class="button" value="Search" / -->
-                                                       </td>
-                                                       </form>
-                                               </tr>
-                                       </table>
-                                       </div>
-                                       <table cellpadding="0" cellspacing="0" 
border="0" class="top-menu-table">
-                                               <tr>
-                                                       <td>
-
-                                                       <%
-                                                               if 
(!userName.equals(RegistryConstants.ANONYMOUS_USER)) {%>
-                                                                       <span> 
<script language="javascript" 
type="text/javascript">doGreeting();</script></span> <%=userName%>!&nbsp;
-                                                               <% } %>
-                                                       </td>
-                                                       <td align="left" 
style="padding-right:0px;"><img src="/wso2registry/admin/images/menu-left.jpg" 
/></td>
-                                                       <td class="top-menu">
-                                                               <a 
href="<%=webPath%>">
-                                                               <img 
src="/wso2registry/admin/images/icon-registryResources.gif" border="0" 
align="top" /> Resources
-                                                               </a>
-                                                       </td>
-                                                       <td class="top-menu">
-                                                               <a 
href="/wso2registry/system/people">
-                                                               <img 
src="/wso2registry/admin/images/icon-people-small.gif" border="0" align="top" 
/> People
-                                                               </a>
-                                                       </td>
-                            <% if (isLogged) { %>
-                            <td class="top-menu">
-                                                               <a 
href="/wso2registry/system/activity/new">
-                                                               <img 
src="/wso2registry/admin/images/icon-recent-activity-small.gif" border="0" 
align="top"  /> Activity
-                                                               </a>
-                                                       </td>
-                            <% } %>
-                                                       <td class="top-menu">
-                                                               <a 
href="http://wso2.org/wiki/display/registry/User+guide"; target="_blank">
-                                                               <img 
src="/wso2registry/admin/images/help.gif" border="0" align="top"  /> Help
-                                                               </a>
-                                                       </td>
-                            <!--Add this after figuring out a better way to do 
the config-->
-                            <%--<% if (isLogged) { %>--%>
-                            <!--<td class="top-menu">-->
-                                                               <!--<a 
href="/wso2registry/system/admin">-->
-                                                               <!--<img 
src="/wso2registry/admin/images/icon-admin.gif" border="0" align="top"  /> 
Admin-->
-                                                               <!--</a>-->
-                            <!--</td>-->
-                            <%--<% } %>--%>
-                            <td class="top-menu">
-                                                               <%
-                                                               if 
(userName.equals(RegistryConstants.ANONYMOUS_USER)) {
-                                                               %>
-                                                                       <a 
href="#" onclick="showHideCommon('popup-main'); showHideCommon('popup');">
-                                                                       <img 
src="/wso2registry/admin/images/icon-logout.gif" border="0" align="top"  /> 
Sign in
-                                                                       </a>
-                                                               <% } else {  %>
-                                                                       <a 
href="/wso2registry/system/signout">
-                                                                       <img 
src="/wso2registry/admin/images/icon-logout.gif" border="0" align="top"  /> 
Sign out
-                                                                       </a>
-
-                                                               <% } %>
-
-                                                       </td>
-                                                       <td align="right" 
style="padding-right:0px;"><img src="/wso2registry/admin/images/menu-right.jpg" 
 /></td>
-                                               </tr>
-                                       </table>
-                               </td>
-                       </tr>
-               </table>
-       </div>
+    <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
+        <tr>
+            <td valign="top" ><img src="/wso2registry/admin/images/logo.jpg" 
style="margin:0px padding:0px;"/></td>
+            <td align="right" style="padding-top:5px;">
+
+            <table cellpadding="0" cellspacing="0" border="0" 
class="search-table">
+                <tr>
+                    <td>
+                        <a href="/wso2registry/system/search/advanced/new" 
class="advanced-search">Advanced Search <img 
src="/wso2registry/admin/images/icon-go.gif" border="0" /></a>
+                    </td>
+
+                    <form action="/wso2registry/system/search" method="get" 
style="display:inline;" name="searchForm">
+                        <td>
+                            <input type="text" name="criteria" 
class="input-text" />
+                        </td>
+                        <td valign="bottom">
+                            <a href="#" 
onclick="document.searchForm.submit();" title="Search"><img 
src="/wso2registry/admin/images/icon-search.gif" border="0" style="margin:0px 
padding:0px;"/></a><!-- input type="submit" class="button" value="Search" / -->
+                        </td>
+                    </form>
+                </tr>
+            </table>
+</div>
+<table cellpadding="0" cellspacing="0" border="0" class="top-menu-table">
+    <tr>
+        <td>
+
+            <%
+                if (!userName.equals(RegistryConstants.ANONYMOUS_USER)) {%>
+            <span> <script language="javascript" 
type="text/javascript">doGreeting();</script></span> <%=userName%>!&nbsp;
+            <% } %>
+        </td>
+        <td align="left" style="padding-right:0px;"><img 
src="/wso2registry/admin/images/menu-left.jpg" /></td>
+        <td class="top-menu">
+            <a href="<%=webPath%>">
+                <img 
src="/wso2registry/admin/images/icon-registryResources.gif" border="0" 
align="top" /> Resources
+            </a>
+        </td>
+        <td class="top-menu">
+            <a href="/wso2registry/system/people">
+                <img src="/wso2registry/admin/images/icon-people-small.gif" 
border="0" align="top" /> People
+            </a>
+        </td>
+        <% if (isLogged) { %>
+        <td class="top-menu">
+            <a href="/wso2registry/system/activity/new">
+                <img 
src="/wso2registry/admin/images/icon-recent-activity-small.gif" border="0" 
align="top"  /> Activity
+            </a>
+        </td>
+        <% } %>
+        <td class="top-menu">
+            <a href="http://wso2.org/wiki/display/registry/User+guide"; 
target="_blank">
+                <img src="/wso2registry/admin/images/help.gif" border="0" 
align="top"  /> Help
+            </a>
+        </td>
+        <!--Add this after figuring out a better way to do the config-->
+        <%--<% if (isLogged) { %>--%>
+        <!--<td class="top-menu">-->
+        <!--<a href="/wso2registry/system/admin">-->
+        <!--<img src="/wso2registry/admin/images/icon-admin.gif" border="0" 
align="top"  /> Admin-->
+        <!--</a>-->
+        <!--</td>-->
+        <%--<% } %>--%>
+        <td class="top-menu">
+            <%
+                if (userName.equals(RegistryConstants.ANONYMOUS_USER)) {
+            %>
+            <a href="#" onclick="showHideCommon('popup-main'); 
showHideCommon('popup');">
+                <img src="/wso2registry/admin/images/icon-logout.gif" 
border="0" align="top"  /> Sign in
+            </a>
+            <% } else {  %>
+            <a href="/wso2registry/system/signout">
+                <img src="/wso2registry/admin/images/icon-logout.gif" 
border="0" align="top"  /> Sign out
+            </a>
+
+            <% } %>
+
+        </td>
+        <td align="right" style="padding-right:0px;"><img 
src="/wso2registry/admin/images/menu-right.jpg"  /></td>
+    </tr>
+</table>
+</td>
+</tr>
+</table>
+</div>
 
 
 

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js   
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js   Thu Jan 
17 03:47:06 2008
@@ -237,10 +237,25 @@
     var userName = document.getElementById('userName').value;
     var password = document.getElementById('password').value;
 
-    new Ajax.request()
-    new Ajax.Updater('loginBox', '/wso2registry/system/signin', { method: 
'post', parameters: {userName: userName, password: password} });
+    new Ajax.Request('/wso2registry/system/signin',
+    {
+        method:'post',
+        parameters: {userName: userName, password: password},
+        onSuccess: function(transport){
+            var response = transport.responseText || "ERROR: Registry is not 
responding.";
+            if (response.indexOf("ERROR") == 0) {
+                document.getElementById('loginMessage').innerHTML = response;
+
+            } else {
+                window.location.reload(false);
+            }
+        },
+        onFailure: function(){}
+    });
 
-    document.refresh();
+    //new Ajax.Updater('loginBox', '/wso2registry/system/signin', { method: 
'post', parameters: {userName: userName, password: password} });
+    //
+    //document.refresh();
 }
 
 /* Ajax Rating Functions */

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to