Author: carlos
Date: Sat Sep  2 20:01:24 2006
New Revision: 439712

URL: http://svn.apache.org/viewvc?rev=439712&view=rev
Log:
Added changePassword actions
Submitted By: Nap Ramirez

Added:
    maven/shared/trunk/maven-user/maven-user-controller/src/test/java/
    maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/controller/
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/controller/action/
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/controller/action/ChangeUserPasswordActionTest.java
   (with props)
    maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/META-INF/
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/META-INF/plexus/
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/META-INF/plexus/components.xml
   (with props)
    
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/log4j.properties
   (with props)
Modified:
    
maven/shared/trunk/maven-user/maven-user-controller/src/main/java/org/apache/maven/user/controller/action/ChangeUserPasswordAction.java
    
maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/localization/MavenUser.properties
    
maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/org/apache/maven/user/webapp/xwork.xml
    
maven/shared/trunk/maven-user/maven-user-webapp/src/main/webapp/user/changePassword.jsp

Modified: 
maven/shared/trunk/maven-user/maven-user-controller/src/main/java/org/apache/maven/user/controller/action/ChangeUserPasswordAction.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-user/maven-user-controller/src/main/java/org/apache/maven/user/controller/action/ChangeUserPasswordAction.java?rev=439712&r1=439711&r2=439712&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-user/maven-user-controller/src/main/java/org/apache/maven/user/controller/action/ChangeUserPasswordAction.java
 (original)
+++ 
maven/shared/trunk/maven-user/maven-user-controller/src/main/java/org/apache/maven/user/controller/action/ChangeUserPasswordAction.java
 Sat Sep  2 20:01:24 2006
@@ -18,7 +18,9 @@
 
 import javax.naming.OperationNotSupportedException;
 
+import org.apache.maven.user.model.User;
 import org.apache.maven.user.model.UserManager;
+import org.apache.maven.user.model.UserSecurityPolicy;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
 
 /**
@@ -37,6 +39,11 @@
      * @plexus.requirement
      */
     private UserManager userManager;
+    
+    /**
+     * @plexus.requirement
+     */
+    private UserSecurityPolicy securityPolicy;
 
     private int accountId;
 
