continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r292582 - in /maven/continuum/trunk: continuum-api/src/main/java/org/apache/maven/continuum/store/ continuum-store/src/main/java/org/apache/maven/continuum/store/ continuum-web/src/main/java/org/apache/maven/continuum/web/action/ continuum-...
Date Thu, 29 Sep 2005 23:56:14 GMT
Author: evenisse
Date: Thu Sep 29 16:56:03 2005
New Revision: 292582

URL: http://svn.apache.org/viewcvs?rev=292582&view=rev
Log:
Fix login process and don't use a static login/password for user but data from database

Added:
    maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/model/
    maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/model/SessionUser.java
  (with props)
Modified:
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
    maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
    maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/Login.java
    maven/continuum/trunk/continuum-web/src/main/resources/META-INF/plexus/components.xml

Modified: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java?rev=292582&r1=292581&r2=292582&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
(original)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
Thu Sep 29 16:56:03 2005
@@ -25,6 +25,7 @@
 import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.SystemConfiguration;
+import org.apache.maven.continuum.model.system.User;
 
 import java.io.File;
 import java.util.Collection;
@@ -153,5 +154,10 @@
         throws ContinuumStoreException;
 
     SystemConfiguration getSystemConfiguration()
+        throws ContinuumStoreException;
+
+    User addUser( User user );
+
+    User getUserByUsername( String username )
         throws ContinuumStoreException;
 }

Modified: maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java?rev=292582&r1=292581&r2=292582&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
(original)
+++ maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
Thu Sep 29 16:56:03 2005
@@ -25,6 +25,7 @@
 import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.SystemConfiguration;
+import org.apache.maven.continuum.model.system.User;
 import org.apache.maven.continuum.project.ContinuumProjectState;
 import org.codehaus.plexus.jdo.JdoFactory;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
@@ -868,6 +869,53 @@
         else
         {
             return (SystemConfiguration) systemConfs.get( 0 );
+        }
+    }
+
+    public User addUser( User user )
+    {
+        return (User) addObject( user );
+    }
+
+    public User getUserByUsername( String username )
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( User.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareImports( "import java.lang.String" );
+
+            query.declareParameters( "String username" );
+
+            query.setFilter( "this.username == username" );
+
+            Collection result = (Collection) query.execute( username );
+
+            if ( result.size() == 0 )
+            {
+                tx.commit();
+
+                return null;
+            }
+
+            Object object = pm.detachCopy( result.iterator().next() );
+
+            tx.commit();
+
+            return (User) object;
+        }
+        finally
+        {
+            rollback( tx );
         }
     }
 }

Modified: maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/Login.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/Login.java?rev=292582&r1=292581&r2=292582&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/Login.java
(original)
+++ maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/Login.java
Thu Sep 29 16:56:03 2005
@@ -16,18 +16,27 @@
  * limitations under the License.
  */
 
-import org.codehaus.plexus.summit.rundata.RunData;
+import org.apache.maven.continuum.model.system.User;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.web.model.SessionUser;
+import org.codehaus.plexus.security.summit.SecureRunData;
 import org.codehaus.plexus.action.AbstractAction;
 
 import java.util.Map;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  * @version $Id$
  */
 public class Login
     extends AbstractAction
 {
+    /**
+     * @plexus.requirement
+     */
+    private ContinuumStore store;
+
     public void execute( Map map )
         throws Exception
     {
@@ -37,13 +46,23 @@
 
         String password = (String) map.get( "login.password" );
 
-        if ( login.equals( "admin" ) && password.equals( "admin" ) )
+        User user = store.getUserByUsername( login );
+
+        if ( user != null && user.equalsPassword( password ) )
         {
-            RunData data = (RunData) map.get( "data" );
+            SecureRunData secData = (SecureRunData) map.get( "data" );
+
+            SessionUser usr = new SessionUser( user.getUsername() );
 
-            data.getRequest().getSession().setAttribute( "loggedIn", "true" );
+            usr.setLoggedIn( true );
 
-            data.setTarget( "Index.vm" );
+            secData.setUser( usr );
+
+            secData.setTarget( "Index.vm" );
+        }
+        else
+        {
+            throw new Exception( "Your login/password is incorrect" );
         }
     }
 }

