archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1310268 [26/42] - in /archiva/redback/redback-core/trunk: ./ redback-authentication/ redback-authentication/redback-authentication-api/ redback-authentication/redback-authentication-api/src/ redback-authentication/redback-authentication-ap...
Date Fri, 06 Apr 2012 09:59:32 GMT
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/site/resources/images/PlexusSecurityAuthentication.png
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/site/resources/images/PlexusSecurityAuthentication.png?rev=1310268&view=auto
==============================================================================
Binary file - no diff available.

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/site/resources/images/PlexusSecurityAuthentication.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionContextStub.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionContextStub.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionContextStub.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionContextStub.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,52 @@
+package org.codehaus.plexus.redback.struts2;
+
+/*
+ * Copyright 2006-2007 The Codehaus 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 com.opensymphony.xwork2.ActionContext;
+
+import java.util.HashMap;
+
+public class ActionContextStub
+    extends ActionContext
+{
+    public static final String CONTEXT_NAME = "context_name";
+
+    public static final String PARAMETER_1 = "parameter_1";
+
+    public static final String PARAMETER_2 = "parameter_2";
+
+    public static final String PARAMETER_3 = "parameter_3";
+
+    public static final String VALUE_1 = "value_1";
+
+    public static final String VALUE_2 = "value_2";
+
+    public static final String VALUE_3 = "value_3";
+
+    @SuppressWarnings("unchecked")
+    public ActionContextStub()
+    {
+        super( new HashMap() );
+        this.setName( CONTEXT_NAME );
+        this.setSession( new HashMap() );
+
+        this.setParameters( new HashMap<String,Object>() );
+        this.getParameters().put( PARAMETER_1, VALUE_1 );
+        this.getParameters().put( PARAMETER_2, VALUE_2 );
+        this.getParameters().put( PARAMETER_3, VALUE_3 );
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionContextStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionContextStub.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionInvocationStub.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionInvocationStub.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionInvocationStub.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionInvocationStub.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,108 @@
+package org.codehaus.plexus.redback.struts2;
+
+/*
+ * Copyright 2006-2007 The Codehaus 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 com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionEventListener;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.Result;
+import com.opensymphony.xwork2.interceptor.PreResultListener;
+import com.opensymphony.xwork2.util.ValueStack;
+
+/**
+ * @noinspection ProhibitedExceptionDeclared
+ */
+public class ActionInvocationStub
+    implements ActionInvocation
+{
+    private ActionContext actionContext = new ActionContextStub();
+
+    private ActionProxy actionProxy = new ActionProxyStub();
+
+    public ActionInvocationStub()
+    {
+        actionContext.setActionInvocation( this );
+    }
+
+    public Object getAction()
+    {
+        return null;
+    }
+
+    public boolean isExecuted()
+    {
+        return false;
+    }
+
+    public ActionContext getInvocationContext()
+    {
+        return actionContext;
+    }
+
+    public ActionProxy getProxy()
+    {
+        return actionProxy;
+    }
+
+    public Result getResult()
+        throws Exception
+    {
+        return null;
+    }
+
+    public String getResultCode()
+    {
+        return null;
+    }
+
+    public void setResultCode( String code )
+    {
+
+    }
+
+    public ValueStack getStack()
+    {
+        return null;
+    }
+
+    public void addPreResultListener( PreResultListener listener )
+    {
+
+    }
+
+    public String invoke()
+        throws Exception
+    {
+        return null;
+    }
+
+    public String invokeActionOnly()
+        throws Exception
+    {
+        return null;
+    }
+
+    public void setActionEventListener(ActionEventListener arg0) {
+        
+    }
+
+    public void init(ActionProxy arg0) {
+        
+    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionInvocationStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionInvocationStub.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionProxyStub.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionProxyStub.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionProxyStub.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionProxyStub.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,109 @@
+package org.codehaus.plexus.redback.struts2;
+
+/*
+ * Copyright 2006-2007 The Codehaus 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 com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.config.entities.ActionConfig;
+
+public class ActionProxyStub
+    implements ActionProxy
+{
+    public static final String ACTION_NAME = "stub_action";
+
+    public static final String NAMESPACE = "namespace";
+
+    public static final String METHOD = "method";
+
+    private String methodName;
+
+    private String actionName;
+
+    public Object getAction()
+    {
+        return null;
+    }
+
+    public void setActionName( String name )
+    {
+        actionName = name;
+    }
+
+    public void prepare() throws Exception
+    {
+        //Do nothing
+    }
+
+    public String getActionName()
+    {
+        if ( actionName != null )
+        {
+            return actionName;
+        }
+        else
+        {
+            return ACTION_NAME;
+        }
+    }
+
+    public ActionConfig getConfig()
+    {
+        return null;
+    }
+
+    public void setExecuteResult( boolean result )
+    {
+
+    }
+
+    public boolean getExecuteResult()
+    {
+        return false;
+    }
+
+    public ActionInvocation getInvocation()
+    {
+        return null;
+    }
+
+    public String getNamespace()
+    {
+        return NAMESPACE;
+    }
+
+    public String execute()
+    {
+        return null;
+    }
+
+    public void setMethod( String name )
+    {
+        methodName = name;
+    }
+
+    public String getMethod()
+    {
+        if ( methodName != null )
+        {
+            return methodName;
+        }
+        else
+        {
+            return METHOD;
+        }
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionProxyStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/ActionProxyStub.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/LoginActionTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/LoginActionTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/LoginActionTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/LoginActionTest.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,89 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.util.HashMap;
+
+import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.DefaultUserSecurityPolicy;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
+import org.codehaus.plexus.redback.policy.UserValidationSettings;
+import org.codehaus.plexus.redback.system.DefaultSecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.XWorkTestCase;
+
+public class LoginActionTest
+    extends XWorkTestCase
+{
+
+    LoginAction action;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        action = new LoginAction();
+        action.session = new HashMap<String, Object>();
+    }
+
+    public void testRedback265()
+        throws SecurityException, NoSuchMethodException, AccountLockedException, MustChangePasswordException,
+        AuthenticationException, UserNotFoundException
+    {
+        String principal = "authenticates_but_does_not_exist";
+
+        // Setup authentication success, with no user found
+        AuthenticationResult result = new AuthenticationResult( true, principal, null );
+        SecuritySession session = new DefaultSecuritySession( result );
+        UserSecurityPolicy policy = new DefaultUserSecurityPolicy();
+
+        SecuritySystem system = createMock( SecuritySystem.class );
+        UserValidationSettings validationSettings = createMock( UserValidationSettings.class );
+        expect( system.authenticate( (AuthenticationDataSource) anyObject() ) ).andReturn( session );
+        expect( system.getPolicy() ).andReturn( policy ).anyTimes();
+        expect( validationSettings.isEmailValidationRequired() ).andReturn( true ).anyTimes();
+
+        // Hook-up action to mock objects
+        action.securitySystem = system;
+        action.setUsername( principal );
+
+        replay( system, validationSettings );
+
+        String actionResult = action.login();
+
+        verify( system, validationSettings );
+
+        assertEquals( Action.ERROR, actionResult );
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/LoginActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/LoginActionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractUserCredentialsActionTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractUserCredentialsActionTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractUserCredentialsActionTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractUserCredentialsActionTest.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,164 @@
+package org.codehaus.plexus.redback.struts2.action.admin;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 net.sf.ehcache.CacheManager;
+import org.apache.struts2.StrutsSpringTestCase;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.RbacObjectInvalidException;
+import org.codehaus.plexus.redback.rbac.UserAssignment;
+import org.codehaus.plexus.redback.role.RoleManager;
+import org.codehaus.plexus.redback.struts2.action.AbstractUserCredentialsAction;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.system.SecuritySystemConstants;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.redback.users.memory.SimpleUser;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.JUnit4;
+
+import java.util.Collections;
+
+@RunWith( JUnit4.class )
+public abstract class AbstractUserCredentialsActionTest
+    extends StrutsSpringTestCase
+{
+    protected static final String PASSWORD = "password1";
+
+    //@Inject
+    //@Named( value = "rBACManager#memory" )
+    protected RBACManager rbacManager;
+
+    //@Inject
+    private RoleManager roleManager;
+
+    //@Inject
+    protected SecuritySystem system;
+
+    protected SecuritySession session;
+
+    @Override
+    protected String[] getContextLocations()
+    {
+        return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
+    }
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        CacheManager.getInstance().clearAll();
+        super.setUp();
+
+        rbacManager = applicationContext.getBean( "rBACManager#memory" , RBACManager.class );
+        roleManager = applicationContext.getBean( RoleManager.class );
+        system = applicationContext.getBean( SecuritySystem.class );
+
+
+        roleManager.loadRoleModel( getClass().getResource( "/redback.xml" ) );
+        roleManager.createTemplatedRole( "project-administrator", "default" );
+        roleManager.createTemplatedRole( "project-administrator", "other" );
+        roleManager.createTemplatedRole( "project-grant-only", "default" );
+
+        UserManager userManager = system.getUserManager();
+
+        User user = new SimpleUser();
+        user.setUsername( "user" );
+        user.setPassword( PASSWORD );
+        userManager.addUserUnchecked( user );
+
+        user = new SimpleUser();
+        user.setUsername( "user2" );
+        user.setPassword( PASSWORD );
+        userManager.addUserUnchecked( user );
+
+        user = new SimpleUser();
+        user.setUsername( "user3" );
+        user.setPassword( PASSWORD );
+        userManager.addUserUnchecked( user );
+
+        user = new SimpleUser();
+        user.setUsername( "admin" );
+        user.setPassword( PASSWORD );
+        userManager.addUserUnchecked( user );
+
+        user = new SimpleUser();
+        user.setUsername( "user-admin" );
+        user.setPassword( PASSWORD );
+        userManager.addUserUnchecked( user );
+
+        UserAssignment assignment = rbacManager.createUserAssignment( "admin" );
+        assignment.addRoleName( "System Administrator" );
+        rbacManager.saveUserAssignment( assignment );
+
+        assignment = rbacManager.createUserAssignment( "user-admin" );
+        assignment.addRoleName( "User Administrator" );
+        rbacManager.saveUserAssignment( assignment );
+
+        assignment = rbacManager.createUserAssignment( "user2" );
+        rbacManager.saveUserAssignment( assignment );
+    }
+
+    @After
+    public void after()
+    {
+        CacheManager.getInstance().clearAll();
+    }
+
+    protected void addAssignment( String principal, String roleName )
+        throws RbacManagerException, RbacObjectInvalidException
+    {
+        UserAssignment assignment;
+
+        if ( rbacManager.userAssignmentExists( principal ) )
+        {
+            assignment = rbacManager.getUserAssignment( principal );
+        }
+        else
+        {
+            assignment = rbacManager.createUserAssignment( principal );
+        }
+        assignment.addRoleName( roleName );
+        rbacManager.saveUserAssignment( assignment );
+    }
+
+    protected void login( AbstractUserCredentialsAction action, String principal, String password )
+        throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException
+    {
+        PasswordBasedAuthenticationDataSource authdatasource = new PasswordBasedAuthenticationDataSource();
+        authdatasource.setPrincipal( principal );
+        authdatasource.setPassword( password );
+        session = system.authenticate( authdatasource );
+        assertTrue( session.isAuthenticated() );
+
+        action.setSession( Collections.singletonMap( SecuritySystemConstants.SECURITY_SESSION_KEY, (Object) session ) );
+    }
+
+}
\ No newline at end of file

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractUserCredentialsActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractUserCredentialsActionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AssignmentsActionTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AssignmentsActionTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AssignmentsActionTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AssignmentsActionTest.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,664 @@
+package org.codehaus.plexus.redback.struts2.action.admin;
+
+/*
+ * Copyright 2008 The Codehaus.
+ *
+ * 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 com.google.common.collect.Lists;
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.ActionProxy;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authorization.AuthorizationResult;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.RbacObjectInvalidException;
+import org.codehaus.plexus.redback.rbac.Role;
+import org.codehaus.plexus.redback.struts2.model.ApplicationRoleDetails;
+import org.codehaus.plexus.redback.struts2.model.ApplicationRoleDetails.RoleTableCell;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @todo missing tests for success/fail on standard show/edit functions (non security testing related)
+ */
+public class AssignmentsActionTest
+    extends AbstractUserCredentialsActionTest
+{
+    private AssignmentsAction action;
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        ActionProxy actionProxy = getActionProxy( "/security/assignments" );
+        action = (AssignmentsAction) actionProxy.getAction();
+
+        login( action, "user", PASSWORD );
+        action.setPrincipal( "user2" );
+
+    }
+
+    /**
+     * Check security - show/edituser should fail if the permission 'user-management-user-role' is not present, but a
+     * valid 'user-management-role-grant' is.
+     */
+    @Test
+    public void testUserWithOnlyRoleGrantHasNoAccess()
+        throws Exception
+    {
+
+        addAssignment( "user", "Grant Administrator - default" );
+
+        List<SecureActionBundle.AuthorizationTuple> authorizationTuples = getTuples();
+        for ( SecureActionBundle.AuthorizationTuple tuple : authorizationTuples )
+        {
+            AuthorizationResult authzResult = system.authorize( session, tuple.getOperation(), tuple.getResource() );
+
+            assertFalse( authzResult.isAuthorized() );
+        }
+    }
+
+    /**
+     * Check security - check success if the permission 'user-management-user-role' is present along with global
+     * 'user-management-role-grant'.
+     */
+    @Test
+    public void testUserWithOnlyRoleGrantHasAccess()
+        throws Exception
+    {
+        addAssignment( "user", "Project Administrator - default" );
+
+        List<SecureActionBundle.AuthorizationTuple> authorizationTuples = getTuples();
+        boolean result = false;
+        for ( SecureActionBundle.AuthorizationTuple tuple : authorizationTuples )
+        {
+            AuthorizationResult authzResult = system.authorize( session, tuple.getOperation(), tuple.getResource() );
+
+            result |= authzResult.isAuthorized();
+        }
+        assertTrue( result );
+    }
+
+    private List<SecureActionBundle.AuthorizationTuple> getTuples()
+        throws SecureActionException
+    {
+        return action.getSecureActionBundle().getAuthorizationTuples();
+    }
+
+    /**
+     * Check roles can be assigned if the user has no previous assignments.
+     */
+    @Test
+    public void testShowWhenUserHasNoAssignments()
+        throws Exception
+    {
+        addAssignment( "user", "Project Administrator - default" );
+
+        action.setPrincipal( "user3" );
+
+        assertEquals( Action.SUCCESS, action.show() );
+
+        assertEquals( 2, action.getApplicationRoleDetails().size() );
+    }
+
+    /**
+     * Check security - show should filter out roles that the 'user-management-role-grant' is not present for
+     */
+    @Test
+    public void testRoleGrantFilteringOnShow()
+        throws Exception
+    {
+        addAssignment( "user", "Project Administrator - default" );
+
+        assertEquals( Action.SUCCESS, action.show() );
+
+        assertEquals( 2, action.getApplicationRoleDetails().size() );
+        ApplicationRoleDetails details = (ApplicationRoleDetails) action.getApplicationRoleDetails().get( 0 );
+        assertEquals( "System", details.getName() );
+        assertEquals( "Roles that apply system-wide, across all of the applications", details.getDescription() );
+        assertEquals( "found roles " + details.getAvailableRoles(), 0, details.getAvailableRoles().size() );
+        details = (ApplicationRoleDetails) action.getApplicationRoleDetails().get( 1 );
+        assertEquals( "Continuum", details.getName() );
+        assertEquals( "found roles " + details.getAvailableRoles(), 0, details.getAvailableRoles().size() );
+
+        // This table rendering code clearly has to go
+        List<List<RoleTableCell>> table = details.getTable();
+        assertEquals( 1, table.size() );
+        assertRow( table, 0, "default", "Project Administrator - default", false );
+    }
+
+    @SuppressWarnings( "unchecked" )
+    private void assertRow( List table, int index, String name, String label, boolean assigned )
+    {
+        List<RoleTableCell> row = (List<RoleTableCell>) table.get( index );
+        assertEquals( name, row.get( 0 ).getName() );
+        assertEquals( label, row.get( 1 ).getName() );
+        assertEquals( assigned, row.get( 2 ).isAssigned() );
+    }
+
+    /**
+     * Check security - show should not filter out roles if 'user-management-role-grant' is present for the global
+     * resource
+     */
+    // TODO: currently returns all roles - we really want all templated roles
+    // public void testRoleGrantFilteringOnShowGlobalGrant()
+    // throws RbacObjectInvalidException, RbacManagerException
+    // {
+    // addAssignment( "user", "Global Grant Administrator" );
+    //
+    // assertEquals( Action.SUCCESS, action.show() );
+    //
+    // assertEquals( 2, action.getApplicationRoleDetails().size() );
+    // ApplicationRoleDetails details = (ApplicationRoleDetails) action.getApplicationRoleDetails().get( 0 );
+    // assertEquals( "redback-xwork-integration-core", details.getName() );
+    // assertEquals( 0, details.getAvailableRoles().size() );
+    //
+    // details = (ApplicationRoleDetails) action.getApplicationRoleDetails().get( 1 );
+    // assertEquals( "Continuum", details.getName() );
+    // assertEquals( 0, details.getAvailableRoles().size() );
+    //
+    // List table = details.getTable();
+    // assertEquals( 2, table.size() );
+    // assertRow( table, 0, "default", "Project Administrator - default", false );
+    // assertRow( table, 1, "other", "Project Administrator - other", false );
+    // }
+
+    /**
+     * Check security - edituser should skip adding a role that 'user-management-role-grant' is not present for a
+     * non-templated role
+     */
+    @Test
+    public void testRoleGrantFilteringOnAddRolesNotPermittedTemplated()
+        throws RbacObjectInvalidException, RbacManagerException
+    {
+        addAssignment( "user", "Project Administrator - default" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> dSelectedRoles = new ArrayList<String>();
+        dSelectedRoles.add( "Project Administrator - other" );
+
+        action.setAddDSelectedRoles( dSelectedRoles );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+
+        assertEquals( Action.SUCCESS, action.edituser() );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+    }
+
+    /**
+     * Check security - edituser should skip adding a role that 'user-management-role-grant' is not present for a
+     * templated role
+     */
+    @Test
+    public void testRoleGrantFilteringOnAddRolesNotPermittedNotTemplated()
+        throws RbacObjectInvalidException, RbacManagerException
+    {
+        addAssignment( "user", "Project Administrator - default" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> ndSelectedRoles = new ArrayList<String>();
+        ndSelectedRoles.add( "Continuum Group Project Administrator" );
+
+        action.setAddNDSelectedRoles( ndSelectedRoles );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+
+        assertEquals( Action.SUCCESS, action.edituser() );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+    }
+
+    /**
+     * Check security - edituser should succeed if adding a role that 'user-management-role-grant' is present for
+     * untemplated roles
+     */
+    @Test
+    public void testRoleGrantFilteringOnAddRolesPermittedNotTemplated()
+        throws RbacObjectInvalidException, RbacManagerException, AccountLockedException, AuthenticationException,
+        UserNotFoundException
+    {
+        addAssignment( "user", "Global Grant Administrator" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> ndSelectedRoles = new ArrayList<String>();
+        ndSelectedRoles.add( "Continuum Group Project Administrator" );
+
+        action.setAddNDSelectedRoles( ndSelectedRoles );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+
+        assertEquals( Action.SUCCESS, action.edituser() );
+
+        assertEquals( Lists.<String>newArrayList( "Continuum Group Project Administrator" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+    }
+
+    /**
+     * Check security - edituser should succeed if adding a role that 'user-management-role-grant' is present for
+     * templated roles
+     */
+    @Ignore
+    public void testRoleGrantFilteringOnAddRolesPermittedTemplated()
+        throws Exception
+    {
+
+        rbacManager.removeUserAssignment( "user" );
+
+        addAssignment( "user", "Project Administrator - default" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> dSelectedRoles = new ArrayList<String>();
+        dSelectedRoles.add( "Project Administrator - default" );
+
+        ActionProxy actionProxy = getActionProxy( "/security/assignments" );
+        AssignmentsAction newAction = (AssignmentsAction) actionProxy.getAction();
+
+        login( newAction, "user", PASSWORD );
+
+        newAction.setPrincipal( "user2" );
+
+        newAction.setAddDSelectedRoles( dSelectedRoles );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+
+        assertEquals( Action.SUCCESS, newAction.edituser() );
+
+        assertEquals( Arrays.asList( "Project Administrator - default" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+    }
+
+    /**
+     * Check security - edituser should succeed if adding a role that 'user-management-role-grant' is present for
+     * templated roles
+     */
+    @Test
+    public void testRoleGrantFilteringOnAddRolesPermittedTemplatedExistingRole()
+        throws Exception
+    {
+        addAssignment( "user", "Project Administrator - default" );
+
+        // cleanup before next test
+        rbacManager.removeUserAssignment( "user2" );
+
+        addAssignment( "user2", "Project Administrator - other" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> dSelectedRoles = new ArrayList<String>();
+        dSelectedRoles.add( "Project Administrator - default" );
+
+        ActionProxy actionProxy = getActionProxy( "/security/assignments" );
+        AssignmentsAction newAction = (AssignmentsAction) actionProxy.getAction();
+
+        login( newAction, "user2", PASSWORD );
+
+        newAction.setPrincipal( "user2" );
+
+        newAction.setAddDSelectedRoles( dSelectedRoles );
+
+        assertEquals( Arrays.asList( "Project Administrator - other" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+
+        assertEquals( Action.SUCCESS, newAction.edituser() );
+
+        //assertEquals( Arrays.asList( "Project Administrator - default", "Project Administrator - other" ),
+        //              rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+    }
+
+    /**
+     * Check security - edituser should fail if removing a role that 'user-management-role-grant' is not present for
+     * untemplated roles
+     */
+    @Test
+    public void testRoleGrantFilteringOnRemoveRolesNotPermittedNotTemplated()
+        throws Exception
+    {
+
+        rbacManager.removeUserAssignment( "user2" );
+
+        addAssignment( "user", "Project Administrator - default" );
+
+        addAssignment( "user2", "Continuum Group Project Administrator" );
+
+        ActionProxy actionProxy = getActionProxy( "/security/assignments" );
+        AssignmentsAction newAction = (AssignmentsAction) actionProxy.getAction();
+
+        login( newAction, "user2", PASSWORD );
+
+        newAction.setPrincipal( "user2" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> ndSelectedRoles = new ArrayList<String>();
+        newAction.setAddNDSelectedRoles( ndSelectedRoles );
+
+        assertEquals( Arrays.asList( "Continuum Group Project Administrator" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+
+        assertEquals( Action.SUCCESS, newAction.edituser() );
+
+        assertEquals( Arrays.asList( "Continuum Group Project Administrator" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+    }
+
+    /**
+     * Check security - edituser should fail if removing a role that 'user-management-role-grant' is not present for
+     * templated roles
+     */
+    @Ignore
+    public void testRoleGrantFilteringOnRemoveRolesNotPermittedTemplated()
+        throws Exception
+    {
+        rbacManager.removeUserAssignment( "user2" );
+
+        addAssignment( "user", "Project Administrator - other" );
+
+        addAssignment( "user2", "Project Administrator - default" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> dSelectedRoles = new ArrayList<String>();
+
+        ActionProxy actionProxy = getActionProxy( "/security/assignments" );
+        AssignmentsAction newAction = (AssignmentsAction) actionProxy.getAction();
+
+        login( newAction, "user2", PASSWORD );
+
+        newAction.setPrincipal( "user2" );
+
+        newAction.setAddDSelectedRoles( dSelectedRoles );
+
+        assertEquals( Arrays.asList( "Project Administrator - default" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+
+        assertEquals( Action.SUCCESS, newAction.edituser() );
+
+        assertEquals( Arrays.asList( "Project Administrator - default" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+    }
+
+    /**
+     * Check security - edituser should succeed if removing a role that 'user-management-role-grant' is present for
+     * untemplated roles
+     */
+    @Test
+    public void testRoleGrantFilteringOnRemoveRolesPermittedNotTemplated()
+        throws Exception
+    {
+        addAssignment( "user", "Global Grant Administrator" );
+
+        addAssignment( "user2", "Continuum Group Project Administrator" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> ndSelectedRoles = new ArrayList<String>();
+        action.setAddNDSelectedRoles( ndSelectedRoles );
+
+        assertEquals( Arrays.asList( "Continuum Group Project Administrator" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+
+        assertEquals( Action.SUCCESS, action.edituser() );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+    }
+
+    /**
+     * Check security - edituser should succeed if removing a role that 'user-management-role-grant' is present for
+     * templated roles and there is an existing role that is not assignable by the current user.
+     */
+    @Test
+    public void testRoleGrantFilteringOnRemoveRolesPermittedTemplatedExistingRole()
+        throws Exception
+    {
+        addAssignment( "user", "Project Administrator - default" );
+
+        rbacManager.removeUserAssignment( "user2" );
+
+        addAssignment( "user2", "Project Administrator - default" );
+        addAssignment( "user2", "Project Administrator - other" );
+        addAssignment( "user2", "Registered User" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> dSelectedRoles = new ArrayList<String>();
+        dSelectedRoles.add( "Project Administrator - other" );
+        dSelectedRoles.add( "Registered User" );
+        action.setAddDSelectedRoles( dSelectedRoles );
+
+        assertEquals(
+            Arrays.asList( "Project Administrator - default", "Project Administrator - other", "Registered User" ),
+            rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+
+        assertEquals( Action.SUCCESS, action.edituser() );
+
+        // Roles may be out of order, due to removal and subsequent re-add
+        List<String> user2roles = rbacManager.getUserAssignment( "user2" ).getRoleNames();
+        assertTrue( user2roles.contains( "Project Administrator - other" ) );
+        assertTrue( user2roles.contains( "Registered User" ) );
+    }
+
+    /**
+     * Check security - edituser should succeed if removing a role that 'user-management-role-grant' is present for
+     * templated roles
+     */
+    @Test
+    public void testRoleGrantFilteringOnRemoveRolesPermittedTemplated()
+        throws Exception
+    {
+        rbacManager.removeUserAssignment( "user2" );
+
+        addAssignment( "user", "Project Administrator - default" );
+
+        addAssignment( "user2", "Project Administrator - default" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> dSelectedRoles = new ArrayList<String>();
+        action.setAddDSelectedRoles( dSelectedRoles );
+
+        assertEquals( Arrays.asList( "Project Administrator - default" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+
+        assertEquals( Action.SUCCESS, action.edituser() );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+    }
+
+    /**
+     * Check security - show should succeed and display all roles, even without 'user-management-role-grant' or
+     * 'user-management-user-role' for the user administrators.
+     *
+     * @throws MustChangePasswordException
+     */
+    @Test
+    public void testSystemAdminCanShowRoles()
+        throws Exception
+    {
+
+        login( action, "admin", PASSWORD );
+
+        assertEquals( Action.SUCCESS, action.show() );
+
+        assertEquals( 2, action.getApplicationRoleDetails().size() );
+        ApplicationRoleDetails details = (ApplicationRoleDetails) action.getApplicationRoleDetails().get( 0 );
+        assertEquals( "System", details.getName() );
+        assertEquals( "Roles that apply system-wide, across all of the applications", details.getDescription() );
+        assertEquals( 4, details.getAvailableRoles().size() );
+        assertEquals( "Guest", details.getAvailableRoles().get( 0 ) );
+        assertEquals( "Registered User", details.getAvailableRoles().get( 1 ) );
+        assertEquals( "System Administrator", details.getAvailableRoles().get( 2 ) );
+        assertEquals( "User Administrator", details.getAvailableRoles().get( 3 ) );
+
+        details = (ApplicationRoleDetails) action.getApplicationRoleDetails().get( 1 );
+        assertEquals( "Continuum", details.getName() );
+
+        assertEquals( 2, details.getAvailableRoles().size() );
+        assertEquals( "Continuum Group Project Administrator", details.getAvailableRoles().get( 0 ) );
+        assertEquals( "Global Grant Administrator", details.getAvailableRoles().get( 1 ) );
+
+        List<List<RoleTableCell>> table = details.getTable();
+        assertEquals( 2, table.size() );
+        assertRow( table, 0, "default", "Project Administrator - default", false );
+        assertRow( table, 1, "other", "Project Administrator - other", false );
+    }
+
+    /**
+     * Check security - show should succeed and display all roles, even without 'user-management-role-grant' or
+     * 'user-management-user-role' for the user administrators.
+     */
+    @Test
+    public void testUserAdminCanShowRoles()
+        throws Exception
+    {
+
+        ActionProxy actionProxy = getActionProxy( "/security/assignments" );
+        AssignmentsAction newAction = (AssignmentsAction) actionProxy.getAction();
+
+        login( newAction, "user-admin", PASSWORD );
+
+        newAction.setPrincipal( "user-admin" );
+
+        assertEquals( Action.SUCCESS, newAction.show() );
+
+        assertEquals( 2, newAction.getApplicationRoleDetails().size() );
+        ApplicationRoleDetails details = (ApplicationRoleDetails) newAction.getApplicationRoleDetails().get( 0 );
+        assertEquals( "System", details.getName() );
+        assertEquals( "Roles that apply system-wide, across all of the applications", details.getDescription() );
+        // TODO assertEquals( 3, details.getAvailableRoles().size() );
+        assertEquals( "Guest", details.getAvailableRoles().get( 0 ) );
+        assertEquals( "not role Registered User roles : " + details.getAvailableRoles(), "Registered User",
+                      details.getAvailableRoles().get( 1 ) );
+        // TODO: assertEquals( "User Administrator", details.getAvailableRoles().get( 2 ) );
+
+        details = newAction.getApplicationRoleDetails().get( 1 );
+        assertEquals( "Continuum", details.getName() );
+
+        assertEquals( 2, details.getAvailableRoles().size() );
+        assertEquals( "Continuum Group Project Administrator", details.getAvailableRoles().get( 0 ) );
+        assertEquals( "Global Grant Administrator", details.getAvailableRoles().get( 1 ) );
+
+        List<List<RoleTableCell>> table = details.getTable();
+        assertEquals( 2, table.size() );
+        assertRow( table, 0, "default", "Project Administrator - default", false );
+        assertRow( table, 1, "other", "Project Administrator - other", false );
+    }
+
+    /**
+     * Check security - edituser should succeed in adding a role, even without 'user-management-role-grant' or
+     * 'user-management-user-role' for the user administrators.
+     */
+    @Test
+    public void testUserAdminCanAddRoles()
+        throws Exception
+    {
+        login( action, "user-admin", PASSWORD );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> ndSelectedRoles = new ArrayList<String>();
+        ndSelectedRoles.add( "Continuum Group Project Administrator" );
+
+        action.setAddNDSelectedRoles( ndSelectedRoles );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> dSelectedRoles = new ArrayList<String>();
+        dSelectedRoles.add( "Project Administrator - default" );
+
+        action.setAddDSelectedRoles( dSelectedRoles );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+
+        assertEquals( Action.SUCCESS, action.edituser() );
+
+        assertEquals( Arrays.asList( "Continuum Group Project Administrator", "Project Administrator - default" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+    }
+
+    /**
+     * Check security - edituser should succeed in removing a role, even without 'user-management-role-grant' or
+     * 'user-management-user-role' for the user administrators.
+     */
+    @Test
+    public void testUserAdminCanRemoveRoles()
+        throws Exception
+    {
+        login( action, "user-admin", PASSWORD );
+
+        rbacManager.removeUserAssignment( "user2" );
+
+        addAssignment( "user2", "Continuum Group Project Administrator" );
+        addAssignment( "user2", "Project Administrator - default" );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> ndSelectedRoles = new ArrayList<String>();
+        action.setAddNDSelectedRoles( ndSelectedRoles );
+
+        List<String> dSelectedRoles = new ArrayList<String>();
+        action.setAddDSelectedRoles( dSelectedRoles );
+
+        assertEquals( Arrays.asList( "Continuum Group Project Administrator", "Project Administrator - default" ),
+                      rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+
+        assertEquals( Action.SUCCESS, action.edituser() );
+
+        assertTrue( rbacManager.getUserAssignment( "user2" ).getRoleNames().isEmpty() );
+    }
+
+    /**
+     * Check that a configured struts2 redback app only removes roles configured for the app. Without this, redback
+     * applications sharing a user database will remove each other's roles on save.
+     */
+    @Test
+    public void testUserAdminCannotRemoveNonAppRoles()
+        throws Exception
+    {
+        login( action, "user-admin", PASSWORD );
+
+        // Create a role that isn't configured for apps
+        String nonAppRoleName = "Other App Role";
+        Role nonAppRole = rbacManager.createRole( nonAppRoleName );
+        rbacManager.saveRole( nonAppRole );
+
+        rbacManager.removeUserAssignment( "user2" );
+
+        addAssignment( "user2", "Continuum Group Project Administrator" );
+        addAssignment( "user2", "Project Administrator - default" );
+        addAssignment( "user2", nonAppRoleName );
+
+        // set addDSelectedRoles (dynamic --> Resource Roles) and addNDSelectedRoles (non-dynamic --> Available Roles)
+        List<String> ndSelectedRoles = new ArrayList<String>();
+        action.setAddNDSelectedRoles( ndSelectedRoles );
+
+        List<String> dSelectedRoles = new ArrayList<String>();
+        action.setAddDSelectedRoles( dSelectedRoles );
+
+        assertEquals(
+            Arrays.asList( "Continuum Group Project Administrator", "Project Administrator - default", nonAppRoleName ),
+            rbacManager.getUserAssignment( "user2" ).getRoleNames() );
+
+        assertEquals( Action.SUCCESS, action.edituser() );
+
+        // All roles except role from other app should be removed.
+        List<String> user2roles = rbacManager.getUserAssignment( "user2" ).getRoleNames();
+        assertTrue( !user2roles.contains( "Continuum Group Project Administrator" ) );
+        assertTrue( !user2roles.contains( "Project Administrator - default" ) );
+        assertTrue( user2roles.contains( nonAppRoleName ) );
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AssignmentsActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AssignmentsActionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoActionTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoActionTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoActionTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoActionTest.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,64 @@
+package org.codehaus.plexus.redback.struts2.action.admin;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * 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.struts2.StrutsSpringTestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * SystemInfoActionTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@RunWith( JUnit4.class )
+public class SystemInfoActionTest
+    extends StrutsSpringTestCase
+{
+    private SystemInfoAction systeminfo;
+
+    @Override
+    protected String[] getContextLocations()
+    {
+        return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
+    }
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        systeminfo = (SystemInfoAction) getActionProxy( "/security/systeminfo" ).getAction();
+
+        //systeminfo = (SystemInfoAction) lookup( "com.opensymphony.xwork2.Action", "redback-sysinfo" );
+    }
+
+    @Test
+    public void testSystemInfoDump()
+    {
+        String result = systeminfo.show();
+        assertNotNull( result );
+        assertEquals( "success", result );
+        assertNotNull( systeminfo.getDetails() );
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoActionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditActionTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditActionTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditActionTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditActionTest.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,361 @@
+package org.codehaus.plexus.redback.struts2.action.admin;
+
+/*
+ * Copyright 2008 The Codehaus.
+ *
+ * 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 com.opensymphony.xwork2.Action;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.RbacObjectInvalidException;
+import org.codehaus.plexus.redback.rbac.RbacObjectNotFoundException;
+import org.codehaus.plexus.redback.rbac.Role;
+import org.codehaus.plexus.redback.system.DefaultSecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystemConstants;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.redback.users.memory.SimpleUser;
+import org.codehaus.redback.integration.model.AdminEditUserCredentials;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * @todo missing tests for success/fail on standard show/edit functions (non security testing related)
+ */
+public class UserEditActionTest
+    extends AbstractUserCredentialsActionTest
+{
+
+    private Locale originalLocale;
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        originalLocale = Locale.getDefault();
+        Locale.setDefault( Locale.ENGLISH );
+    }
+
+    @After
+    public void tearDown()
+        throws Exception
+    {
+        try
+        {
+            super.tearDown();
+        }
+        finally
+        {
+            Locale.setDefault( originalLocale == null ? Locale.ENGLISH : originalLocale );
+        }
+    }
+
+    @Test
+    public void testEditPageShowsAdministratableRoles()
+        throws RbacObjectInvalidException, RbacManagerException, AccountLockedException, AuthenticationException,
+        UserNotFoundException, MustChangePasswordException
+    {
+
+        rbacManager.removeUserAssignment( "user2" );
+
+        addAssignment( "user", "User Administrator" );
+
+        addAssignment( "user2", "Project Administrator - default" );
+        addAssignment( "user2", "Project Administrator - other" );
+
+        UserEditAction action = (UserEditAction) getActionProxy( "/security/useredit" ).getAction();
+        login( action, "user2", PASSWORD );
+        action.setUsername( "user2" );
+        assertEquals( Action.INPUT, action.edit() );
+
+        List<Role> effectivelyAssignedRoles = action.getEffectivelyAssignedRoles();
+        assertEquals( 2, effectivelyAssignedRoles.size() );
+        Role r = effectivelyAssignedRoles.get( 0 );
+        assertEquals( "Project Administrator - default", r.getName() );
+        r = effectivelyAssignedRoles.get( 1 );
+        assertEquals( "Project Administrator - other", r.getName() );
+        assertFalse( action.isHasHiddenRoles() );
+
+        rbacManager.removeUserAssignment( "user2" );
+    }
+
+    @Test
+    public void testEditPageHidesUnadministratableRoles()
+        throws Exception
+    {
+        // REDBACK-29
+        // user should not be able to see the other project admin role of user2, but should be able to see the one
+        // from their own group
+
+        rbacManager.removeUserAssignment( "user" );
+        rbacManager.removeUserAssignment( "user2" );
+
+        addAssignment( "user", "Project Administrator - default" );
+        addAssignment( "user", "User Administrator" );
+        addAssignment( "user", "Grant Administrator" );
+
+        addAssignment( "user2", "Project Administrator - default" );
+        addAssignment( "user2", "Project Administrator - other" );
+
+        UserEditAction action = (UserEditAction) getActionProxy( "/security/useredit" ).getAction();
+        login( action, "user", PASSWORD );
+
+        action.setUsername( "user2" );
+        assertEquals( Action.INPUT, action.edit() );
+
+        List<Role> effectivelyAssignedRoles = action.getEffectivelyAssignedRoles();
+        assertEquals( 2, effectivelyAssignedRoles.size() );
+        Role r = effectivelyAssignedRoles.get( 0 );
+        assertEquals( "Project Administrator - default", r.getName() );
+        //assertTrue( action.isHasHiddenRoles() );
+
+        rbacManager.removeUserAssignment( "user" );
+        rbacManager.removeUserAssignment( "user2" );
+    }
+
+    @Test
+    public void testEditPageHidesUnassignableRoles()
+        throws RbacObjectInvalidException, RbacManagerException, AccountLockedException, AuthenticationException,
+        UserNotFoundException, MustChangePasswordException
+    {
+        // REDBACK-201
+        // user should not be able to see the unassignable roles 
+
+        try
+        {
+            if ( rbacManager.getUserAssignment( "user" ) != null )
+            {
+                rbacManager.removeUserAssignment( "user" );
+            }
+        }
+        catch ( RbacObjectNotFoundException e )
+        {
+            // ignore
+        }
+
+        addAssignment( "user", "User Administrator" );
+
+        UserEditAction action = (UserEditAction) getActionProxy( "/security/useredit" ).getAction();
+        login( action, "user", PASSWORD );
+
+        action.setUsername( "user" );
+        assertEquals( Action.INPUT, action.edit() );
+
+        List<Role> effectivelyAssignedRoles = action.getEffectivelyAssignedRoles();
+        assertEquals( 1, effectivelyAssignedRoles.size() );
+        Role r = effectivelyAssignedRoles.get( 0 );
+        assertEquals( "User Administrator", r.getName() );
+        assertFalse( action.isHasHiddenRoles() );
+
+        rbacManager.removeUserAssignment( "user" );
+    }
+
+    @Test
+    public void testRequireOldPWWhenEditingOwnAccountSuccess()
+        throws Exception
+    {
+        addAssignment( "user", "User Administrator" );
+
+        UserEditAction action = (UserEditAction) getActionProxy( "/security/useredit" ).getAction();
+        login( action, "user", PASSWORD );
+
+        action.setUsername( "user" );
+        assertEquals( Action.INPUT, action.edit() );
+
+        assertTrue( action.isSelf() );
+
+        AdminEditUserCredentials user = action.getUser();
+        user.setEmail( "user@example.com" );
+        user.setFullName( "User" );
+        action.setOldPassword( PASSWORD );
+
+        Map<String, Object> mockSession = new HashMap<String, Object>();
+
+        User currentUser = new SimpleUser();
+        currentUser.setUsername( "user" );
+
+        AuthenticationResult authResult = new AuthenticationResult( true, "user", null );
+        SecuritySession securitySession = new DefaultSecuritySession( authResult, currentUser );
+
+        mockSession.put( SecuritySystemConstants.SECURITY_SESSION_KEY, securitySession );
+        action.setSession( mockSession );
+
+        assertEquals( Action.SUCCESS, action.submit() );
+
+        assertEquals( 0, action.getFieldErrors().size() );
+    }
+
+    @Test
+    public void testRequireOldPWWhenEditingOwnAccountFailed()
+        throws Exception
+    {
+        addAssignment( "user", "User Administrator" );
+
+        UserEditAction action = (UserEditAction) getActionProxy( "/security/useredit" ).getAction();
+        login( action, "user", PASSWORD );
+
+        action.setUsername( "user" );
+        assertEquals( Action.INPUT, action.edit() );
+
+        assertTrue( action.isSelf() );
+
+        AdminEditUserCredentials user = action.getUser();
+        user.setEmail( "user@example.com" );
+        user.setFullName( "User" );
+        user.setPassword( PASSWORD );
+        user.setConfirmPassword( PASSWORD );
+
+        action.setOldPassword( "notmatchingoldpassword" );
+
+        assertEquals( Action.ERROR, action.submit() );
+
+        Map<String, List<String>> fieldErrors = action.getFieldErrors();
+        List<String> oldPasswordErrors = fieldErrors.get( "oldPassword" );
+
+        assertNotNull( oldPasswordErrors );
+        assertEquals( 1, oldPasswordErrors.size() );
+
+        assertEquals( action.getText( "password.provided.does.not.match.existing" ), oldPasswordErrors.get( 0 ) );
+
+        rbacManager.removeUserAssignment( "user" );
+    }
+
+    @Test
+    public void testRequireOldPWWhenEditingOwnAccountOldPasswordIsNull()
+        throws Exception
+    {
+        addAssignment( "user", "User Administrator" );
+
+        UserEditAction action = (UserEditAction) getActionProxy( "/security/useredit" ).getAction();
+        login( action, "user", PASSWORD );
+
+        action.setUsername( "user" );
+        assertEquals( Action.INPUT, action.edit() );
+
+        assertTrue( action.isSelf() );
+
+        AdminEditUserCredentials user = action.getUser();
+        user.setEmail( "user@example.com" );
+        user.setFullName( "User" );
+        user.setPassword( PASSWORD );
+        user.setConfirmPassword( PASSWORD );
+
+        action.setOldPassword( null );
+
+        assertEquals( Action.ERROR, action.submit() );
+
+        Map<String, List<String>> fieldErrors = action.getFieldErrors();
+        List<String> oldPasswordErrors = fieldErrors.get( "oldPassword" );
+
+        assertNotNull( oldPasswordErrors );
+        assertEquals( 1, oldPasswordErrors.size() );
+
+        assertEquals( action.getText( "old.password.required" ), oldPasswordErrors.get( 0 ) );
+
+        rbacManager.removeUserAssignment( "user" );
+
+    }
+
+    @Test
+    public void testRequireAdminPWWhenEditingOtherAccountPWIncorrect()
+        throws Exception
+    {
+        addAssignment( "user", "User Administrator" );
+
+        UserEditAction action = (UserEditAction) getActionProxy( "/security/useredit" ).getAction();
+        login( action, "user", PASSWORD );
+
+        action.setUsername( "user2" );
+
+        assertEquals( Action.INPUT, action.edit() );
+
+        assertFalse( action.isSelf() );
+
+        AdminEditUserCredentials user = action.getUser();
+        user.setEmail( "user2@example.com" );
+        user.setFullName( "User2" );
+        user.setPassword( PASSWORD );
+        user.setConfirmPassword( PASSWORD );
+
+        assertEquals( UserEditAction.CONFIRM, action.submit() );
+
+        assertFalse( action.isSelf() );
+
+        action.setUserAdminPassword( "boguspassword" );
+
+        assertEquals( UserEditAction.CONFIRM_ERROR, action.confirmAdminPassword() );
+
+        Collection<String> errors = action.getActionErrors();
+
+        assertNotNull( errors );
+        assertEquals( 1, errors.size() );
+
+        assertEquals( action.getText( "user.admin.password.does.not.match.existing" ), errors.iterator().next() );
+
+        rbacManager.removeUserAssignment( "user" );
+    }
+
+    @Test
+    public void testRequireAdminPWWhenEditingOtherAccountPWEmpty()
+        throws Exception
+    {
+        addAssignment( "user", "User Administrator" );
+
+        UserEditAction action = (UserEditAction) getActionProxy( "/security/useredit" ).getAction();
+        login( action, "user", PASSWORD );
+
+        action.setUsername( "user2" );
+        assertEquals( Action.INPUT, action.edit() );
+
+        assertFalse( action.isSelf() );
+
+        AdminEditUserCredentials user = action.getUser();
+        user.setEmail( "user2@example.com" );
+        user.setFullName( "User2" );
+        user.setPassword( PASSWORD );
+        user.setConfirmPassword( PASSWORD );
+
+        action.setUserAdminPassword( "" );
+
+        assertEquals( UserEditAction.CONFIRM, action.submit() );
+
+        assertFalse( action.isSelf() );
+
+        assertEquals( UserEditAction.CONFIRM_ERROR, action.confirmAdminPassword() );
+
+        Collection<String> errors = action.getActionErrors();
+
+        assertNotNull( errors );
+        assertEquals( 1, errors.size() );
+
+        assertEquals( action.getText( "user.admin.password.required" ), errors.iterator().next() );
+
+        rbacManager.removeUserAssignment( "user" );
+    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditActionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/CustomInterceptorTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/CustomInterceptorTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/CustomInterceptorTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/CustomInterceptorTest.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,56 @@
+/**
+ *
+ */
+package org.codehaus.plexus.redback.struts2.interceptor;
+
+/*
+ * Copyright 2006-2007 The Codehaus 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 junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+
+/**
+ *
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ */
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+public class CustomInterceptorTest
+    extends TestCase
+{
+
+    @Inject @Named(value = "testCustomInterceptor")
+    MockCustomInterceptor component;
+
+    /**
+     *
+     * @throws Exception on errors
+     */
+    @Test
+    public void testLookup()
+        throws Exception
+    {
+        assertNotNull( component );
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/CustomInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/CustomInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponent.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponent.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponent.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponent.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,27 @@
+package org.codehaus.plexus.redback.struts2.interceptor;
+
+/*
+ * Copyright 2006-2007 The Codehaus 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:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ */
+public interface MockComponent
+{
+    String ROLE = MockComponent.class.getName();
+
+    void displayResult( String result );
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponent.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponentImpl.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponentImpl.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponentImpl.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponentImpl.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,43 @@
+package org.codehaus.plexus.redback.struts2.interceptor;
+
+/*
+ * Copyright 2006-2007 The Codehaus 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.springframework.stereotype.Service;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ */
+@Service
+public class MockComponentImpl
+    implements MockComponent
+{
+    private String result;
+
+    /* (non-Javadoc)
+    * @see org.codehaus.plexus.xwork.interceptor.TestComponent#execute()
+    */
+    public void displayResult( String result )
+    {
+        this.result = result;
+    }
+
+    public String getResult()
+    {
+        return result;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponentImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockComponentImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockCustomInterceptor.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockCustomInterceptor.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockCustomInterceptor.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockCustomInterceptor.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,88 @@
+package org.codehaus.plexus.redback.struts2.interceptor;
+
+/*
+ * Copyright 2006-2007 The Codehaus 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 com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.Interceptor;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ */
+@Service("testCustomInterceptor")
+public class MockCustomInterceptor
+    implements Interceptor
+{
+    /**
+     *
+     */
+    @Inject
+    private MockComponent testComponent;
+
+    public MockCustomInterceptor()
+    {
+    }
+
+    public MockCustomInterceptor( MockComponent testComponent )
+    {
+        this.testComponent = testComponent;
+    }
+
+    /* (non-Javadoc)
+     * @see com.opensymphony.xwork2.interceptor.Interceptor#destroy()
+     */
+    public void destroy()
+    {
+        // do nothing
+    }
+
+    /* (non-Javadoc)
+     * @see com.opensymphony.xwork2.interceptor.Interceptor#init()
+     */
+    public void init()
+    {
+        // do nothing
+    }
+
+    /**
+     * @noinspection ProhibitedExceptionDeclared
+     */
+    public String intercept( ActionInvocation invocation )
+        throws Exception
+    {
+        String result = "Hello Custom Interceptor";
+
+        testComponent.displayResult( result );
+
+        return result;
+    }
+
+    public MockComponent getTestComponent()
+    {
+        return testComponent;
+    }
+
+    // Introduce a Composition Exception , see PLX - 278 
+    //    public void setTestComponent( MockComponent testComponent )
+    //    {
+    //        this.testComponent = testComponent;
+    //    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockCustomInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/interceptor/MockCustomInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message