continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r420943 - in /maven/continuum/branches/continuum-acegi: continuum-core/src/main/java/org/apache/maven/continuum/initialization/ continuum-security/continuum-security-acegi/ continuum-security/continuum-security-acegi/src/main/java/org/apach...
Date Tue, 11 Jul 2006 18:30:26 GMT
Author: carlos
Date: Tue Jul 11 11:30:25 2006
New Revision: 420943

URL: http://svn.apache.org/viewvc?rev=420943&view=rev
Log:
[CONTINUUM-764] Finished acegi authentication against Continuum DB, added admin user

Added:
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsServiceTest.java
  (with props)
Modified:
    maven/continuum/branches/continuum-acegi/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsService.java
    maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/resources/plexus-application.xml
    maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/secure/debug.jsp

Modified: maven/continuum/branches/continuum-acegi/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java?rev=420943&r1=420942&r2=420943&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
Tue Jul 11 11:30:25 2006
@@ -162,6 +162,10 @@
         createPermission( "manageSchedule", "Manage Schedules" );
 
         createPermission( "manageUsers", "Manage Users/Groups" );
+
+        createPermission( "ROLE_USER", "Authenticated User" );
+
+        createPermission( "ROLE_ADMIN", "Administrator" );
     }
 
     private Permission createPermission( String name, String description )

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml?rev=420943&r1=420942&r2=420943&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml
Tue Jul 11 11:30:25 2006
@@ -25,5 +25,9 @@
       <groupId>org.apache.maven.continuum</groupId>
       <artifactId>continuum-model</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.continuum</groupId>
+      <artifactId>continuum-store</artifactId>
+    </dependency>
   </dependencies>
 </project>

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsService.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsService.java?rev=420943&r1=420942&r2=420943&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsService.java
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsService.java
Tue Jul 11 11:30:25 2006
@@ -52,13 +52,28 @@
     {
     }
 
+    public void setStore( ContinuumStore store )
+    {
+        this.store = store;
+    }
+
+    /**
+     * {@link ContinuumStore} to load the user from.
+     * 
+     * @return the store
+     */
+    public ContinuumStore getStore()
+    {
+        return store;
+    }
+
     public UserDetails loadUserByUsername( String username )
         throws UsernameNotFoundException, DataAccessException
     {
         ContinuumUser user;
         try
         {
-            user = store.getUserByUsername( username );
+            user = getStore().getUserByUsername( username );
         }
         catch ( ContinuumStoreException e )
         {
@@ -77,7 +92,7 @@
      * @param user the continuum user loaded from DB
      * @return the Acegi user
      */
-    private UserDetails getUserDetails( ContinuumUser user )
+    UserDetails getUserDetails( ContinuumUser user )
     {
         List permissions = user.getGroup().getPermissions();
 
@@ -90,19 +105,20 @@
             grantedAuthorities[i] = new GrantedAuthorityImpl( permission.getName() );
             i++;
         }
+        String username = user.getUsername();
+        String password = user.getHashedPassword();
         boolean enabled = true;
         boolean accountNonExpired = true;
         boolean credentialsNonExpired = true;
         boolean accountNonLocked = true;
 
-        UserDetails userDetails = new User( user.getUsername(), user.getPassword(), enabled,
accountNonExpired,
-                                            credentialsNonExpired, accountNonLocked, grantedAuthorities
);
+        UserDetails userDetails = new User( username, password, enabled, accountNonExpired,
credentialsNonExpired,
+                                            accountNonLocked, grantedAuthorities );
 
         return userDetails;
     }
 
     /**
-    *TODO: clean up ContinuumAuthenticator
-    *TODO: convert Acegi user into Continuum user?
-    */
+     * TODO: convert Acegi user into Continuum user?
+     */
 }

Added: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsServiceTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsServiceTest.java?rev=420943&view=auto
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsServiceTest.java
(added)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsServiceTest.java
Tue Jul 11 11:30:25 2006
@@ -0,0 +1,84 @@
+package org.apache.maven.continuum.security.acegi;
+
+/*
+ * Copyright 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 org.acegisecurity.providers.encoding.ShaPasswordEncoder;
+import org.acegisecurity.userdetails.UserDetails;
+import org.apache.maven.continuum.model.system.ContinuumUser;
+import org.apache.maven.continuum.model.system.Permission;
+import org.apache.maven.continuum.model.system.UserGroup;
+
+import junit.framework.TestCase;
+
+/**
+ * Test for {@link ContinuumUserDetailsService}
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class ContinuumUserDetailsServiceTest
+    extends TestCase
+{
+
+    private ContinuumUserDetailsService userDetailsService;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+    }
+
+    public void testGetUserDetails()
+    {
+        Permission p1 = new Permission();
+        p1.setName( "p1" );
+        Permission p2 = new Permission();
+        p2.setName( "p2" );
+        Permission p3 = new Permission();
+        p3.setName( "p3" );
+        
+        UserGroup group = new UserGroup();
+        group.addPermission( p1 );
+        group.addPermission( p2 );
+        group.addPermission( p3 );
+        
+        ContinuumUser continuumUser = new ContinuumUser();
+        continuumUser.setUsername( "username" );
+        continuumUser.setPassword( "password" );
+        continuumUser.setGroup( group );
+        
+        ShaPasswordEncoder passwordEncoder = new ShaPasswordEncoder();
+        String shaPassword = passwordEncoder.encodePassword( "password", null );
+        
+        UserDetails userDetails = userDetailsService.getUserDetails( continuumUser );
+        
+        assertEquals( userDetails.getUsername(), continuumUser.getUsername() );
+        assertEquals( userDetails.getPassword(), shaPassword );
+        assertEquals( userDetails.getAuthorities(), continuumUser.getUsername() );
+    }
+
+    public void testPasswordEncoding()
+    {
+        ContinuumUser continuumUser = new ContinuumUser();
+        continuumUser.setPassword( "admin" );
+        
+        ShaPasswordEncoder passwordEncoder = new ShaPasswordEncoder();
+        String shaPassword = passwordEncoder.encodePassword( "admin", null );
+        
+        assertEquals( continuumUser.getHashedPassword(), shaPassword );
+    }
+}

Propchange: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/ContinuumUserDetailsServiceTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/resources/plexus-application.xml
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/resources/plexus-application.xml?rev=420943&r1=420942&r2=420943&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/resources/plexus-application.xml
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/resources/plexus-application.xml
Tue Jul 11 11:30:25 2006
@@ -338,7 +338,7 @@
     <!-- Bridge between Acegi and Continuum database -->
     <component>
       <role>org.acegisecurity.userdetails.UserDetailsService</role>
-      <implementation>org.apache.maven.continuum.security.ContinuumAuthenticator</implementation>
+      <implementation>org.apache.maven.continuum.security.acegi.ContinuumUserDetailsService</implementation>
       <requirements>
         <requirement>
           <role>org.apache.maven.continuum.store.ContinuumStore</role>
@@ -355,6 +355,9 @@
           <field-name>userDetailsService</field-name>
         </requirement>
       </requirements>
+      <configuration>
+        <passwordEncoder implementation="org.acegisecurity.providers.encoding.ShaPasswordEncoder"/>
+      </configuration>
     </component>
 
     <component>

Modified: maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/secure/debug.jsp
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/secure/debug.jsp?rev=420943&r1=420942&r2=420943&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/secure/debug.jsp
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/secure/debug.jsp
Tue Jul 11 11:30:25 2006
@@ -32,5 +32,13 @@
 
 <%-- other way to access the info using taglibs --%>
 
-  <c:set var="authentication" value="${sessionScope['ACEGI_SECURITY_AUTHENTICATION']}"/>
-  user: ${authentication.principal}
+  <c:set var="authentication" value="${sessionScope['ACEGI_SECURITY_CONTEXT'].authentication}"/>
+  <c:set var="user" value="${authentication.principal}"/>
+
+  user: <c:out value="${user.username}"/><br/>
+  Roles: 
+    <ul>
+      <c:forEach var="item" items="${user.authorities}">
+        <li><c:out value="${item.authority}"/></li>
+      </c:forEach>
+    </ul>



Mime
View raw message