@@ -49,12 +56,36 @@
     public String execute()
         throws Exception
     {
-        // TODO validate that newPassword and confirmPassword are the same
-        // TODO check currentPassword is old password
-        // TODO calls userManager.updateUser( user );
+        // validate that newPassword and confirmPassword are the same
+        if ( !newPassword.equals( confirmPassword ) )
+        {
+            addActionError( "user.password.mismatch.error" );
+        }
+        
+        // TODO check currentPassword is old password should be done in 
UserManager
+        User user = userManager.getUser( accountId );
+        String encodedCurrentPassword = 
securityPolicy.getPasswordEncoder().encodePassword( currentPassword );
+        if ( !user.getEncodedPassword().equals( encodedCurrentPassword ) )
+        {
+            addActionError( "user.invalid.current.password.error" );
+        }
+        
+        if ( getActionErrors().size() > 0 )
+        {
+            return INPUT;
+        }
 
-        // not implemented yet
-        throw new OperationNotSupportedException( "changePassword is not yet 
implemented" );
+        // calls userManager.updateUser( user );
+        user.setPassword( newPassword );
+        userManager.updateUser( user );
+        
+        return SUCCESS;
+    }
+    
+    public String doChange()
+        throws Exception
+    {
+        return INPUT;
     }
 
     public void setCurrentPassword( String currentPassword )

Modified: 
maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/localization/MavenUser.properties
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/localization/MavenUser.properties?rev=439712&r1=439711&r2=439712&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/localization/MavenUser.properties
 (original)
+++ 
maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/localization/MavenUser.properties
 Sat Sep  2 20:01:24 2006
@@ -38,3 +38,14 @@
 role.page.title = Continuum - Roles List
 role.section.title = Roles List
 role.rolename = Roles
+
+// ----------------------------------------------------------------------
+// Page: Change User Password
+// ----------------------------------------------------------------------
+user.change.password.page.title = Continuum - Change User Password
+user.change.password.section.title = Change User Password
+user.current.password = Current Password
+user.new.password = New Password
+user.confirm.password = Confirm Password
+user.invalid.current.password.error = Invalid current password
+user.password.mismatch.error = Password mismatch

Modified: 
maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/org/apache/maven/user/webapp/xwork.xml
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/org/apache/maven/user/webapp/xwork.xml?rev=439712&r1=439711&r2=439712&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/org/apache/maven/user/webapp/xwork.xml
 (original)
+++ 
maven/shared/trunk/maven-user/maven-user-controller/src/main/resources/org/apache/maven/user/webapp/xwork.xml
 Sat Sep  2 20:01:24 2006
@@ -18,11 +18,10 @@
       <result name="success">/user/list.jsp</result>
     </action>
 
-<!--
     <action name="changeUserPassword" class="changeUserPassword">
+      <result name="input">/user/changePassword.jsp</result>
       <result name="success">/user/changePassword.jsp</result>
     </action>
--->
 
   </package>
 </xwork>

Added: 
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/controller/action/ChangeUserPasswordActionTest.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/controller/action/ChangeUserPasswordActionTest.java?rev=439712&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/controller/action/ChangeUserPasswordActionTest.java
 (added)
+++ 
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/controller/action/ChangeUserPasswordActionTest.java
 Sat Sep  2 20:01:24 2006
@@ -0,0 +1,189 @@
+package org.apache.maven.user.controller.action;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.maven.user.model.User;
+import org.apache.maven.user.model.UserManager;
+import org.apache.maven.user.model.impl.DefaultUserManager;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.jdo.ConfigurableJdoFactory;
+import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
+import org.codehaus.plexus.jdo.JdoFactory;
+import org.jpox.SchemaTool;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Napoleon Esmundo C. Ramirez</a>
+ */
+public class ChangeUserPasswordActionTest
+    extends PlexusTestCase
+{
+    
+    private DefaultUserManager userManager = null;
+    
+    private User user = null;
+    
+    private ChangeUserPasswordAction action = null;
+    
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        ConfigurableJdoFactory jdoFactory = (ConfigurableJdoFactory) lookup( 
JdoFactory.ROLE );
+        assertEquals( DefaultConfigurableJdoFactory.class.getName(), 
jdoFactory.getClass().getName() );
+
+        jdoFactory.setPersistenceManagerFactoryClass( 
"org.jpox.PersistenceManagerFactoryImpl" ); //$NON-NLS-1$
+
+        jdoFactory.setDriverName( "org.hsqldb.jdbcDriver" ); //$NON-NLS-1$
+
+        jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() ); //$NON-NLS-1$
+
+        jdoFactory.setUserName( "sa" ); //$NON-NLS-1$
+
+        jdoFactory.setPassword( "" ); //$NON-NLS-1$
+
+        jdoFactory.setProperty( "org.jpox.transactionIsolation", 
"READ_UNCOMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", 
"READ_UNCOMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" ); 
//$NON-NLS-1$ //$NON-NLS-2$
+
+        Properties properties = jdoFactory.getProperties();
+
+        for ( Iterator it = properties.entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+
+            System.setProperty( (String) entry.getKey(), (String) 
entry.getValue() );
+        }
+
+        SchemaTool.createSchemaTables( new URL[] { getClass().getResource( 
"/org/apache/maven/user/model/package.jdo" ) }, null, false ); //$NON-NLS-1$
+
+        PersistenceManagerFactory pmf = 
jdoFactory.getPersistenceManagerFactory();
+
+        assertNotNull( pmf );
+
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        pm.close();
+
+        userManager = (DefaultUserManager) lookup( UserManager.ROLE );
+        
+        user = new User();
+        user.setUsername( "nramirez" );
+        user.setPassword( "abc123" );
+        user.setEmail( "[EMAIL PROTECTED]" );
+        user = userManager.addUser( user );
+        
+        action = (ChangeUserPasswordAction) lookup( 
"com.opensymphony.xwork.Action", "changeUserPassword" );
+    }
+    
+    public void testInvalidCurrentPasswordFail()
+        throws Exception
+    {
+        action.setAccountId( user.getAccountId() );
+        action.setCurrentPassword( "123abc" );
+        action.setNewPassword( "" );
+        action.setConfirmPassword( "" );
+        
+        action.execute();
+        
+        assertEquals( action.getActionErrors().size(), 1 );
+        assertTrue( action.getActionErrors().contains( 
"user.invalid.current.password.error" ) );
+    }
+    
+    public void testInvalidCurrentPasswordSuccess()
+        throws Exception
+    {
+        action.setAccountId( user.getAccountId() );
+        action.setCurrentPassword( "abc123" );
+        action.setNewPassword( "" );
+        action.setConfirmPassword( "" );
+        
+        action.execute();
+        
+        assertEquals( action.getActionErrors().size(), 0 );
+        assertFalse( action.getActionErrors().contains( 
"user.invalid.current.password.error" ) );
+    }
+    
+    public void testPasswordMismatchFail()
+        throws Exception
+    {
+        action.setAccountId( user.getAccountId() );
+        action.setCurrentPassword( "abc123" );
+        action.setNewPassword( "welcome!" );
+        action.setConfirmPassword( "!welcome" );
+        
+        action.execute();
+        
+        assertEquals( action.getActionErrors().size(), 1 );
+        assertTrue( action.getActionErrors().contains( 
"user.password.mismatch.error" ) );
+    }
+    
+    public void testPasswordMismatchSuccess()
+        throws Exception
+    {
+        action.setAccountId( user.getAccountId() );
+        action.setCurrentPassword( "abc123" );
+        action.setNewPassword( "welcome!" );
+        action.setConfirmPassword( "welcome!" );
+        
+        action.execute();
+        
+        assertEquals( action.getActionErrors().size(), 0 );
+        assertFalse( action.getActionErrors().contains( 
"user.password.mismatch.error" ) );
+    }
+    
+    public void testInvalidCurrentPasswordAndPasswordMismatchFail()
+        throws Exception
+    {
+        action.setAccountId( user.getAccountId() );
+        action.setCurrentPassword( "123abc" );
+        action.setNewPassword( "welcome!" );
+        action.setConfirmPassword( "!welcome" );
+        
+        action.execute();
+        
+        assertEquals( action.getActionErrors().size(), 2 );
+        assertTrue( action.getActionErrors().contains( 
"user.invalid.current.password.error" ) );
+        assertTrue( action.getActionErrors().contains( 
"user.password.mismatch.error" ) );
+    }
+    
+    public void testInvalidCurrentPasswordAndPasswordMismatchSuccess()
+        throws Exception
+    {
+        action.setAccountId( user.getAccountId() );
+        action.setCurrentPassword( "abc123" );
+        action.setNewPassword( "welcome!" );
+        action.setConfirmPassword( "welcome!" );
+        
+        action.execute();
+        
+        assertEquals( action.getActionErrors().size(), 0 );
+        assertFalse( action.getActionErrors().contains( 
"user.invalid.current.password.error" ) );
+        assertFalse( action.getActionErrors().contains( 
"user.password.mismatch.error" ) );
+    }
+}