Added: maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/model/SessionUser.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/model/SessionUser.java?rev=292582&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/model/SessionUser.java
(added)
+++ maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/model/SessionUser.java
Thu Sep 29 16:56:03 2005
@@ -0,0 +1,90 @@
+package org.apache.maven.continuum.web.model;
+
+/*
+ * Copyright 2004-2005 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 org.codehaus.plexus.security.summit.User;
+import org.codehaus.plexus.security.summit.session.SessionBindingEvent;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @version $Id$
+ */
+public class SessionUser
+    implements User
+{
+    private String username;
+
+    private boolean loggedIn;
+
+    public SessionUser( String username )
+    {
+        this.username = username;
+    }
+
+    public String getUserName()
+    {
+        return username;
+    }
+
+    public boolean isLoggedIn()
+    {
+        return loggedIn;
+    }
+
+    public void setLoggedIn( boolean loggedIn )
+    {
+        this.loggedIn = loggedIn;
+    }
+
+    public void updateLastAccessDate()
+    {
+    }
+
+    public void incrementAccessCounter()
+    {
+    }
+
+    public void incrementAccessCounterForSession()
+    {
+    }
+
+    public void setTemp( String key, Object value )
+    {
+    }
+
+    public Object getTemp( String key )
+    {
+        return null;
+    }
+
+    public void setPerm( String key, Object value )
+    {
+    }
+
+    public Object getPerm( String key )
+    {
+        return null;
+    }
+
+    public void valueBound(SessionBindingEvent event)
+    {
+    }
+
+    public void valueUnbound(SessionBindingEvent event)
+    {
+    }
+}

Propchange: maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/model/SessionUser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/model/SessionUser.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/continuum/trunk/continuum-web/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-web/src/main/resources/META-INF/plexus/components.xml?rev=292582&r1=292581&r2=292582&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-web/src/main/resources/META-INF/plexus/components.xml
(original)
+++ maven/continuum/trunk/continuum-web/src/main/resources/META-INF/plexus/components.xml
Thu Sep 29 16:56:03 2005
@@ -38,6 +38,7 @@
         <!-- This indicates that we do not wanted pages cached on the client side -->
         <nocache>true</nocache>
         <valves>
+          <valve>org.apache.maven.continuum.web.pipeline.valve.InitializationCheckerValve</valve>
           <valve>org.apache.maven.continuum.web.pipeline.valve.LoginValve</valve>
           <!-- This is required because actions may need to put things in the context
-->
           <valve>org.apache.maven.continuum.web.pipeline.valve.ContinuumViewContextValve</valve>
@@ -353,6 +354,17 @@
 
     <component>
       <role>org.codehaus.plexus.summit.pipeline.valve.Valve</role>
+      <role-hint>org.apache.maven.continuum.web.pipeline.valve.InitializationCheckerValve</role-hint>
+      <implementation>org.apache.maven.continuum.web.pipeline.valve.InitializationCheckerValve</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.configuration.ConfigurationService</role>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.codehaus.plexus.summit.pipeline.valve.Valve</role>
       <role-hint>org.apache.maven.continuum.web.pipeline.valve.LoginValve</role-hint>
       <implementation>org.apache.maven.continuum.web.pipeline.valve.LoginValve</implementation>
       <requirements>
@@ -381,8 +393,27 @@
 
     <component>
       <role>org.codehaus.plexus.action.Action</role>
+      <role-hint>initializationChecker</role-hint>
+      <implementation>org.apache.maven.continuum.web.action.InitializationChecker</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.configuration.ConfigurationService</role>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.codehaus.plexus.action.Action</role>
       <role-hint>login</role-hint>
       <implementation>org.apache.maven.continuum.web.action.Login</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
     </component>
 
     <component>



Mime
View raw message