continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcconn...@apache.org
Subject svn commit: r453076 - /maven/continuum/branches/rbac-integration/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java
Date Thu, 05 Oct 2006 01:09:58 GMT
Author: jmcconnell
Date: Wed Oct  4 18:09:57 2006
New Revision: 453076

URL: http://svn.apache.org/viewvc?view=rev&rev=453076
Log:
this is the right logic for the setting of the locked status of the guest user from the configuration
screens, the problem is the check box is returning true even when it is being unchecked.

Modified:
    maven/continuum/branches/rbac-integration/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java

Modified: maven/continuum/branches/rbac-integration/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/rbac-integration/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java?view=diff&rev=453076&r1=453075&r2=453076
==============================================================================
--- maven/continuum/branches/rbac-integration/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java
(original)
+++ maven/continuum/branches/rbac-integration/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java
Wed Oct  4 18:09:57 2006
@@ -19,19 +19,20 @@
 import com.opensymphony.xwork.Preparable;
 import org.apache.maven.continuum.configuration.ConfigurationService;
 import org.apache.maven.continuum.configuration.ConfigurationStoringException;
-import org.apache.maven.continuum.model.system.UserGroup;
-import org.apache.maven.continuum.security.ContinuumSecurity;
 import org.apache.maven.continuum.security.ContinuumRoleConstants;
 import org.apache.maven.continuum.store.ContinuumStore;
 import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.codehaus.plexus.security.rbac.Resource;
 import org.codehaus.plexus.security.ui.web.interceptor.SecureAction;
 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionBundle;
 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionException;
-import org.codehaus.plexus.security.rbac.Resource;
+import org.codehaus.plexus.security.user.User;
 import org.codehaus.plexus.security.user.UserManager;
+import org.codehaus.plexus.security.user.UserNotFoundException;
+import org.codehaus.plexus.security.policy.UserSecurityPolicy;
+import org.codehaus.plexus.security.system.SecuritySystem;
 
 import java.io.File;
-import java.util.Collections;
 
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -54,7 +55,7 @@
     /**
      * @plexus.requirement
      */
-    private UserManager userManager;
+    private SecuritySystem securitySystem;
 
     private boolean guestAccountEnabled;
 
@@ -74,7 +75,7 @@
     {
         ConfigurationService configuration = getContinuum().getConfiguration();
 
-        guestAccountEnabled = configuration.isGuestAccountEnabled();
+        guestAccountEnabled = getGuestAccountLockingStatus();
 
         workingDirectory = configuration.getWorkingDirectory().getAbsolutePath();
 
@@ -92,25 +93,12 @@
     public String save()
         throws ConfigurationStoringException, ContinuumStoreException
     {
-        
-        ConfigurationService configuration = getContinuum().getConfiguration();
-        
-        if ( guestAccountEnabled )
-        {
-            configuration.setGuestAccountEnabled( guestAccountEnabled );
-
 
-        }
-        else
-        {
-            configuration.setGuestAccountEnabled( false );
-
-            UserGroup guestGroup = store.getUserGroup( ContinuumSecurity.GUEST_GROUP_NAME
);
+        ConfigurationService configuration = getContinuum().getConfiguration();
 
-            guestGroup.setPermissions( Collections.EMPTY_LIST );
+        configuration.setGuestAccountEnabled( guestAccountEnabled );
 
-            store.updateUserGroup( guestGroup );
-        }
+        resolveGuestAccountLockingStatus();
 
         configuration.setWorkingDirectory( new File( workingDirectory ) );
 
@@ -128,10 +116,67 @@
         configuration.store();
 
         configuration.setInitialized( true );
-        configuration.store();            
+        configuration.store();
 
         return SUCCESS;
     }
+
+    private void resolveGuestAccountLockingStatus()
+    {
+        UserManager userManager = securitySystem.getUserManager();
+        UserSecurityPolicy policy = securitySystem.getPolicy();
+
+        User guest;
+
+        try
+        {
+            guest = userManager.findUser( "guest" );
+            guest.setLocked( guestAccountEnabled );
+            userManager.updateUser( guest );
+        }
+        catch ( UserNotFoundException ne )
+        {
+            policy.setEnabled( false );
+
+            guest = userManager.createUser( "guest", "Guest", "" );
+            guest.setLocked( guestAccountEnabled );
+            guest = userManager.addUser( guest );
+
+        }
+        finally
+        {
+            policy.setEnabled( true );
+        }       
+    }
+
+    private boolean getGuestAccountLockingStatus()
+    {
+        UserManager userManager = securitySystem.getUserManager();
+        UserSecurityPolicy policy = securitySystem.getPolicy();
+
+        User guest;
+
+        try
+        {
+            guest = userManager.findUser( "guest" );
+
+            return guest.isLocked();
+        }
+        catch ( UserNotFoundException ne )
+        {
+            policy.setEnabled( false );
+
+            guest = userManager.createUser( "guest", "Guest", "" );
+            guest = userManager.addUser( guest );
+
+            return guest.isLocked();
+        }
+        finally
+        {
+            policy.setEnabled( true );
+        }
+    }
+
 
     public boolean isGuestAccountEnabled()
     {



Mime
View raw message