Propchange: 
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/controller/action/ChangeUserPasswordActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/maven-user/maven-user-controller/src/test/java/org/apache/maven/user/controller/action/ChangeUserPasswordActionTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/META-INF/plexus/components.xml
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/META-INF/plexus/components.xml?rev=439712&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/META-INF/plexus/components.xml
 (added)
+++ 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/META-INF/plexus/components.xml
 Sat Sep  2 20:01:24 2006
@@ -0,0 +1,8 @@
+<component-set>
+  <components>
+    <component>
+      <role>org.codehaus.plexus.jdo.JdoFactory</role>
+      
<implementation>org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory</implementation>
+    </component>
+  </components>
+</component-set>

Propchange: 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/log4j.properties?rev=439712&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/log4j.properties
 (added)
+++ 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/log4j.properties
 Sat Sep  2 20:01:24 2006
@@ -0,0 +1,10 @@
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=WARN, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
+

Propchange: 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/maven-user/maven-user-controller/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
maven/shared/trunk/maven-user/maven-user-webapp/src/main/webapp/user/changePassword.jsp
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-user/maven-user-webapp/src/main/webapp/user/changePassword.jsp?rev=439712&r1=439711&r2=439712&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-user/maven-user-webapp/src/main/webapp/user/changePassword.jsp
 (original)
+++ 
maven/shared/trunk/maven-user/maven-user-webapp/src/main/webapp/user/changePassword.jsp
 Sat Sep  2 20:01:24 2006
@@ -1,3 +1,5 @@
+<%@ taglib uri="/webwork" prefix="ww" %>
+<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
 <html>
   <ww:i18n name="localization.MavenUser">
     <head>
@@ -8,6 +10,13 @@
         <h3><ww:text name="user.change.password.section.title"/></h3>
         <div class="axial">
           <ww:form action="changeUserPassword.action" method="post">
+            <c:if test="${!empty actionErrors}">
+              <div class="errormessage">
+                <c:forEach items="${actionErrors}" var="actionError">
+                  <p><ww:text name="${actionError}"/></p>
+                </c:forEach>
+              </div>
+            </c:if>
             <table>
               <tbody>
                 <ww:hidden id="accountId_field" name="accountId"/>


Reply via email to