continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r293446 - in /maven/continuum/trunk: continuum-api/src/main/java/org/apache/maven/continuum/ continuum-api/src/main/java/org/apache/maven/continuum/security/ continuum-api/src/main/java/org/apache/maven/continuum/store/ continuum-core/src/m...
Date Mon, 03 Oct 2005 20:38:09 GMT
Author: evenisse
Date: Mon Oct  3 13:37:46 2005
New Revision: 293446

URL: http://svn.apache.org/viewcvs?rev=293446&view=rev
Log:
[CONTINUUM-275] implement user/permissions in store
Rename User in continuum model to ContinuumUser due to an sql error with derby when continuum
insert new user (ERROR 42X01: Syntax error:...)

Added:
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurity.java
  (with props)
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurityException.java
  (with props)
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/security/
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/security/DefaultContinuumSecurity.java
  (with props)
Modified:
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
    maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml
    maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo
    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/InitializationChecker.java
    maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/Login.java

Modified: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java?rev=293446&r1=293445&r2=293446&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
(original)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
Mon Oct  3 13:37:46 2005
@@ -22,6 +22,7 @@
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectNotifier;
 import org.apache.maven.continuum.model.project.Schedule;
+import org.apache.maven.continuum.security.ContinuumSecurity;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
 import org.codehaus.plexus.util.dag.CycleDetectedException;
 
@@ -206,4 +207,10 @@
 
     void reloadConfiguration()
         throws ContinuumException;
+
+    // ----------------------------------------------------------------------
+    // Security
+    // ----------------------------------------------------------------------
+
+    ContinuumSecurity getSecurity();
 }

Added: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurity.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurity.java?rev=293446&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurity.java
(added)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurity.java
Mon Oct  3 13:37:46 2005
@@ -0,0 +1,47 @@
+package org.apache.maven.continuum.security;
+
+/*
+ * 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.apache.maven.continuum.model.system.ContinuumUser;
+import org.apache.maven.continuum.model.system.Permission;
+import org.apache.maven.continuum.model.system.UserGroup;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public interface ContinuumSecurity
+{
+    String ROLE = ContinuumSecurity.class.getName();
+
+    static final String ADMIN_GROUP_NAME = "Continuum admin";
+
+    static final String GUEST_GROUP_NAME = "Continuum guest";
+    
+    List getPermissions( ContinuumUser user )
+        throws ContinuumSecurityException;
+
+    List getPermissions( UserGroup group );
+
+    boolean isAuthorized( ContinuumUser user, String action )
+        throws ContinuumSecurityException;
+
+    ContinuumUser getGuestUser()
+        throws ContinuumSecurityException;
+}

Propchange: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurity.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurityException.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurityException.java?rev=293446&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurityException.java
(added)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurityException.java
Mon Oct  3 13:37:46 2005
@@ -0,0 +1,34 @@
+package org.apache.maven.continuum.security;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class ContinuumSecurityException extends Exception
+{
+    public ContinuumSecurityException( String msg )
+    {
+        super( msg );
+    }
+
+    public ContinuumSecurityException( String msg, Exception ex )
+    {
+        super( msg, ex );
+    }
+}

Propchange: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurityException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/security/ContinuumSecurityException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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=293446&r1=293445&r2=293446&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
Mon Oct  3 13:37:46 2005
@@ -24,8 +24,10 @@
 import org.apache.maven.continuum.model.project.ProjectNotifier;
 import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.model.system.Installation;
+import org.apache.maven.continuum.model.system.ContinuumUser;
 import org.apache.maven.continuum.model.system.SystemConfiguration;
-import org.apache.maven.continuum.model.system.User;
+import org.apache.maven.continuum.model.system.Permission;
+import org.apache.maven.continuum.model.system.UserGroup;
 
 import java.io.File;
 import java.util.Collection;
@@ -156,8 +158,26 @@
     SystemConfiguration getSystemConfiguration()
         throws ContinuumStoreException;
 
-    User addUser( User user );
+    ContinuumUser addUser( ContinuumUser user );
 
-    User getUserByUsername( String username )
+    ContinuumUser getGuestUser()
         throws ContinuumStoreException;
+
+    ContinuumUser getUserByUsername( String username )
+        throws ContinuumStoreException;
+
+    List getPermissions()
+        throws ContinuumStoreException;
+
+    Permission getPermission( String name )
+        throws ContinuumStoreException;
+
+    Permission addPermission( Permission perm );
+
+    UserGroup addUserGroup( UserGroup group);
+
+    void updateUserGroup( UserGroup group )
+        throws ContinuumStoreException;
+
+    UserGroup getUserGroup( String name );
 }

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=293446&r1=293445&r2=293446&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
Mon Oct  3 13:37:46 2005
@@ -39,6 +39,7 @@
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
 import org.apache.maven.continuum.project.builder.maven.MavenOneContinuumProjectBuilder;
 import org.apache.maven.continuum.project.builder.maven.MavenTwoContinuumProjectBuilder;
+import org.apache.maven.continuum.security.ContinuumSecurity;
 import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
 import org.apache.maven.continuum.store.ContinuumStore;
 import org.apache.maven.continuum.store.ContinuumStoreException;
@@ -105,6 +106,11 @@
      */
     private SchedulesActivator schedulesActivator;
 
