You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/04/06 11:59:32 UTC
svn commit: r1310268 [22/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...
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleCreateAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleCreateAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleCreateAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleCreateAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,229 @@
+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.codehaus.plexus.redback.rbac.Permission;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.rbac.Role;
+import org.codehaus.plexus.redback.struts2.action.AbstractSecurityAction;
+import org.codehaus.plexus.redback.struts2.action.AuditEvent;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.model.SimplePermission;
+import org.codehaus.redback.integration.role.RoleConstants;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * RoleCreateAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-role-create" )
+@Scope( "prototype" )
+public class RoleCreateAction
+ extends AbstractSecurityAction
+{
+ // ------------------------------------------------------------------
+ // Component Requirements
+ // ------------------------------------------------------------------
+
+ /**
+ * role-hint="cached"
+ */
+ @Inject
+ @Named( value = "rBACManager#cached" )
+ private RBACManager manager;
+
+ // ------------------------------------------------------------------
+ // Action Parameters
+ // ------------------------------------------------------------------
+
+ private String principal;
+
+ private String roleName;
+
+ private String description;
+
+ private List<SimplePermission> permissions;
+
+ private List<String> childRoles;
+
+ private SimplePermission addpermission;
+
+ private String submitMode;
+
+ protected static final String VALID_ROLENAME_CHARS = "[a-zA-Z_0-9\\-\\s.,]*";
+
+ // ------------------------------------------------------------------
+ // Action Entry Points - (aka Names)
+ // ------------------------------------------------------------------
+
+ public String show()
+ {
+ if ( permissions == null )
+ {
+ permissions = new ArrayList<SimplePermission>();
+ }
+
+ if ( childRoles == null )
+ {
+ childRoles = new ArrayList<String>();
+ }
+
+ if ( addpermission == null )
+ {
+ addpermission = new SimplePermission();
+ }
+
+ return INPUT;
+ }
+
+ public String addpermission()
+ {
+ if ( addpermission == null )
+ {
+ addActionError( getText( "cannot.add.null.permission" ) );
+ return ERROR;
+ }
+
+ if ( permissions == null )
+ {
+ permissions = new ArrayList<SimplePermission>();
+ }
+
+ permissions.add( addpermission );
+
+ addpermission = new SimplePermission();
+
+ return INPUT;
+ }
+
+ public String submit()
+ {
+ if ( StringUtils.equals( getSubmitMode(), "addPermission" ) )
+ {
+ return addpermission();
+ }
+
+ if ( StringUtils.isEmpty( roleName ) )
+ {
+ addActionError( getText( "cannot.add.empty.role" ) );
+ return ERROR;
+ }
+ if ( !roleName.matches( VALID_ROLENAME_CHARS ) )
+ {
+ addActionError( getText( "roleName.invalid.characters" ) );
+ return ERROR;
+ }
+
+ try
+ {
+ Role _role;
+ if ( manager.roleExists( roleName ) )
+ {
+ _role = manager.getRole( roleName );
+ }
+ else
+ {
+ _role = manager.createRole( roleName );
+ }
+
+ _role.setDescription( description );
+ _role.setChildRoleNames( childRoles );
+
+ List<Permission> _permissionList = new ArrayList<Permission>();
+ for ( SimplePermission perm : permissions )
+ {
+ _permissionList.add(
+ manager.createPermission( perm.getName(), perm.getOperationName(), perm.getResourceIdentifier() ) );
+ }
+
+ _role.setPermissions( _permissionList );
+
+ manager.saveRole( _role );
+
+ addActionMessage( getText( "save.role.success", Arrays.asList( (Object) roleName ) ) );
+ String currentUser = getCurrentUser();
+ AuditEvent event = new AuditEvent( getText( "log.role.create" ) );
+ event.setRole( roleName );
+ event.setCurrentUser( currentUser );
+ event.log();
+ }
+ catch ( RbacManagerException e )
+ {
+ addActionError( getText( "cannot.get.role", Arrays.asList( (Object) roleName, e.getMessage() ) ) );
+ return ERROR;
+ }
+
+ return SUCCESS;
+ }
+
+ // ------------------------------------------------------------------
+ // Parameter Accessor Methods
+ // ------------------------------------------------------------------
+
+ public String getPrincipal()
+ {
+ return principal;
+ }
+
+ public void setPrincipal( String principal )
+ {
+ this.principal = principal;
+ }
+
+ public SimplePermission getAddpermission()
+ {
+ return addpermission;
+ }
+
+ public void setAddpermission( SimplePermission addpermission )
+ {
+ this.addpermission = addpermission;
+ }
+
+ public String getSubmitMode()
+ {
+ return submitMode;
+ }
+
+ public void setSubmitMode( String submitMode )
+ {
+ this.submitMode = submitMode;
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION, Resource.GLOBAL );
+ return bundle;
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleCreateAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleCreateAction.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleModelAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleModelAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleModelAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleModelAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,75 @@
+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.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.role.RoleManager;
+import org.codehaus.plexus.redback.role.model.RedbackRoleModel;
+import org.codehaus.plexus.redback.struts2.action.AbstractSecurityAction;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.role.RoleConstants;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+
+/**
+ * RolesAction
+ *
+ * @author <a href="mailto:jmcconnell@apache.org">Jesse McConnell</a>
+ * @version $Id$
+ */
+@Controller( "redback-role-model" )
+@Scope( "prototype" )
+public class RoleModelAction
+ extends AbstractSecurityAction
+{
+ /**
+ * role-hint="default"
+ */
+ @Inject
+ private RoleManager manager;
+
+ private RedbackRoleModel model;
+
+ public String view()
+ {
+ model = manager.getModel();
+
+ return SUCCESS;
+ }
+
+ public RedbackRoleModel getModel()
+ {
+ return model;
+ }
+
+ public void setModel( RedbackRoleModel model )
+ {
+ this.model = model;
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION, Resource.GLOBAL );
+ return bundle;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleModelAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RoleModelAction.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RolesAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RolesAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RolesAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RolesAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,88 @@
+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.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.rbac.Role;
+import org.codehaus.plexus.redback.struts2.action.AbstractUserCredentialsAction;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.role.RoleConstants;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * RolesAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-roles" )
+@Scope( "prototype" )
+public class RolesAction
+ extends AbstractUserCredentialsAction
+{
+ private static final String LIST = "list";
+
+ private List<Role> allRoles;
+
+ public String list()
+ {
+ try
+ {
+ allRoles = getFilteredRolesForCurrentUserAccess();
+ }
+ catch ( RbacManagerException e )
+ {
+ List<Object> list = new ArrayList<Object>();
+ list.add( e.getMessage() );
+ addActionError( getText( "cannot.list.all.roles", list ) );
+ log.error( "System error:", e );
+ allRoles = Collections.emptyList();
+ }
+
+ return LIST;
+ }
+
+ public List<Role> getAllRoles()
+ {
+ return allRoles;
+ }
+
+ public void setAllRoles( List<Role> allRoles )
+ {
+ this.allRoles = allRoles;
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_ROLE_GRANT_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_ROLE_DROP_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_ROLE_OPERATION, Resource.GLOBAL );
+ return bundle;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RolesAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/RolesAction.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,271 @@
+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.commons.beanutils.PropertyUtils;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.struts2.action.AbstractSecurityAction;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.registry.Registry;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.role.RoleConstants;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * SystemInfoAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-sysinfo" )
+@Scope( "prototype" )
+public class SystemInfoAction
+ extends AbstractSecurityAction
+{
+ // ------------------------------------------------------------------
+ // Component Requirements
+ // ------------------------------------------------------------------
+
+ /**
+ *
+ */
+ @Inject
+ private SecuritySystem securitySystem;
+
+ /**
+ * role-hint="commons-configuration"
+ */
+ @Inject
+ @Named( value = "commons-configuration" )
+ private Registry registry;
+
+ /**
+ * role-hint="cached"
+ */
+ @Inject
+ @Named( value = "rBACManager#cached" )
+ private RBACManager rbacManager;
+
+ // Class.getClass() and some JPOX classes
+ private static final List<String> ignoredReaders = Arrays.asList( "class", "copy" );
+
+ private static final String NULL = "<null>";
+
+ private static final char LN = Character.LINE_SEPARATOR;
+
+ private static final String INDENT = " ";
+
+ private static final int MAXDEPTH = 10;
+
+ // ------------------------------------------------------------------
+ // Action Parameters
+ // ------------------------------------------------------------------
+
+ private StringBuilder details;
+
+ // ------------------------------------------------------------------
+ // Action Entry Points - (aka Names)
+ // ------------------------------------------------------------------
+
+ public String show()
+ {
+ details = new StringBuilder();
+
+ details.append( "Configuration: " );
+ dumpObject( details, registry, INDENT );
+ details.append( registry.dump() );
+ details.append( LN );
+
+ details.append( LN ).append( "<hr/>" ).append( LN );
+ details.append( "RBAC Manager: " );
+ dumpObject( details, rbacManager, INDENT );
+
+ details.append( LN ).append( "<hr/>" ).append( LN );
+ details.append( "SecuritySystem: " );
+ dumpObject( details, securitySystem, INDENT );
+
+ return SUCCESS;
+ }
+
+ private void dumpObject( StringBuilder sb, Object obj, String indent )
+ {
+ dumpObjectSwitchboard( new ArrayList<Object>(), sb, obj, indent, 0 );
+ }
+
+ /**
+ * The recursive object dumping switchboard.
+ *
+ * @param seenObjects objects already seen (to prevent cycles)
+ * @param sb the stringbuffer to populate
+ * @param obj the object to dump
+ * @param indent the current indent string.
+ * @param depth the depth in the tree.
+ */
+ private void dumpObjectSwitchboard( List<Object> seenObjects, StringBuilder sb, Object obj, String indent,
+ int depth )
+ {
+ if ( obj == null )
+ {
+ sb.append( NULL ).append( LN );
+ return;
+ }
+
+ if ( depth > MAXDEPTH )
+ {
+ sb.append( StringEscapeUtils.escapeHtml( "<MAX DEPTH>" ) );
+ sb.append( LN );
+ return;
+ }
+
+ depth++;
+
+ String className = obj.getClass().getName();
+
+ sb.append( '(' ).append( className ).append( ") " );
+
+ if ( obj instanceof List )
+ {
+ dumpIterator( seenObjects, sb, ( (List<?>) obj ).iterator(), indent, depth );
+ }
+ else if ( obj instanceof Set )
+ {
+ dumpIterator( seenObjects, sb, ( (Set<?>) obj ).iterator(), indent, depth );
+ }
+ else if ( obj instanceof Map )
+ {
+ dumpIterator( seenObjects, sb, ( (Map<?, ?>) obj ).entrySet().iterator(), indent, depth );
+ }
+ else if ( obj instanceof Iterator )
+ {
+ dumpIterator( seenObjects, sb, (Iterator<?>) obj, indent, depth );
+ }
+ else
+ {
+ // Filter classes that start with java or javax
+ if ( className.startsWith( "java." ) || className.startsWith( "javax." ) )
+ {
+ sb.append( StringEscapeUtils.escapeHtml( obj.toString() ) ).append( LN );
+ return;
+ }
+
+ // prevent cycles
+ if ( seenObjects.contains( obj ) )
+ {
+ // No need to dump.
+ sb.append( StringEscapeUtils.escapeHtml( "<seen already preventing cycle in dump> " ) );
+ sb.append( LN );
+ return;
+ }
+
+ // Adding object to seen list (to prevent cycles)
+ seenObjects.add( obj );
+
+ dumpObjectReaders( seenObjects, sb, obj, indent, depth );
+ }
+ depth--;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private void dumpObjectReaders( List<Object> seenObjects, StringBuilder sb, Object obj, String indent, int depth )
+ {
+ sb.append( obj.toString() ).append( LN );
+ String name = null;
+
+ try
+ {
+ Map<String, Object> readers = PropertyUtils.describe( obj );
+ for ( Map.Entry<String, Object> readerEntry : readers.entrySet() )
+ {
+ name = (String) readerEntry.getKey();
+
+ if ( ignoredReaders.contains( name ) )
+ {
+ // skip this reader.
+ continue;
+ }
+
+ sb.append( indent );
+ sb.append( name ).append( ':' );
+
+ Object value = readerEntry.getValue();
+ if ( value == null )
+ {
+ sb.append( NULL ).append( LN );
+ }
+ else
+ {
+ dumpObjectSwitchboard( seenObjects, sb, value, INDENT + indent, depth );
+ }
+ }
+ }
+ catch ( Throwable e )
+ {
+ sb.append( LN ).append( indent );
+ sb.append( "Unable to read bean [" ).append( obj.getClass().getName() );
+ if ( StringUtils.isNotBlank( name ) )
+ {
+ sb.append( ".get" ).append( StringUtils.capitalize( name ) ).append( "()" );
+ }
+ sb.append( "]: " ).append( '(' ).append( e.getClass().getName() ).append( ") " );
+ sb.append( e.getMessage() ).append( LN );
+ }
+ }
+
+ private void dumpIterator( List<Object> seenObjects, StringBuilder sb, Iterator<?> iterator, String indent,
+ int depth )
+ {
+ sb.append( LN );
+ while ( iterator.hasNext() )
+ {
+ Object entry = iterator.next();
+ sb.append( indent );
+ dumpObjectSwitchboard( seenObjects, sb, entry, indent + " | ", depth );
+ }
+ }
+
+ // ------------------------------------------------------------------
+ // Parameter Accessor Methods
+ // ------------------------------------------------------------------
+
+ public String getDetails()
+ {
+ return details.toString();
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.CONFIGURATION_EDIT_OPERATION, Resource.GLOBAL );
+ return bundle;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoAction.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserCreateAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserCreateAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserCreateAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserCreateAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,145 @@
+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 java.util.Arrays;
+
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
+import org.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.struts2.action.AbstractUserCredentialsAction;
+import org.codehaus.plexus.redback.struts2.action.AuditEvent;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.model.CreateUserCredentials;
+import org.codehaus.redback.integration.role.RoleConstants;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+/**
+ * UserCreateAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller("redback-admin-user-create")
+@Scope("prototype")
+public class UserCreateAction
+ extends AbstractUserCredentialsAction
+{
+ // ------------------------------------------------------------------
+ // Action Parameters
+ // ------------------------------------------------------------------
+
+ private CreateUserCredentials user;
+
+ // ------------------------------------------------------------------
+ // Action Entry Points - (aka Names)
+ // ------------------------------------------------------------------
+
+ public String show()
+ {
+ if ( user == null )
+ {
+ user = new CreateUserCredentials();
+ }
+
+ return INPUT;
+ }
+
+ public String submit()
+ {
+ if ( user == null )
+ {
+ user = new CreateUserCredentials();
+ addActionError( getText( "invalid.user.credentials" ) );
+ return ERROR;
+ }
+
+ internalUser = user;
+
+ validateCredentialsLoose();
+
+ // NOTE: Do not perform Password Rules Validation Here.
+
+ UserManager manager = super.securitySystem.getUserManager();
+
+ if ( manager.userExists( user.getUsername() ) )
+ {
+ // Means that the role name doesn't exist.
+ // We need to fail fast and return to the previous page.
+ addActionError( getText( "user.already.exists", Arrays.asList( ( Object ) user.getUsername() ) ) );
+ }
+
+ if ( hasActionErrors() || hasFieldErrors() )
+ {
+ return ERROR;
+ }
+
+ User u = manager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
+ u.setPassword( user.getPassword() );
+
+ // force the user to change their password when they log in next
+ u.setPasswordChangeRequired( true );
+
+ // Disable Password Rules for this creation.
+ UserSecurityPolicy securityPolicy = securitySystem.getPolicy();
+ try
+ {
+ // REDBACK-156
+ securityPolicy.setEnabled( false );
+ u.setValidated( true );
+ manager.addUser( u );
+ String currentUser = getCurrentUser();
+ AuditEvent event = new AuditEvent( getText( "log.account.create" ) );
+ event.setAffectedUser( u.getUsername() );
+ event.setCurrentUser( currentUser );
+ event.log();
+ }
+ finally
+ {
+ securityPolicy.setEnabled( true );
+ }
+
+ return SUCCESS;
+ }
+
+ // ------------------------------------------------------------------
+ // Parameter Accessor Methods
+ // ------------------------------------------------------------------
+
+ public CreateUserCredentials getUser()
+ {
+ return user;
+ }
+
+ public void setUser( CreateUserCredentials user )
+ {
+ this.user = user;
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_CREATE_OPERATION, Resource.GLOBAL );
+ return bundle;
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserCreateAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserCreateAction.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserDeleteAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserDeleteAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserDeleteAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserDeleteAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,199 @@
+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.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.RbacObjectNotFoundException;
+import org.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.struts2.action.AbstractSecurityAction;
+import org.codehaus.plexus.redback.struts2.action.AuditEvent;
+import org.codehaus.plexus.redback.struts2.action.CancellableAction;
+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.util.StringUtils;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.role.RoleConstants;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.Arrays;
+
+/**
+ * UserDeleteAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-admin-user-delete" )
+@Scope( "prototype" )
+public class UserDeleteAction
+ extends AbstractSecurityAction
+ implements CancellableAction
+{
+ // ------------------------------------------------------------------
+ // Component Requirements
+ // ------------------------------------------------------------------
+
+ /**
+ * role-hint="configurable"
+ */
+ @Inject
+ @Named( value = "userManager#configurable" )
+ private UserManager userManager;
+
+ /**
+ * role-hint="cached"
+ */
+ @Inject
+ @Named( value = "rBACManager#cached" )
+ private RBACManager rbacManager;
+
+ // ------------------------------------------------------------------
+ // Action Parameters
+ // ------------------------------------------------------------------
+
+ private String username;
+
+ private User user;
+
+ // ------------------------------------------------------------------
+ // Action Entry Points - (aka Names)
+ // ------------------------------------------------------------------
+
+ public String confirm()
+ {
+ if ( username == null )
+ {
+ addActionError( getText( "cannot.remove.user.null.username" ) );
+ return SUCCESS;
+ }
+
+ try
+ {
+ user = userManager.findUser( username );
+ }
+ catch ( UserNotFoundException e )
+ {
+ addActionError( getText( "cannot.remove.user.not.found", Arrays.asList( (Object) username ) ) );
+ return SUCCESS;
+ }
+
+ return INPUT;
+ }
+
+ public String submit()
+ {
+ if ( username == null )
+ {
+ addActionError( getText( "invalid.user.credentials" ) );
+ return SUCCESS;
+ }
+
+ if ( StringUtils.isEmpty( username ) )
+ {
+ addActionError( getText( "cannot.remove.user.empty.username" ) );
+ return SUCCESS;
+ }
+
+ try
+ {
+ rbacManager.removeUserAssignment( username );
+ }
+ catch ( RbacObjectNotFoundException e )
+ {
+ // ignore, this is possible since the user may never have had roles assigned
+ }
+ catch ( RbacObjectInvalidException e )
+ {
+ addActionError( getText( "cannot.remove.user.role", Arrays.asList( (Object) username, e.getMessage() ) ) );
+ }
+ catch ( RbacManagerException e )
+ {
+ addActionError( getText( "cannot.remove.user.role", Arrays.asList( (Object) username, e.getMessage() ) ) );
+ }
+
+ if ( getActionErrors().isEmpty() )
+ {
+ try
+ {
+ userManager.deleteUser( username );
+ }
+ catch ( UserNotFoundException e )
+ {
+ addActionError( getText( "cannot.remove.user.non.existent", Arrays.asList( (Object) username ) ) );
+ }
+ }
+ String currentUser = getCurrentUser();
+
+ AuditEvent event = new AuditEvent( getText( "log.account.delete" ) );
+ event.setAffectedUser( username );
+ event.setCurrentUser( currentUser );
+ event.log();
+
+ return SUCCESS;
+ }
+
+ /**
+ * Returns the cancel result. <p/> A basic implementation would simply be to return CANCEL.
+ *
+ * @return
+ */
+ public String cancel()
+ {
+ return CANCEL;
+ }
+
+ // ------------------------------------------------------------------
+ // Parameter Accessor Methods
+ // ------------------------------------------------------------------
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public void setUsername( String username )
+ {
+ this.username = username;
+ }
+
+ public User getUser()
+ {
+ return user;
+ }
+
+ public void setUser( User user )
+ {
+ this.user = user;
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_DELETE_OPERATION, Resource.GLOBAL );
+ return bundle;
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserDeleteAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserDeleteAction.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,408 @@
+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.commons.lang.StringEscapeUtils;
+import org.codehaus.plexus.redback.policy.PasswordEncoder;
+import org.codehaus.plexus.redback.policy.PasswordRuleViolationException;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.rbac.Role;
+import org.codehaus.plexus.redback.struts2.action.AuditEvent;
+import org.codehaus.plexus.redback.struts2.action.CancellableAction;
+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.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.model.AdminEditUserCredentials;
+import org.codehaus.redback.integration.role.RoleConstants;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * UserEditAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-admin-user-edit" )
+@Scope( "prototype" )
+public class UserEditAction
+ extends AbstractAdminUserCredentialsAction
+ implements CancellableAction
+{
+ /**
+ * role-hint="cached"
+ */
+ @Inject
+ @Named( value = "rBACManager#cached" )
+ private RBACManager rbacManager;
+
+ /**
+ * A List of {@link org.codehaus.plexus.redback.rbac.Role} objects.
+ */
+ private List<Role> effectivelyAssignedRoles;
+
+ // ------------------------------------------------------------------
+ // Action Parameters
+ // ------------------------------------------------------------------
+
+ private AdminEditUserCredentials user;
+
+ private String updateButton;
+
+ private boolean emailValidationRequired;
+
+ private boolean hasHiddenRoles;
+
+ private String oldPassword;
+
+ private String userAdminPassword;
+
+ private boolean self;
+
+ public static String CONFIRM = "confirm";
+
+ public static String CONFIRM_ERROR = "confirmError";
+
+ // ------------------------------------------------------------------
+ // Action Entry Points - (aka Names)
+ // ------------------------------------------------------------------
+
+ public String edit()
+ {
+ oldPassword = "";
+
+ emailValidationRequired = securitySystem.getPolicy().getUserValidationSettings().isEmailValidationRequired();
+
+ if ( getUsername() == null )
+ {
+ addActionError( getText( "cannot.edit.user.null.username" ) );
+ return ERROR;
+ }
+
+ if ( StringUtils.isEmpty( getUsername() ) )
+ {
+ addActionError( getText( "cannot.edit.user.empty.username" ) );
+ return ERROR;
+ }
+
+ UserManager manager = super.securitySystem.getUserManager();
+
+ String escapedUsername = StringEscapeUtils.escapeXml( getUsername() );
+
+ if ( !manager.userExists( escapedUsername ) )
+ {
+ // Means that the role name doesn't exist.
+ // We need to fail fast and return to the previous page.
+ addActionError( getText( "user.does.not.exist", Collections.singletonList( (Object) escapedUsername ) ) );
+ return ERROR;
+ }
+
+ try
+ {
+ User u = manager.findUser( escapedUsername );
+
+ if ( u == null )
+ {
+ addActionError( getText( "cannot.operate.on.null.user" ) );
+ return ERROR;
+ }
+
+ user = new AdminEditUserCredentials( u );
+
+ // require user admin to provide his/her password if editing account of others
+ if ( getUsername().equals( getCurrentUser() ) )
+ {
+ self = true;
+ }
+
+ try
+ {
+ String principal = u.getPrincipal().toString();
+ List<Role> roles = filterAssignableRoles( rbacManager.getEffectivelyAssignedRoles( principal ) );
+ effectivelyAssignedRoles = filterRolesForCurrentUserAccess( roles );
+ hasHiddenRoles = ( roles.size() > effectivelyAssignedRoles.size() );
+ }
+ catch ( RbacManagerException rme )
+ {
+ // ignore, this can happen when the user has no roles assigned
+ }
+ }
+ catch ( UserNotFoundException e )
+ {
+ addActionError( getText( "cannot.get.user", Arrays.asList( (Object) getUsername(), e.getMessage() ) ) );
+ return ERROR;
+ }
+
+ return INPUT;
+ }
+
+ private List<Role> filterAssignableRoles( Collection<Role> roles )
+ {
+ List<Role> assignableRoles = new ArrayList<Role>( roles.size() );
+ for ( Role r : roles )
+ {
+ if ( r.isAssignable() )
+ {
+ assignableRoles.add( r );
+ }
+ }
+ return assignableRoles;
+ }
+
+ public String submit()
+ {
+ if ( getUsername() == null )
+ {
+ addActionError( getText( "cannot.edit.user.null.username" ) );
+ return ERROR;
+ }
+
+ if ( StringUtils.isEmpty( getUsername() ) )
+ {
+ addActionError( getText( "cannot.edit.user.empty.username" ) );
+ return ERROR;
+ }
+
+ if ( user == null )
+ {
+ addActionError( getText( "cannot.edit.user.null.credentials" ) );
+ return ERROR;
+ }
+
+ internalUser = user;
+
+ validateCredentialsLoose();
+
+ // if form errors, return with them before continuing
+ if ( hasActionErrors() || hasFieldErrors() )
+ {
+ return ERROR;
+ }
+
+ if ( !getUsername().equals( getCurrentUser() ) )
+ {
+ return CONFIRM;
+ }
+ else
+ {
+ return save( true );
+ }
+ }
+
+ // confirm user admin's password before allowing to proceed with the operation
+ public String confirmAdminPassword()
+ {
+ UserManager manager = super.securitySystem.getUserManager();
+
+ if ( StringUtils.isEmpty( userAdminPassword ) )
+ {
+ addActionError( getText( "user.admin.password.required" ) );
+ return CONFIRM_ERROR;
+ }
+
+ try
+ {
+ User currentUser = manager.findUser( getCurrentUser() );
+
+ // check if user admin provided correct password!
+ PasswordEncoder encoder = securitySystem.getPolicy().getPasswordEncoder();
+ if ( !encoder.isPasswordValid( currentUser.getEncodedPassword(), userAdminPassword ) )
+ {
+ addActionError( getText( "user.admin.password.does.not.match.existing" ) );
+ return CONFIRM_ERROR;
+ }
+ }
+ catch ( UserNotFoundException e )
+ {
+ addActionError( getText( "cannot.find.user", Arrays.asList( (Object) getCurrentUser(), e.getMessage() ) ) );
+ return CONFIRM_ERROR;
+ }
+
+ return save( false );
+ }
+
+ public String cancel()
+ {
+ return CANCEL;
+ }
+
+ private String save( boolean validateOldPassword )
+ {
+ UserManager manager = super.securitySystem.getUserManager();
+
+ if ( !manager.userExists( getUsername() ) )
+ {
+ // Means that the role name doesn't exist.
+ // We need to fail fast and return to the previous page.
+ addActionError( getText( "user.does.not.exist", Collections.singletonList( (Object) getUsername() ) ) );
+ return ERROR;
+ }
+
+ try
+ {
+ User u = manager.findUser( getUsername() );
+ if ( u == null )
+ {
+ addActionError( getText( "cannot.operate.on.null.user" ) );
+ return ERROR;
+ }
+
+ if ( validateOldPassword )
+ {
+ PasswordEncoder encoder = securitySystem.getPolicy().getPasswordEncoder();
+
+ if ( StringUtils.isEmpty( oldPassword ) )
+ {
+ self = true;
+ addFieldError( "oldPassword", getText( "old.password.required" ) );
+ return ERROR;
+ }
+
+ if ( !encoder.isPasswordValid( u.getEncodedPassword(), oldPassword ) )
+ {
+ self = true;
+ addFieldError( "oldPassword", getText( "password.provided.does.not.match.existing" ) );
+ return ERROR;
+ }
+ }
+
+ u.setFullName( user.getFullName() );
+ u.setEmail( user.getEmail() );
+ u.setPassword( user.getPassword() );
+ u.setLocked( user.isLocked() );
+ u.setPasswordChangeRequired( user.isPasswordChangeRequired() );
+
+ manager.updateUser( u, user.isPasswordChangeRequired() );
+
+ //check if current user then update the session
+ if ( getSecuritySession().getUser().getUsername().equals( u.getUsername() ) )
+ {
+ SecuritySession securitySession =
+ new DefaultSecuritySession( getSecuritySession().getAuthenticationResult(), u );
+
+ session.put( SecuritySystemConstants.SECURITY_SESSION_KEY, securitySession );
+
+ setSession( session );
+ }
+ }
+ catch ( UserNotFoundException e )
+ {
+ addActionError( getText( "cannot.find.user", Arrays.asList( (Object) getUsername(), e.getMessage() ) ) );
+ return ERROR;
+ }
+ catch ( PasswordRuleViolationException pe )
+ {
+ processPasswordRuleViolations( pe );
+ return ERROR;
+ }
+ String currentUser = getCurrentUser();
+
+ AuditEvent event = new AuditEvent( getText( "log.account.edit" ) );
+ event.setAffectedUser( getUsername() );
+ event.setCurrentUser( currentUser );
+ event.log();
+
+ return SUCCESS;
+ }
+
+ // ------------------------------------------------------------------
+ // Parameter Accessor Methods
+ // ------------------------------------------------------------------
+
+
+ public String getUpdateButton()
+ {
+ return updateButton;
+ }
+
+ public void setUpdateButton( String updateButton )
+ {
+ this.updateButton = updateButton;
+ }
+
+ public AdminEditUserCredentials getUser()
+ {
+ return user;
+ }
+
+ public void setUser( AdminEditUserCredentials user )
+ {
+ this.user = user;
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION, getUsername() );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_ROLE_OPERATION, Resource.GLOBAL );
+ return bundle;
+ }
+
+ public List<Role> getEffectivelyAssignedRoles()
+ {
+ return effectivelyAssignedRoles;
+ }
+
+ public boolean isEmailValidationRequired()
+ {
+ return emailValidationRequired;
+ }
+
+ public boolean isHasHiddenRoles()
+ {
+ return hasHiddenRoles;
+ }
+
+ public void setHasHiddenRoles( boolean hasHiddenRoles )
+ {
+ this.hasHiddenRoles = hasHiddenRoles;
+ }
+
+ public void setOldPassword( String oldPassword )
+ {
+ this.oldPassword = oldPassword;
+ }
+
+ public void setUserAdminPassword( String userAdminPassword )
+ {
+ this.userAdminPassword = userAdminPassword;
+ }
+
+ public boolean isSelf()
+ {
+ return self;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditAction.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserListAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserListAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserListAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserListAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,274 @@
+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.commons.lang.StringEscapeUtils;
+import org.apache.struts2.ServletActionContext;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.RbacObjectNotFoundException;
+import org.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.rbac.Role;
+import org.codehaus.plexus.redback.rbac.UserAssignment;
+import org.codehaus.plexus.redback.struts2.action.AbstractSecurityAction;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserQuery;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.reports.Report;
+import org.codehaus.redback.integration.reports.ReportManager;
+import org.codehaus.redback.integration.role.RoleConstants;
+import org.extremecomponents.table.context.Context;
+import org.extremecomponents.table.context.HttpServletRequestContext;
+import org.extremecomponents.table.limit.FilterSet;
+import org.extremecomponents.table.limit.Limit;
+import org.extremecomponents.table.limit.LimitFactory;
+import org.extremecomponents.table.limit.TableLimit;
+import org.extremecomponents.table.limit.TableLimitFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * UserListAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-admin-user-list" )
+@Scope( "prototype" )
+public class UserListAction
+ extends AbstractSecurityAction
+{
+ // ------------------------------------------------------------------
+ // Component Requirements
+ // ------------------------------------------------------------------
+
+ /**
+ *
+ */
+ @Inject
+ private SecuritySystem securitySystem;
+
+ /**
+ * role-hint="cached"
+ */
+ @Inject
+ @Named( value = "rBACManager#cached" )
+ private RBACManager rbac;
+
+ /**
+ *
+ */
+ @Inject
+ private ReportManager reportManager;
+
+ // ------------------------------------------------------------------
+ // Action Parameters
+ // ------------------------------------------------------------------
+
+ private List<User> users;
+
+ private List<Role> roles;
+
+ private String roleName;
+
+ // ------------------------------------------------------------------
+ // Action Entry Points - (aka Names)
+ // ------------------------------------------------------------------
+
+ public String show()
+ {
+ try
+ {
+ roles = rbac.getAllRoles();
+ }
+ catch ( RbacManagerException e )
+ {
+ roles = Collections.emptyList();
+ }
+
+ if ( StringUtils.isEmpty( roleName ) )
+ {
+ users = findUsersWithFilter();
+ }
+ else
+ {
+ roleName = StringEscapeUtils.escapeXml( roleName );
+
+ try
+ {
+ Role target = rbac.getRole( roleName );
+ Set<String> targetRoleNames = new HashSet<String>();
+
+ for ( int i = 0; i < roles.size(); i++ )
+ {
+ Role r = roles.get( i );
+ if ( rbac.getEffectiveRoles( r ).contains( target ) )
+ {
+ targetRoleNames.add( r.getName() );
+ }
+ }
+
+ users = findUsers( targetRoleNames );
+ }
+ catch ( RbacObjectNotFoundException e )
+ {
+ users = Collections.emptyList();
+ }
+ catch ( RbacManagerException e )
+ {
+ users = Collections.emptyList();
+ }
+ }
+
+ if ( users == null )
+ {
+ users = Collections.emptyList();
+ }
+
+ return INPUT;
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_LIST_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_ROLE_OPERATION, Resource.GLOBAL );
+ return bundle;
+ }
+
+ private List<User> findUsers( Collection<String> roleNames )
+ {
+ List<String> usernames = getUsernamesForRoles( roleNames );
+ List<User> filteredUsers = new ArrayList<User>();
+
+ for ( User user : findUsersWithFilter() )
+ {
+ if ( usernames.contains( user.getUsername() ) )
+ {
+ filteredUsers.add( user );
+ }
+ }
+
+ return filteredUsers;
+ }
+
+ private List<User> findUsersWithFilter()
+ {
+ Context context = new HttpServletRequestContext( ServletActionContext.getRequest() );
+ LimitFactory limitFactory = new TableLimitFactory( context );
+ Limit limit = new TableLimit( limitFactory );
+ FilterSet filterSet = limit.getFilterSet();
+
+ UserQuery query = getUserManager().createUserQuery();
+ if ( filterSet.getFilter( "username" ) != null )
+ {
+ query.setUsername( filterSet.getFilter( "username" ).getValue() );
+ }
+ if ( filterSet.getFilter( "fullName" ) != null )
+ {
+ query.setFullName( filterSet.getFilter( "fullName" ).getValue() );
+ }
+ if ( filterSet.getFilter( "email" ) != null )
+ {
+ query.setEmail( filterSet.getFilter( "email" ).getValue() );
+ }
+ return getUserManager().findUsersByQuery( query );
+ }
+
+ private List<String> getUsernamesForRoles( Collection<String> roleNames )
+ {
+ Set<String> usernames = new HashSet<String>();
+
+ try
+ {
+ List<UserAssignment> userAssignments = rbac.getUserAssignmentsForRoles( roleNames );
+
+ if ( userAssignments != null )
+ {
+ for ( UserAssignment a : userAssignments )
+ {
+ usernames.add( a.getPrincipal() );
+ }
+ }
+ }
+ catch ( RbacManagerException e )
+ {
+ log.warn( "Unable to get user assignments for roles " + roleNames, e );
+ }
+
+ return new ArrayList<String>( usernames );
+ }
+
+ private UserManager getUserManager()
+ {
+ return securitySystem.getUserManager();
+ }
+
+ // ------------------------------------------------------------------
+ // Parameter Accessor Methods
+ // ------------------------------------------------------------------
+
+ public List<User> getUsers()
+ {
+ return users;
+ }
+
+ public void setUsers( List<User> users )
+ {
+ this.users = users;
+ }
+
+ public String getRoleName()
+ {
+ if ( StringUtils.isEmpty( roleName ) )
+ {
+ return "Any";
+ }
+ return roleName;
+ }
+
+ public void setRoleName( String roleName )
+ {
+ this.roleName = roleName;
+ }
+
+ public List<Role> getRoles()
+ {
+ return roles;
+ }
+
+ public Map<String, Map<String, Report>> getReportMap()
+ {
+ return reportManager.getReportMap();
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserListAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/UserListAction.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/AbstractXworkConfigurationCheck.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/AbstractXworkConfigurationCheck.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/AbstractXworkConfigurationCheck.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/AbstractXworkConfigurationCheck.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,140 @@
+package org.codehaus.plexus.redback.struts2.checks;
+
+/*
+ * 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 java.util.List;
+import java.util.Map;
+
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.redback.integration.checks.xwork.XworkActionConfig;
+import org.codehaus.redback.integration.checks.xwork.XworkPackageConfig;
+
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.entities.ActionConfig;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+
+/**
+ * AbstractXworkConfigurationCheck
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class AbstractXworkConfigurationCheck
+{
+
+ protected void checkAction( List<String> violations, XworkPackageConfig expectedPackage, XworkActionConfig expectedAction,
+ Map<?, ?> xwActionMap )
+ {
+ ActionConfig xwActionConfig = (ActionConfig) xwActionMap.get( expectedAction.name );
+ if ( xwActionConfig != null )
+ {
+ if ( StringUtils.isNotEmpty( expectedAction.clazz ) )
+ {
+ if ( !StringUtils.equals( expectedAction.clazz, xwActionConfig.getClassName() ) )
+ {
+ violations.add( "xwork.xml - Expected class attribute value of " + quote( expectedAction.clazz ) +
+ " but got " + quote( xwActionConfig.getClassName() ) + " instead, on action " +
+ quote( expectedAction.name ) + " in package " + quote( expectedPackage.name ) + "." );
+ }
+ }
+
+ if ( StringUtils.isNotEmpty( expectedAction.method ) )
+ {
+ if ( !StringUtils.equals( expectedAction.method, xwActionConfig.getMethodName() ) )
+ {
+ violations.add( "xwork.xml - Expected method attribute value of " + quote( expectedAction.method ) +
+ " but got " + quote( xwActionConfig.getMethodName() ) + " instead, on action " +
+ quote( expectedAction.name ) + " in package " + quote( expectedPackage.name ) + "." );
+ }
+ }
+
+ Map<?, ?> xwResultMap = xwActionConfig.getResults();
+
+ if ( expectedAction.results.isEmpty() )
+ {
+ // Check for single default result.
+ if ( xwResultMap.size() < 1 )
+ {
+ violations.add( "xwork.xml - Missing default result on action name " +
+ quote( expectedAction.name ) + " in package " + quote( expectedPackage.name ) + "." );
+ }
+ }
+ else
+ {
+ // Check for named result names.
+ for ( String resultName : expectedAction.results )
+ {
+ if ( xwResultMap.get( resultName ) == null )
+ {
+ violations.add( "xwork.xml - Missing named result " + quote( resultName ) + " in action " +
+ quote( expectedAction.name ) + " in package " + quote( expectedPackage.name ) + "." );
+ }
+ }
+ }
+ }
+ else
+ {
+ violations.add( "xwork.xml - Missing action named " + quote( expectedAction.name ) + " in package " +
+ quote( expectedPackage.name ) + "." );
+ }
+ }
+
+ protected void checkPackage( List<String> violations, XworkPackageConfig expectedPackage, Configuration xwConfig )
+ {
+ PackageConfig xwPackageConfig = findPackageNamespace( xwConfig, expectedPackage.name );
+
+ if ( xwPackageConfig != null )
+ {
+ Map<?, ?> xwActionMap = xwPackageConfig.getActionConfigs();
+
+ for ( XworkActionConfig expectedAction : expectedPackage.actions )
+ {
+ checkAction( violations, expectedPackage, expectedAction, xwActionMap );
+ }
+ }
+ else
+ {
+ violations.add( "Missing " + quote( expectedPackage.name ) + " package namespace in xwork.xml" );
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected PackageConfig findPackageNamespace( Configuration xwConfig, String name )
+ {
+ Map<?,PackageConfig> xwPackageConfigMap = xwConfig.getPackageConfigs();
+
+ for ( PackageConfig xwPackageConfig : xwPackageConfigMap.values() )
+ {
+ if ( StringUtils.equals( name, xwPackageConfig.getNamespace() ) )
+ {
+ return xwPackageConfig;
+ }
+ }
+
+ return null;
+ }
+
+ protected String quote( Object o )
+ {
+ if ( o == null )
+ {
+ return "<null>";
+ }
+ return "\"" + o.toString() + "\"";
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/AbstractXworkConfigurationCheck.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/AbstractXworkConfigurationCheck.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkActions.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkActions.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkActions.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkActions.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,85 @@
+package org.codehaus.plexus.redback.struts2.checks;
+
+/*
+ * 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 java.util.List;
+
+import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
+
+/**
+ * ExpectedXworkActions
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ */
+public class ExpectedXworkActions
+ implements EnvironmentCheck
+{
+ public void validateEnvironment( List<String> violations )
+ {
+ String classNames[] = new String[]{"org.codehaus.plexus.redback.struts2.action.admin.UserCreateAction",
+ "org.codehaus.plexus.redback.struts2.action.admin.UserDeleteAction",
+ "org.codehaus.plexus.redback.struts2.action.admin.UserEditAction",
+ "org.codehaus.plexus.redback.struts2.action.admin.UserListAction",
+ "org.codehaus.plexus.redback.struts2.action.AccountAction",
+ "org.codehaus.plexus.redback.struts2.action.LoginAction",
+ "org.codehaus.plexus.redback.struts2.action.LogoutAction",
+ "org.codehaus.plexus.redback.struts2.action.PasswordAction",
+ "org.codehaus.plexus.redback.struts2.action.RegisterAction",
+ "org.codehaus.plexus.redback.struts2.action.admin.AdminConsoleAction",
+ "org.codehaus.plexus.redback.struts2.action.admin.SystemInfoAction"};
+
+ int count = 0;
+
+ for ( int i = 0; i >= classNames.length; i++ )
+ {
+ if ( !classExists( violations, classNames[i] ) )
+ {
+ count++;
+ }
+ }
+
+ if ( count > 0 )
+ {
+ violations.add( "Missing [" + count + "] xwork Actions." );
+ }
+ }
+
+ private boolean classExists( List<String> violations, String className )
+ {
+ try
+ {
+ Class.forName( className );
+
+ // TODO: check that class is an instance of Action?
+ }
+ catch ( ClassNotFoundException e )
+ {
+ violations.add( "Missing xwork Action class " + quote( className ) + "." );
+ return false;
+ }
+ return true;
+ }
+
+ private String quote( Object o )
+ {
+ if ( o == null )
+ {
+ return "<null>";
+ }
+ return "\"" + o.toString() + "\"";
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkActions.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkActions.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkConfiguration.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkConfiguration.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkConfiguration.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkConfiguration.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,126 @@
+package org.codehaus.plexus.redback.struts2.checks;
+
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
+import org.codehaus.redback.integration.checks.xwork.XworkPackageConfig;
+
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.ConfigurationManager;
+
+/**
+ * <p/>
+ * ExpectedXworkConfiguration reason for existence is to validate that the executing
+ * environment has everything needed for a proper execution of
+ * Plexus Security :: UI Web components and javascript and jsps.
+ * </p>
+ * <p/>
+ * <p/>
+ * It is quite possible for the environment overlay to have not been done.
+ * Such as when using <code>"mvn jetty:run"</code>, but forgetting to run
+ * <code>"mvn war:inplace"</code> first.
+ * </p>
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * TODO: Address comment below and add back in the component declaration
+ *
+ */
+public class ExpectedXworkConfiguration
+ extends AbstractXworkConfigurationCheck
+ implements EnvironmentCheck
+{
+ public void validateEnvironment( List<String> violations )
+ {
+ // Get the configuration.
+
+ Configuration xworkConfig = new ConfigurationManager().getConfiguration();
+
+ if ( xworkConfig != null )
+ {
+ List<String> internalViolations = new ArrayList<String>();
+
+ /* PLXREDBACK-67
+ * TODO: this currently throws a violation since the standard practice is
+ * to include the xwork-security namespace in from the war overlay. Otherwise
+ * all actions in the security namespace are also addressable from the
+ * root default action lookup since by extending the security package thats how
+ * webwork/xwork deals with the actions
+ */
+ XworkPackageConfig expectedPackage = new XworkPackageConfig( "/security" );
+
+ expectedPackage.addAction( "account", "redback-account", "show" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ expectedPackage.addAction( "login", "redback-login", "show" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ expectedPackage.addAction( "logout", "redback-logout", "show" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ expectedPackage.addAction( "register", "redback-register", "show" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ expectedPackage.addAction( "password", "redback-password", "show" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ // -----------------------------------------------------------------
+ // Security Admin Tests
+
+ expectedPackage.addAction( "systeminfo", "redback-sysinfo", "show" );
+ expectedPackage.addAction( "adminConsole", "redback-admin-console", "show" );
+
+ expectedPackage.addAction( "userlist", "redback-admin-user-list", "show" ).addResult( "input" ).addResult(
+ "success" );
+
+ expectedPackage.addAction( "useredit", "redback-admin-user-edit", "edit" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ expectedPackage.addAction( "usercreate", "redback-admin-user-create", "edit" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ expectedPackage.addAction( "userdelete", "redback-admin-user-delete", "confirm" ).addResult(
+ "input" ).addResult( "error" ).addResult( "success" );
+
+ expectedPackage.addAction( "assignments", "redback-assignments", "show" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ expectedPackage.addAction( "roles", "redback-roles", "show" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ expectedPackage.addAction( "permissions", "redback-permissions", "show" ).addResult( "input" ).addResult(
+ "error" ).addResult( "success" );
+
+ checkPackage( internalViolations, expectedPackage, xworkConfig );
+
+ if ( internalViolations.size() > 0 )
+ {
+ violations.addAll( internalViolations );
+ violations.add( "Missing [" + internalViolations.size() + "] xwork.xml configuration elements." );
+ }
+ }
+ else
+ {
+ violations.add( "Missing xwork.xml configuration." );
+ }
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/checks/ExpectedXworkConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/interceptor/AbstractHttpRequestTrackerInterceptor.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/interceptor/AbstractHttpRequestTrackerInterceptor.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/interceptor/AbstractHttpRequestTrackerInterceptor.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/interceptor/AbstractHttpRequestTrackerInterceptor.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,71 @@
+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.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
+import org.apache.struts2.StrutsException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
+
+import java.util.Map;
+
+public abstract class AbstractHttpRequestTrackerInterceptor
+ extends AbstractInterceptor
+{
+ public static final String TRACKER_NAME = ActionInvocationTracker.class.getName( )+ ":name";
+
+ protected Logger logger = LoggerFactory.getLogger( getClass() );
+
+ protected abstract String getTrackerName();
+
+ @Override
+ public void init()
+ {
+ super.init();
+ logger.info( "{} initialized!", this.getClass().getName() );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ protected synchronized ActionInvocationTracker addActionInvocation( ActionInvocation invocation )
+ {
+ Map<String, Object> sessionMap = invocation.getInvocationContext().getSession();
+
+ ApplicationContext applicationContext = (ApplicationContext) ActionContext.getContext().getApplication().get(
+ WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE );
+ if ( applicationContext == null )
+ {
+ throw new StrutsException( "Could not locate ApplicationContext" );
+ }
+
+ ActionInvocationTracker tracker = (ActionInvocationTracker) sessionMap.get( ActionInvocationTracker.class.getName() );
+
+ if ( tracker == null )
+ {
+ //noinspection deprecation
+ tracker = applicationContext.getBean( getTrackerName(), ActionInvocationTracker.class );
+ sessionMap.put( ActionInvocationTracker.class.getName(), tracker );
+ }
+
+ tracker.addActionInvocation( invocation );
+
+ return tracker;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/interceptor/AbstractHttpRequestTrackerInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/interceptor/AbstractHttpRequestTrackerInterceptor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision