roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r657369 - in /roller/trunk/apps/weblogger: src/java/org/apache/roller/weblogger/ui/struts2/core/Register-validation.xml src/java/org/apache/roller/weblogger/ui/struts2/core/Register.java web/WEB-INF/jsps/core/Register.jsp
Date Sat, 17 May 2008 14:48:34 GMT
Author: snoopdave
Date: Sat May 17 07:48:34 2008
New Revision: 657369

URL: http://svn.apache.org/viewvc?rev=657369&view=rev
Log:
Related to Externalize User Management implementation:
https://issues.apache.org/roller/browse/ROL-1534

Fixes to allow "auto-registration" logic to work in a CMA setup where only user info comes
from request.getUserPrincipal() and Acegi not available.

Removed:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/core/Register-validation.xml
Modified:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/core/Register.java
    roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/Register.jsp

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/core/Register.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/core/Register.java?rev=657369&r1=657368&r2=657369&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/core/Register.java
(original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/core/Register.java
Sat May 17 07:48:34 2008
@@ -77,7 +77,7 @@
     @SkipValidation
     public String execute() {
         
-        if(!WebloggerRuntimeConfig.getBooleanProperty("users.registration.enabled")) {
+        if (!WebloggerRuntimeConfig.getBooleanProperty("users.registration.enabled")) {
             return "disabled";
         }
         
@@ -86,15 +86,22 @@
         getBean().setTimeZone(TimeZone.getDefault().getID());
             
         try {
-            // Let's see if there's any user-authentication available from Acegi
-            // and retrieve custom user data to pre-populate form.
+
             boolean usingSSO = WebloggerConfig.getBooleanProperty("users.sso.enabled");
-            if(usingSSO) {
+            if (usingSSO) {
+                // See if user is already logged in via Acegi
                 User fromSSO = CustomUserRegistry.getUserDetailsFromAuthentication(getServletRequest());
-
-                if(fromSSO != null) {
+                if (fromSSO != null) {
+                    // Copy user details from Acegi, including LDAP attributes
                     getBean().copyFrom(fromSSO);
-                    setFromSS0(true);
+                    setFromSso(true);
+                }
+                // See if user is already logged in via CMA
+                else if (getServletRequest().getUserPrincipal() != null) {
+                    // Only detail we get is username, sadly no LDAP attributes
+                    getBean().setUserName(getServletRequest().getUserPrincipal().getName());
+                    getBean().setScreenName(getServletRequest().getUserPrincipal().getName());
+                    setFromSso(true);
                 }
             }
             
@@ -243,26 +250,35 @@
     public void myValidate() {
         
         // if usingSSO, we don't want to error on empty password/username from HTML form.
-        setFromSS0(false);
+        setFromSso(false);
         boolean usingSSO = WebloggerConfig.getBooleanProperty("users.sso.enabled");
-        if(usingSSO) {
+        if (usingSSO) {
             boolean storePassword = WebloggerConfig.getBooleanProperty("users.sso.passwords.saveInRollerDb");
+            String password = WebloggerConfig.getProperty("users.sso.passwords.defaultValue",
"<unknown>");
+            
+            // Preserve username and password, Acegi case             
             User fromSSO = CustomUserRegistry.getUserDetailsFromAuthentication(getServletRequest());
-
-            if(fromSSO != null) {
-                String password = WebloggerConfig.getProperty("users.sso.passwords.defaultValue",
"<unknown>");
-                if(storePassword) {
+            if (fromSSO != null) {
+                if (storePassword) {
                     password = fromSSO.getPassword();
                 }
                 getBean().setPasswordText(password);
                 getBean().setPasswordConfirm(password);
                 getBean().setUserName(fromSSO.getUserName());
-                setFromSS0(true);
+                setFromSso(true);
+            }
+
+            // Preserve username and password, CMA case             
+            else if (getServletRequest().getUserPrincipal() != null) {
+                getBean().setUserName(getServletRequest().getUserPrincipal().getName());
+                getBean().setPasswordText(password);
+                getBean().setPasswordConfirm(password);
+                setFromSso(true);
             }
         }
         
         String allowed = WebloggerConfig.getProperty("username.allowedChars");
-        if(allowed == null || allowed.trim().length() == 0) {
+        if (allowed == null || allowed.trim().length() == 0) {
             allowed = DEFAULT_ALLOWED_CHARS;
         }
         
@@ -273,12 +289,12 @@
         }
         
         // check that passwords match
-        if(!getBean().getPasswordText().equals(getBean().getPasswordConfirm())) {
+        if (!getBean().getPasswordText().equals(getBean().getPasswordConfirm())) {
             addError("Register.error.passowordMismatch");
         }
         
         // check that username is not taken
-        if(!StringUtils.isEmpty(getBean().getUserName())) try {
+        if (!StringUtils.isEmpty(getBean().getUserName())) try {
             UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
             if(mgr.getUserByUserName(getBean().getUserName(), null) != null) {
                 addError("error.add.user.userNameInUse");
@@ -309,11 +325,11 @@
         this.bean = bean;
     }
 
-    public boolean isFromSS0() {
+    public boolean getFromSso() {
         return fromSS0;
     }
 
-    public void setFromSS0(boolean fromSS0) {
+    public void setFromSso(boolean fromSS0) {
         this.fromSS0 = fromSS0;
     }
 

Modified: roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/Register.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/Register.jsp?rev=657369&r1=657368&r2=657369&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/Register.jsp (original)
+++ roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/Register.jsp Sat May 17 07:48:34 2008
@@ -25,34 +25,34 @@
 
 <table class="formtable">
 
-    <s:if test="fromSSO">
-<tr>
-    <td class="label"><label for="userName" /><s:text name="userSettings.username"
/></label></td>
-    <td class="field"><strong><s:property value="bean.userName" /></strong></td>
-    <td class="description"><s:text name="userRegister.tip.userName" /></td>
-</tr>
+<s:if test="fromSso">
+    <tr>
+        <td class="label"><label for="userName" /><s:text name="userSettings.username"
/></label></td>
+        <td class="field"><strong><s:property value="bean.userName" /></strong></td>
+        <td class="description"><s:text name="userRegister.tip.userName" /></td>
+    </tr>
 </s:if>
 <s:else>
-<tr>
-    <td class="label"><label for="userName" /><s:text name="userSettings.username"
/></label></td>
-    <td class="field"><s:textfield name="bean.userName" size="30" maxlength="30"
/></td>
-    <td class="description"><s:text name="userRegister.tip.userName" /></td>
-</tr>
-
-<tr>
-    <td class="label"><label for="passwordText" /><s:text name="userSettings.password"
/></label></td>
-    <td class="field">
-       <s:password name="bean.passwordText" size="20" maxlength="20" />
-       <s:hidden name="bean.password" />
-   </td>
-    <td class="description"><s:text name="userRegister.tip.password" /></td>
-</tr>
-
-<tr>
-    <td class="label"><label for="passwordConfirm" /><s:text name="userSettings.passwordConfirm"
/></label></td>
-    <td class="field"><s:password name="bean.passwordConfirm" size="20" maxlength="20"
/></td>
-    <td class="description"><s:text name="userRegister.tip.passwordConfirm" /></td>
-</tr>
+    <tr>
+        <td class="label"><label for="userName" /><s:text name="userSettings.username"
/></label></td>
+        <td class="field"><s:textfield name="bean.userName" size="30" maxlength="30"
/></td>
+        <td class="description"><s:text name="userRegister.tip.userName" /></td>
+    </tr>
+
+    <tr>
+        <td class="label"><label for="passwordText" /><s:text name="userSettings.password"
/></label></td>
+        <td class="field">
+           <s:password name="bean.passwordText" size="20" maxlength="20" />
+           <s:hidden name="bean.password" />
+       </td>
+        <td class="description"><s:text name="userRegister.tip.password" /></td>
+    </tr>
+
+    <tr>
+        <td class="label"><label for="passwordConfirm" /><s:text name="userSettings.passwordConfirm"
/></label></td>
+        <td class="field"><s:password name="bean.passwordConfirm" size="20" maxlength="20"
/></td>
+        <td class="description"><s:text name="userRegister.tip.passwordConfirm"
/></td>
+    </tr>
 </s:else>
 
 <tr>



Mime
View raw message