+    /**
+     * @plexus.requirement
+     */
+    private ContinuumSecurity security;
+
     // ----------------------------------------------------------------------
     // Moved from core
     // ----------------------------------------------------------------------
@@ -1056,6 +1062,15 @@
         {
             throw new ContinuumException( "Can't reload configuration.", e );
         }
+    }
+
+    // ----------------------------------------------------------------------
+    // Security
+    // ----------------------------------------------------------------------
+
+    public ContinuumSecurity getSecurity()
+    {
+        return security;
     }
 
     // ----------------------------------------------------------------------

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java?rev=293446&r1=293445&r2=293446&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
Mon Oct  3 13:37:46 2005
@@ -17,14 +17,21 @@
  */
 
 import org.apache.maven.continuum.model.project.Schedule;
+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 org.apache.maven.continuum.model.system.SystemConfiguration;
+import org.apache.maven.continuum.security.ContinuumSecurity;
 import org.apache.maven.continuum.store.ContinuumStore;
 import org.apache.maven.continuum.store.ContinuumStoreException;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
- * @version $Id:$
+ * @version $Id$
  * @todo use this, reintroduce default project group
  */
 public class DefaultContinuumInitializer
@@ -101,6 +108,13 @@
 
                 defaultSchedule = store.addSchedule( defaultSchedule );
             }
+
+            // Permission
+            createPermissions();
+
+            createGroups();
+
+            createGuestUser();
         }
         catch ( ContinuumStoreException e )
         {
@@ -126,5 +140,123 @@
         schedule.setActive( true );
 
         return schedule;
+    }
+
+    private void createPermissions()
+        throws ContinuumStoreException
+    {
+        createPermission( "addProject", "Add Projects" );
+
+        createPermission( "editProject", "Edit Projects" );
+
+        createPermission( "deleteProject", "Delete Projects" );
+
+        createPermission( "buildProject", "Build Projects" );
+
+        createPermission( "showProject", "Show Projects" );
+
+        createPermission( "addBuildDefinition", "Add Build Definitions" );
+
+        createPermission( "editBuildDefinition", "Edit Build Definitions" );
+
+        createPermission( "deleteBuildDefinition", "Delete Build Definitions" );
+
+        createPermission( "addNotifier", "Add Notifiers" );
+
+        createPermission( "editNotifier", "Edit Notifiers" );
+
+        createPermission( "deleteNotifier", "Delete Notifiers" );
+
+        createPermission( "manageConfiguration", "Manage Continuum Configuration" );
+
+        createPermission( "manageSchedule", "Manage Schedules" );
+
+        createPermission( "manageUsers", "Manage Users/Groups" );
+    }
+
+    private Permission createPermission( String name, String description)
+        throws ContinuumStoreException
+    {
+        Permission perm = store.getPermission( name );
+
+        if ( perm == null )
+        {
+            perm = new Permission();
+
+            perm.setName( name );
+
+            perm.setDescription( description );
+
+            perm = store.addPermission( perm );
+        }
+
+        return perm;
+    }
+
+    private void createGroups()
+        throws ContinuumStoreException
+    {
+        // Continuum Administrator
+        List adminPermissions = store.getPermissions();
+
+        UserGroup adminGroup = new UserGroup();
+
+        adminGroup.setName( ContinuumSecurity.ADMIN_GROUP_NAME );
+
+        adminGroup.setDescription( "Continuum Admin Group" );
+
+        adminGroup.setPermissions( adminPermissions );
+
+        adminGroup = store.addUserGroup( adminGroup );
+
+        // Continuum Guest
+        UserGroup guestGroup = new UserGroup();
+
+        guestGroup.setName( ContinuumSecurity.GUEST_GROUP_NAME );
+
+        guestGroup.setDescription( "Continuum Guest Group" );
+
+        List guestPermissions = new ArrayList();
+
+        guestPermissions.add( store.getPermission( "addProject" ) );
+
+        guestPermissions.add( store.getPermission( "editProject" ) );
+
+        guestPermissions.add( store.getPermission( "deleteProject" ) );
+
+        guestPermissions.add( store.getPermission( "buildProject" ) );
+
+        guestPermissions.add( store.getPermission( "showProject" ) );
+
+        guestPermissions.add( store.getPermission( "addBuildDefinition" ) );
+
+        guestPermissions.add( store.getPermission( "editBuildDefinition" ) );
+
+        guestPermissions.add( store.getPermission( "deleteBuildDefinition" ) );
+
+        guestPermissions.add( store.getPermission( "addNotifier" ) );
+
+        guestPermissions.add( store.getPermission( "editNotifier" ) );
+
+        guestPermissions.add( store.getPermission( "deleteNotifier" ) );
+
+        guestGroup.setPermissions( guestPermissions );
+
+        guestGroup = store.addUserGroup( guestGroup );
+    }
+
+    private void createGuestUser()
+    {
+        ContinuumUser guest = new ContinuumUser();
+
+        guest.setUsername( "guest" );
+
+        guest.setFullName( "Anonymous User" );
+
+        guest.setGroup( store.getUserGroup( ContinuumSecurity.GUEST_GROUP_NAME ) );
+
+        guest.setGuest( true );
+
+        guest = store.addUser( guest );
     }
 }

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/security/DefaultContinuumSecurity.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/security/DefaultContinuumSecurity.java?rev=293446&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/security/DefaultContinuumSecurity.java
(added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/security/DefaultContinuumSecurity.java
Mon Oct  3 13:37:46 2005
@@ -0,0 +1,90 @@
+package org.apache.maven.continuum.security;
+
+/*
+ * 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.apache.maven.continuum.model.system.ContinuumUser;
+import org.apache.maven.continuum.model.system.Permission;
+import org.apache.maven.continuum.model.system.UserGroup;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class DefaultContinuumSecurity
+    implements ContinuumSecurity
+{
+    /**
+     * @plexus.requirement
+     */
+    private ContinuumStore store;
+
+    public List getPermissions( ContinuumUser user )
+        throws ContinuumSecurityException
+    {
+        ContinuumUser u = user;
+
+        if ( u == null )
+        {
+            u = getGuestUser();
+        }
+
+        return getPermissions( u.getGroup() );
+    }
+
+    public List getPermissions( UserGroup group )
+    {
+        return group.getPermissions();
+    }
+
+    public boolean isAuthorized( ContinuumUser user, String action )
+        throws ContinuumSecurityException
+    {
+        List perms = getPermissions( user );
+
+        if ( perms != null )
+        {
+            for ( Iterator i = perms.iterator(); i.hasNext(); )
+            {
+                Permission perm = (Permission) i.next();
+                if ( perm.getName().equals( action ) )
+                {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    public ContinuumUser getGuestUser()
+        throws ContinuumSecurityException
+    {
+        try
+        {
+            return store.getGuestUser();
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ContinuumSecurityException( "Can't obtain guest user.", e );
+        }
+    }
+}

Propchange: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/security/DefaultContinuumSecurity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/security/DefaultContinuumSecurity.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml?rev=293446&r1=293445&r2=293446&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml
(original)
+++ maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml
Mon Oct  3 13:37:46 2005
@@ -14,6 +14,9 @@
           <role>org.apache.maven.continuum.store.ContinuumStore</role>
         </requirement>
         <requirement>
+          <role>org.apache.maven.continuum.security.ContinuumSecurity</role>
+        </requirement>
+        <requirement>
           <role>org.apache.maven.continuum.initialization.ContinuumInitializer</role>
         </requirement>
         <requirement>
@@ -46,6 +49,16 @@
         <source>${plexus.home}/conf/configuration.xml</source>
         <application-home>${plexus.home}</application-home>
       </configuration>
+    </component>
+
+    <component>
+      <role>org.apache.maven.continuum.security.ContinuumSecurity</role>
+      <implementation>org.apache.maven.continuum.security.DefaultContinuumSecurity</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
     </component>
 
     <component>

Modified: maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo?rev=293446&r1=293445&r2=293446&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo (original)
+++ maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo Mon Oct  3 13:37:46 2005
@@ -704,22 +704,59 @@
     </class>
 
     <class>
-      <name>User</name>
+      <name>UserGroup</name>
       <packageName>org.apache.maven.continuum.model.system</packageName>
       <version>1.0.0+</version>
       <fields>
         <field>
-          <name>username</name>
+          <name>id</name>
+          <identifier>true</identifier>
+          <version>1.0.0+</version>
+          <type>int</type>
+        </field>
+        <field>
+          <name>name</name>
           <version>1.0.0+</version>
           <type>String</type>
         </field>
         <field>
+          <name>description</name>
+          <version>1.0.0+</version>
+          <type>String</type>
+        </field>
+        <field>
+          <name>permissions</name>
+          <version>1.0.0+</version>
+          <association stash.part="true">
+            <type>Permission</type>
+            <multiplicity>*</multiplicity>
+          </association>
+        </field>
+      </fields>
+    </class>
+    <class>
+      <name>ContinuumUser</name>
+      <packageName>org.apache.maven.continuum.model.system</packageName>
+      <version>1.0.0+</version>
+      <fields>
+        <field>
           <name>accountId</name>
           <version>1.0.0+</version>
           <type>int</type>
           <identifier>true</identifier>
         </field>
         <field>
+          <name>username</name>
+          <version>1.0.0+</version>
+          <type>String</type>
+        </field>
+        <field>
+          <name>guest</name>
+          <version>1.0.0+</version>
+          <type>boolean</type>
+          <defaultValue>false</defaultValue>
+        </field>
+        <field>
           <name>hashedPassword</name>
           <version>1.0.0+</version>
           <type>String</type>
@@ -735,11 +772,10 @@
           <type>String</type>
         </field>
         <field>
-          <name>permissions</name>
+          <name>group</name>
           <version>1.0.0+</version>
-          <association>
-            <type>Permission</type>
-            <multiplicity>*</multiplicity>
+          <association stash.part="true">
+            <type>UserGroup</type>
           </association>
         </field>
         <field>

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=293446&r1=293445&r2=293446&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
Mon Oct  3 13:37:46 2005
@@ -24,8 +24,10 @@
 import org.apache.maven.continuum.model.project.ProjectNotifier;
 import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.model.system.Installation;
+import org.apache.maven.continuum.model.system.ContinuumUser;
 import org.apache.maven.continuum.model.system.SystemConfiguration;
-import org.apache.maven.continuum.model.system.User;
+import org.apache.maven.continuum.model.system.Permission;
+import org.apache.maven.continuum.model.system.UserGroup;
 import org.apache.maven.continuum.project.ContinuumProjectState;
 import org.codehaus.plexus.jdo.JdoFactory;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
@@ -872,12 +874,12 @@
         }
     }
 
-    public User addUser( User user )
+    public ContinuumUser addUser( ContinuumUser user )
     {
-        return (User) addObject( user );
+        return (ContinuumUser) addObject( user );
     }
 
-    public User getUserByUsername( String username )
+    public ContinuumUser getGuestUser()
         throws ContinuumStoreException
     {
         PersistenceManager pm = pmf.getPersistenceManager();
@@ -888,7 +890,45 @@
         {
             tx.begin();
 
-            Extent extent = pm.getExtent( User.class, true );
+            Extent extent = pm.getExtent( ContinuumUser.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.setFilter( "this.guest == true" );
+
+            Collection result = (Collection) query.execute();
+
+            if ( result.size() == 0 )
+            {
+                tx.commit();
+
+                return null;
+            }
+
+            Object object = pm.detachCopy( result.iterator().next() );
+
+            tx.commit();
+
+            return (ContinuumUser) object;
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
+    public ContinuumUser getUserByUsername( String username )
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( ContinuumUser.class, true );
 
             Query query = pm.newQuery( extent );
 
@@ -911,7 +951,112 @@
 
             tx.commit();
 
-            return (User) object;
+            return (ContinuumUser) object;
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
+    public List getPermissions()
+        throws ContinuumStoreException
+    {
+        return getAllObjectsDetached( Permission.class );
+    }
+
+    public Permission getPermission( String name )
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( Permission.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareImports( "import java.lang.String" );
+
+            query.declareParameters( "String name" );
+
+            query.setFilter( "this.name == name" );
+
+            Collection result = (Collection) query.execute( name );
+
+            if ( result.size() == 0 )
+            {
+                tx.commit();
+
+                return null;
+            }
+
+            Object object = pm.detachCopy( result.iterator().next() );
+
+            tx.commit();
+
+            return (Permission) object;
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
+    public Permission addPermission( Permission perm )
+    {
+        return (Permission) addObject( perm );
+    }
+
+    public UserGroup addUserGroup( UserGroup group)
+    {
+        return (UserGroup) addObject( group );
+    }
+
+    public void updateUserGroup( UserGroup group )
+        throws ContinuumStoreException
+    {
+        updateObject( group );
+    }
+
+    public UserGroup getUserGroup( String name )
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( UserGroup.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareImports( "import java.lang.String" );
+
+            query.declareParameters( "String name" );
+
+            query.setFilter( "this.name == name" );
+
+            Collection result = (Collection) query.execute( name );
+
+            if ( result.size() == 0 )
+            {
+                tx.commit();
+
+                return null;
+            }
+
+            Object object = pm.detachCopy( result.iterator().next() );
+
+            tx.commit();
+
+            return (UserGroup) object;
         }
         finally
         {

Modified: maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/InitializationChecker.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/InitializationChecker.java?rev=293446&r1=293445&r2=293446&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/InitializationChecker.java
(original)
+++ maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/action/InitializationChecker.java
Mon Oct  3 13:37:46 2005
@@ -16,8 +16,10 @@
  * limitations under the License.
  */
 
-import org.apache.maven.continuum.model.system.User;
+import org.apache.maven.continuum.model.system.ContinuumUser;
+import org.apache.maven.continuum.model.system.UserGroup;
 import org.apache.maven.continuum.configuration.ConfigurationService;
+import org.apache.maven.continuum.security.ContinuumSecurity;
 import org.apache.maven.continuum.store.ContinuumStore;
 import org.codehaus.plexus.summit.rundata.RunData;
 import org.codehaus.plexus.action.AbstractAction;
@@ -45,7 +47,7 @@
     public void execute( Map map )
         throws Exception
     {
-        User adminUser = new User();
+        ContinuumUser adminUser = new ContinuumUser();
 
         String username = getValue( map, "username" );
 
@@ -80,8 +82,6 @@
             throw new Exception( "You must set a full name." );
         }
 
-        store.addUser( adminUser );
-
         String email = getValue( map, "email" );
 
         if ( !StringUtils.isEmpty( email) )
@@ -93,6 +93,10 @@
             throw new Exception( "You must set an email." );
         }
 
+        adminUser.setGroup( store.getUserGroup( ContinuumSecurity.ADMIN_GROUP_NAME ) );
+
+        store.addUser( adminUser );
+
         String workingDirectory = getValue( map, "workingDirectory" );
 
         if ( !StringUtils.isEmpty( workingDirectory) )
@@ -147,7 +151,20 @@
             configuration.setCompanyUrl( companyUrl );
         }
 
-        configuration.setGuestAccountEnabled( getBooleanValue( map, "guestAccountEnabled"
) );
+        boolean guestAccountEnabled = getBooleanValue( map, "guestAccountEnabled" );
+
+        if ( guestAccountEnabled )
+        {
+            configuration.setGuestAccountEnabled( guestAccountEnabled );
+        }
+        else
+        {
+            UserGroup guestGroup = store.getUserGroup( "guest" );
+
+            guestGroup.setPermissions( null );
+
+            store.updateUserGroup( guestGroup );
+        }
 
         configuration.setInitialized( true );
 

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=293446&r1=293445&r2=293446&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
Mon Oct  3 13:37:46 2005
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-import org.apache.maven.continuum.model.system.User;
+import org.apache.maven.continuum.model.system.ContinuumUser;
 import org.apache.maven.continuum.store.ContinuumStore;
 import org.apache.maven.continuum.web.model.SessionUser;
 import org.codehaus.plexus.security.summit.SecureRunData;
@@ -46,7 +46,7 @@
 
         String password = (String) map.get( "login.password" );
 
-        User user = store.getUserByUsername( login );
+        ContinuumUser user = store.getUserByUsername( login );
 
         if ( user != null && user.equalsPassword( password ) )
         {



Mime
View raw message