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 [21/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/AdminConsoleAction.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/AdminConsoleAction.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/AdminConsoleAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AdminConsoleAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,58 @@
+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.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;
+
+/**
+ * AdminConsoleAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller("redback-admin-console")
+@Scope("prototype")
+public class AdminConsoleAction
+ extends AbstractSecurityAction
+{
+ public String show()
+ {
+ return INPUT;
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.CONFIGURATION_EDIT_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_ROLE_DROP_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_ROLE_GRANT_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_CREATE_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_DELETE_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_LIST_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/AdminConsoleAction.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/AdminConsoleAction.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/AssignmentsAction.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/AssignmentsAction.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/AssignmentsAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AssignmentsAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,466 @@
+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.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.role.RoleManager;
+import org.codehaus.plexus.redback.role.model.ModelApplication;
+import org.codehaus.plexus.redback.struts2.action.AbstractUserCredentialsAction;
+import org.codehaus.plexus.redback.struts2.action.AuditEvent;
+import org.codehaus.plexus.redback.struts2.model.ApplicationRoleDetails;
+import org.codehaus.plexus.redback.struts2.model.ApplicationRoleDetails.RoleTableCell;
+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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * AssignmentsAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller("redback-assignments")
+@Scope("prototype")
+public class AssignmentsAction
+ extends AbstractUserCredentialsAction
+{
+ // ------------------------------------------------------------------
+ // Component Requirements
+ // ------------------------------------------------------------------
+
+ /**
+ * role-hint="default"
+ */
+ @Inject
+ private RoleManager rmanager;
+
+ // ------------------------------------------------------------------
+ // Action Parameters
+ // ------------------------------------------------------------------
+
+ private String principal;
+
+ private AdminEditUserCredentials user;
+
+ /**
+ * A List of {@link Role} objects.
+ */
+ private List<Role> assignedRoles;
+
+ /**
+ * A List of {@link Role} objects.
+ */
+ private List<Role> availableRoles;
+
+ private List<Role> effectivelyAssignedRoles;
+
+ /**
+ * List of names (received from client) of dynamic roles to set/unset
+ */
+ private List<String> addDSelectedRoles;
+
+ /**
+ * List of names (received from client) of nondynamic roles to set/unset
+ */
+ private List<String> addNDSelectedRoles;
+
+ private List<Role> nondynamicroles;
+
+ private List<Role> dynamicroles;
+
+ private List<String> NDRoles;
+
+ private List<String> DRoles;
+
+ private List<ApplicationRoleDetails> applicationRoleDetails = new ArrayList<ApplicationRoleDetails>();
+
+ // ------------------------------------------------------------------
+ // Action Entry Points - (aka Names)
+ // ------------------------------------------------------------------
+
+ public List<ApplicationRoleDetails> getApplicationRoleDetails()
+ {
+ return applicationRoleDetails;
+ }
+
+ /**
+ * Display the edit user panel. <p/> This should consist of the Role details for the specified user. <p/> A table of
+ * currently assigned roles. This table should have a column to remove the role from the user. This table should
+ * also have a column of checkboxes that can be selected and then removed from the user. <p/> A table of roles that
+ * can be assigned. This table should have a set of checkboxes that can be selected and then added to the user. <p/>
+ * Duplicate role assignment needs to be taken care of.
+ *
+ * @throws RbacManagerException
+ * @throws RbacObjectNotFoundException
+ */
+ @SuppressWarnings( "unchecked" )
+ public String show()
+ throws RbacManagerException
+ {
+ this.addNDSelectedRoles = new ArrayList<String>();
+ this.addDSelectedRoles = new ArrayList<String>();
+
+ if ( StringUtils.isEmpty( principal ) )
+ {
+ addActionError( getText( "rbac.edit.user.empty.principal" ) );
+ return ERROR;
+ }
+
+ UserManager userManager = super.securitySystem.getUserManager();
+
+ if ( !userManager.userExists( principal ) )
+ {
+ addActionError( getText( "user.does.not.exist", new String[]{principal} ) );
+ return ERROR;
+ }
+
+ try
+ {
+ User u = userManager.findUser( principal );
+
+ if ( u == null )
+ {
+ addActionError( getText( "cannot.operate.on.null.user" ) );
+ return ERROR;
+ }
+
+ user = new AdminEditUserCredentials( u );
+ }
+ catch ( UserNotFoundException e )
+ {
+ addActionError( getText( "user.not.found.exception", Arrays.asList( ( Object ) principal, e.getMessage() ) ) );
+ return ERROR;
+ }
+
+ // check first if role assignments for user exist
+ if ( !getManager().userAssignmentExists( principal ) )
+ {
+ UserAssignment assignment = getManager().createUserAssignment( principal );
+ getManager().saveUserAssignment( assignment );
+ }
+
+ List<Role> assignableRoles = getFilteredRolesForCurrentUserAccess();
+ List<ApplicationRoleDetails> appRoleDetails = lookupAppRoleDetails( principal, assignableRoles );
+ applicationRoleDetails.addAll( appRoleDetails );
+
+ return SUCCESS;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private List<ApplicationRoleDetails> lookupAppRoleDetails( String principal, List<Role> assignableRoles )
+ throws RbacManagerException
+ {
+ List<ApplicationRoleDetails> appRoleDetails = new ArrayList<ApplicationRoleDetails>();
+ for ( Iterator<ModelApplication> i = rmanager.getModel().getApplications().iterator(); i.hasNext(); )
+ {
+ ModelApplication application = i.next();
+ ApplicationRoleDetails details =
+ new ApplicationRoleDetails( application, getManager().getEffectivelyAssignedRoles( principal ),
+ getManager().getAssignedRoles( principal ), assignableRoles );
+ appRoleDetails.add( details );
+ }
+ return appRoleDetails;
+ }
+
+ /**
+ * Applies role additions and removals and then displays the edit user panel.
+ *
+ * @return
+ */
+ public String edituser()
+ {
+ try
+ {
+ Collection<Role> assignedRoles = getManager().getAssignedRoles( principal );
+ List<Role> assignableRoles = getFilteredRolesForCurrentUserAccess();
+
+ // Compute set of roles usable by configured apps, add/del from this set only
+ List<ApplicationRoleDetails> appRoleDetails = lookupAppRoleDetails( principal, assignableRoles );
+ applicationRoleDetails.addAll( appRoleDetails );
+
+ Set<String> availableAppRoleNames = new HashSet<String>();
+ for ( ApplicationRoleDetails appRoleDetail : applicationRoleDetails )
+ {
+ availableAppRoleNames.addAll( appRoleDetail.getAssignedRoles() );
+ availableAppRoleNames.addAll( appRoleDetail.getAvailableRoles() );
+
+ // Add dynamic roles offered on page
+ for ( List<RoleTableCell> row : appRoleDetail.getTable() )
+ {
+ for ( RoleTableCell col : row )
+ {
+ if ( !col.isLabel() )
+ {
+ availableAppRoleNames.add( col.getName() );
+ }
+ }
+ }
+ }
+
+ Set<Role> availableRoles = new HashSet<Role>( assignedRoles );
+ availableRoles.addAll( assignableRoles );
+
+ // Filter the available roles so we only consider configured app roles
+ Iterator<Role> availableRoleIterator = availableRoles.iterator();
+ while ( availableRoleIterator.hasNext() )
+ {
+ Role availableRole = availableRoleIterator.next();
+ if ( !availableAppRoleNames.contains( availableRole.getName() ) )
+ {
+ availableRoleIterator.remove();
+ }
+ }
+
+ List<String> selectedRoleNames = new ArrayList<String>();
+ addSelectedRoles( availableRoles, selectedRoleNames, addNDSelectedRoles );
+ addSelectedRoles( availableRoles, selectedRoleNames, addDSelectedRoles );
+
+ List<String> newRoles = new ArrayList<String>( selectedRoleNames );
+ String currentUser = getCurrentUser();
+ for ( Role assignedRole : assignedRoles )
+ {
+ if ( !selectedRoleNames.contains( assignedRole.getName() ) )
+ {
+ // removing a currently assigned role, check if we have permission
+ if ( !availableRoles.contains( assignedRole )
+ || !checkRoleName( assignableRoles, assignedRole.getName() ) )
+ {
+ // it may have not been on the page. Leave it assigned.
+ selectedRoleNames.add( assignedRole.getName() );
+ }
+ else
+ {
+ String role = assignedRole.getName();
+ AuditEvent event = new AuditEvent( getText( "log.revoke.role" ) );
+ event.setAffectedUser( principal );
+ event.setRole( role );
+ event.setCurrentUser( currentUser );
+ event.log();
+ }
+ }
+ else
+ {
+ newRoles.remove( assignedRole.getName() );
+ }
+ }
+ for ( String r : newRoles )
+ {
+ AuditEvent event = new AuditEvent( getText( "log.assign.role" ) );
+ event.setAffectedUser( principal );
+ event.setRole( r );
+ event.setCurrentUser( currentUser );
+ event.log();
+ }
+
+ UserAssignment assignment;
+
+ if ( getManager().userAssignmentExists( principal ) )
+ {
+ assignment = getManager().getUserAssignment( principal );
+ }
+ else
+ {
+ assignment = getManager().createUserAssignment( principal );
+ }
+
+ assignment.setRoleNames( selectedRoleNames );
+
+ assignment = getManager().saveUserAssignment( assignment );
+ }
+ catch ( RbacManagerException ne )
+ {
+ addActionError( getText( "error.removing.selected.roles", Arrays.asList( ( Object ) ne.getMessage() ) ) );
+ return ERROR;
+ }
+ return SUCCESS;
+ }
+
+ private void addSelectedRoles( Collection<Role> assignableRoles, List<String> roles, List<String> selectedRoles )
+ {
+ if ( selectedRoles != null )
+ {
+ for ( String r : selectedRoles )
+ {
+ if ( checkRoleName( assignableRoles, r ) )
+ {
+ roles.add( r );
+ }
+ }
+ }
+ }
+
+ private boolean checkRoleName( Collection<Role> assignableRoles, String r )
+ {
+ for ( Role role : assignableRoles )
+ {
+ if ( role.getName().equals( r ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // ------------------------------------------------------------------
+ // Parameter Accessor Methods
+ // ------------------------------------------------------------------
+
+ public List<Role> getAssignedRoles()
+ {
+ return assignedRoles;
+ }
+
+ public void setAssignedRoles( List<Role> assignedRoles )
+ {
+ this.assignedRoles = assignedRoles;
+ }
+
+ public List<Role> getAvailableRoles()
+ {
+ return availableRoles;
+ }
+
+ public void setAvailableRoles( List<Role> availableRoles )
+ {
+ this.availableRoles = availableRoles;
+ }
+
+ public List<Role> getEffectivelyAssignedRoles()
+ {
+ return effectivelyAssignedRoles;
+ }
+
+ public void setEffectivelyAssignedRoles( List<Role> effectivelyAssignedRoles )
+ {
+ this.effectivelyAssignedRoles = effectivelyAssignedRoles;
+ }
+
+ public String getPrincipal()
+ {
+ return principal;
+ }
+
+ public void setPrincipal( String principal )
+ {
+ this.principal = principal;
+ }
+
+ public void setUsername( String username )
+ {
+ this.principal = username;
+ }
+
+ public AdminEditUserCredentials getUser()
+ {
+ return 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_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;
+ }
+
+ public List<Role> getNondynamicroles()
+ {
+ return nondynamicroles;
+ }
+
+ public void setNondynamicroles( List<Role> nondynamicroles )
+ {
+ this.nondynamicroles = nondynamicroles;
+ }
+
+ public List<Role> getDynamicroles()
+ {
+ return dynamicroles;
+ }
+
+ public void setDynamicroles( List<Role> dynamicroles )
+ {
+ this.dynamicroles = dynamicroles;
+ }
+
+ public List<String> getNDRoles()
+ {
+ return NDRoles;
+ }
+
+ public void setNDRoles( List<String> roles )
+ {
+ NDRoles = roles;
+ }
+
+ public List<String> getDRoles()
+ {
+ return DRoles;
+ }
+
+ public void setDRoles( List<String> roles )
+ {
+ DRoles = roles;
+ }
+
+ public List<String> getAddDSelectedRoles()
+ {
+ return addDSelectedRoles;
+ }
+
+ public void setAddDSelectedRoles( List<String> addDSelectedRoles )
+ {
+ this.addDSelectedRoles = addDSelectedRoles;
+ }
+
+ public List<String> getAddNDSelectedRoles()
+ {
+ return addNDSelectedRoles;
+ }
+
+ public void setAddNDSelectedRoles( List<String> addNDSelectedRoles )
+ {
+ this.addNDSelectedRoles = addNDSelectedRoles;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AssignmentsAction.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/AssignmentsAction.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/BackupRecord.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/BackupRecord.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/BackupRecord.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/BackupRecord.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,70 @@
+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 java.io.File;
+import java.util.Date;
+
+/**
+ * A record of a backup directory for displaying the backup/restore page.
+ */
+public class BackupRecord
+ implements Comparable<BackupRecord>
+{
+ private final File directory;
+
+ private final Date date;
+
+ private final boolean userDatabase;
+
+ public BackupRecord( File directory )
+ {
+ this.directory = directory;
+
+ this.date = new Date( directory.lastModified() );
+
+ this.userDatabase = new File( directory, "users.xml" ).exists();
+ }
+
+ public File getDirectory()
+ {
+ return directory;
+ }
+
+ public Date getDate()
+ {
+ return date;
+ }
+
+ public boolean isUserDatabase()
+ {
+ return userDatabase;
+ }
+
+ public boolean isValidBackup()
+ {
+ return userDatabase;
+ }
+
+ public int compareTo( BackupRecord record )
+ {
+ return record.date.compareTo( this.date );
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/BackupRecord.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/BackupRecord.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/BackupRestoreAction.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/BackupRestoreAction.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/BackupRestoreAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/BackupRestoreAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,299 @@
+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 com.opensymphony.xwork2.Preparable;
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.plexus.redback.keys.KeyManager;
+import org.codehaus.plexus.redback.management.DataManagementTool;
+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.users.UserManager;
+import org.codehaus.redback.integration.interceptor.SecureAction;
+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.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+
+/**
+ * BackupRestoreAction
+ */
+@Controller( "backup-restore" )
+@Scope( "prototype" )
+public class BackupRestoreAction
+ extends AbstractSecurityAction
+ implements SecureAction, Preparable
+{
+ public final static String CUSTOM_ERROR = "custom_error";
+
+ /**
+ *
+ */
+ private File applicationHome = new File( "data" );
+
+ /**
+ * role-hint="jdo"
+ */
+ @Inject
+ private DataManagementTool dataManagementTool;
+
+ /**
+ * role-hint="jdo"
+ */
+ @Inject
+ @Named( value = "rBACManager#jdo" )
+ private RBACManager rbacManager;
+
+ /**
+ * role-hint="jdo"
+ */
+ @Inject
+ @Named( value = "userManager#jdo" )
+ private UserManager userManager;
+
+ /**
+ * role-hint="jdo"
+ */
+ @Inject
+ @Named( value = "keyManager#jdo" )
+ private KeyManager keyManager;
+
+ private File backupDirectory;
+
+ private String restoreDirectory;
+
+ private List<BackupRecord> previousBackups;
+
+ private boolean confirmed;
+
+ public static final String BACKUP_DIRECTORY = "user-backup-directory";
+
+ public String view()
+ throws Exception
+ {
+
+ retrievePreviousBackups();
+
+ return SUCCESS;
+ }
+
+ public String backup()
+ throws Exception
+ {
+
+ File backupDirectory = getTimestampedBackupDirectory();
+ backupDirectory.mkdirs();
+
+ log.info( "Backing up security database to {}", backupDirectory );
+ this.backupDatabase( backupDirectory );
+
+ log.info( "Done backing up security database" );
+
+ return SUCCESS;
+ }
+
+ public String restore()
+ throws Exception
+ {
+ if ( StringUtils.isEmpty( restoreDirectory ) )
+ {
+ addActionError( getText( "backupRestore.backup.empty.error" ) );
+ return CUSTOM_ERROR;
+ }
+
+ File restoreDirectory = new File( this.restoreDirectory );
+
+ boolean fileExists = restoreDirectory.exists() && restoreDirectory.isDirectory();
+ boolean isValidBackup = false;
+
+ if ( fileExists )
+ {
+ BackupRecord record = new BackupRecord( restoreDirectory );
+ isValidBackup = record.isValidBackup();
+ }
+
+ if ( !fileExists )
+ {
+ log.warn( "Backup: " + this.restoreDirectory + " not found." );
+ addActionError( getText( "backupRestore.backup.error" ) );
+ retrievePreviousBackups();
+ return CUSTOM_ERROR;
+ }
+ else if ( !isValidBackup )
+ {
+ log.warn( "Backup: " + this.restoreDirectory + " is not a valid backup directory." );
+ addActionError( getText( "backupRestore.backup.error" ) );
+ retrievePreviousBackups();
+ return CUSTOM_ERROR;
+ }
+
+ log.info( "Restoring security database from {}", this.restoreDirectory );
+ this.eraseDatabase();
+ this.restoreDatabase( restoreDirectory );
+ log.info( "Done restoring security database" );
+
+ return SUCCESS;
+ }
+
+
+ private void backupDatabase( File backupDirectory )
+ throws Exception
+ {
+
+ dataManagementTool.backupKeyDatabase( keyManager, backupDirectory );
+ dataManagementTool.backupRBACDatabase( rbacManager, backupDirectory );
+ dataManagementTool.backupUserDatabase( userManager, backupDirectory );
+ }
+
+ private void eraseDatabase()
+ {
+ dataManagementTool.eraseKeysDatabase( keyManager );
+ dataManagementTool.eraseRBACDatabase( rbacManager );
+ dataManagementTool.eraseUsersDatabase( userManager );
+ }
+
+ private void restoreDatabase( File backupDirectory )
+ throws Exception
+ {
+
+ dataManagementTool.restoreKeysDatabase( keyManager, backupDirectory );
+ dataManagementTool.restoreRBACDatabase( rbacManager, backupDirectory );
+ dataManagementTool.restoreUsersDatabase( userManager, backupDirectory );
+ }
+
+ public String getRestoreDirectory()
+ {
+ return restoreDirectory;
+ }
+
+ public void setRestoreDirectory( String restoreDirectory )
+ {
+ this.restoreDirectory = restoreDirectory;
+ }
+
+ private File getTimestampedBackupDirectory()
+ {
+ SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMdd.HHmmss", Locale.US );
+ return new File( this.backupDirectory, dateFormat.format( new Date() ) );
+ }
+
+ public File getBackupDirectory()
+ {
+ return backupDirectory;
+ }
+
+ public List<BackupRecord> getPreviousBackups()
+ {
+ return previousBackups;
+ }
+
+ public void prepare()
+ {
+ backupDirectory = this.getFile( BACKUP_DIRECTORY );
+ retrievePreviousBackups();
+ }
+
+ private void retrievePreviousBackups()
+ {
+ previousBackups = new ArrayList<BackupRecord>();
+ File[] files = backupDirectory.listFiles();
+ if ( files != null )
+ {
+ for ( int i = 0; i < files.length; i++ )
+ {
+ File f = files[i];
+
+ if ( f.isDirectory() && !f.getName().startsWith( "." ) )
+ {
+ BackupRecord record = new BackupRecord( f );
+
+ if ( record.isValidBackup() )
+ {
+ previousBackups.add( record );
+ }
+ }
+ }
+ }
+ Collections.sort( previousBackups );
+ }
+
+ public boolean isConfirmed()
+ {
+ return confirmed;
+ }
+
+ public void setConfirmed( boolean confirmed )
+ {
+ this.confirmed = confirmed;
+ }
+
+ @Override
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_MANAGE_DATA, Resource.GLOBAL );
+ return bundle;
+ }
+
+ public File getFile( String filename )
+ {
+ if ( filename == null )
+ {
+ return null;
+ }
+
+ File f = null;
+
+ if ( filename != null && filename.length() != 0 )
+ {
+ f = new File( filename );
+
+ if ( !f.isAbsolute() )
+ {
+ f = new File( applicationHome, filename );
+ }
+ }
+
+ try
+ {
+ return f.getCanonicalFile();
+ }
+ catch ( IOException e )
+ {
+ return f;
+ }
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/BackupRestoreAction.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/BackupRestoreAction.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/EditRoleAction.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/EditRoleAction.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/EditRoleAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/EditRoleAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,542 @@
+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.rbac.Permission;
+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.rbac.UserAssignment;
+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.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.codehaus.redback.integration.security.role.RedbackRoleConstants;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * EditRoleAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-role-edit" )
+@Scope( "prototype" )
+public class EditRoleAction
+ extends AbstractUserCredentialsAction
+{
+ // ------------------------------------------------------------------
+ // Action Parameters
+ // ------------------------------------------------------------------
+
+ private String name;
+
+ private String description;
+
+ private String newDescription;
+
+ private List<String> childRoleNames = new ArrayList<String>();
+
+ private List<String> parentRoleNames = new ArrayList<String>();
+
+ private List<Permission> permissions = new ArrayList<Permission>();
+
+ private List<User> users = new ArrayList<User>();
+
+ private List<User> parentUsers = new ArrayList<User>();
+
+ private List<User> allUsers = new ArrayList<User>();
+
+ private List<String> usersList = new ArrayList<String>();
+
+ private List<String> availableUsers = new ArrayList<String>();
+
+ private List<String> currentUsers = new ArrayList<String>();
+
+ // ------------------------------------------------------------------
+ // Action Entry Points - (aka Names)
+ // ------------------------------------------------------------------
+
+ public String input()
+ {
+ if ( name == null )
+ {
+ addActionError( getText( "cannot.edit.null.role" ) );
+ return ERROR;
+ }
+
+ if ( StringUtils.isEmpty( name ) )
+ {
+ addActionError( getText( "cannot.edit.empty.role" ) );
+ return ERROR;
+ }
+
+ name = StringEscapeUtils.escapeXml( name );
+
+ if ( !getManager().roleExists( name ) )
+ {
+ // Means that the role name doesn't exist.
+ // We should exit early and not attempt to look up the role information.
+ return INPUT;
+ }
+
+ try
+ {
+ if ( !isAuthorized() )
+ {
+ log.warn( getCurrentUser() + " isn't authorized to access to the role '" + name + "'" );
+ addActionError( getText( "alert.message" ) );
+ return ERROR;
+ }
+
+ Role role = getManager().getRole( name );
+ if ( role == null )
+ {
+ addActionError( getText( "cannot.operate.null.role" ) );
+ return ERROR;
+ }
+
+ description = role.getDescription();
+ childRoleNames = role.getChildRoleNames();
+ Map<String, Role> parentRoles = getManager().getParentRoles( role );
+ for ( String roleName : parentRoles.keySet() )
+ {
+ parentRoleNames.add( roleName );
+ }
+ permissions = role.getPermissions();
+
+ //Get users of the current role
+ List<String> roles = new ArrayList<String>();
+ roles.add( name );
+ List<UserAssignment> userAssignments = getManager().getUserAssignmentsForRoles( roles );
+ users = new ArrayList<User>();
+ if ( userAssignments != null )
+ {
+ for ( UserAssignment userAssignment : userAssignments )
+ {
+ try
+ {
+ User user = getUserManager().findUser( userAssignment.getPrincipal() );
+ users.add( user );
+ }
+ catch ( UserNotFoundException e )
+ {
+ log.warn( "User '" + userAssignment.getPrincipal() + "' doesn't exist.", e );
+ }
+ }
+ }
+
+ //Get users of the parent roles
+ parentUsers = new ArrayList<User>();
+ if ( !parentRoles.isEmpty() )
+ {
+ List<UserAssignment> userParentAssignments =
+ getManager().getUserAssignmentsForRoles( parentRoles.keySet() );
+ if ( userParentAssignments != null )
+ {
+ for ( UserAssignment userAssignment : userParentAssignments )
+ {
+ try
+ {
+ User user = getUserManager().findUser( userAssignment.getPrincipal() );
+ parentUsers.add( user );
+ }
+ catch ( UserNotFoundException e )
+ {
+ log.warn( "User '" + userAssignment.getPrincipal() + "' doesn't exist.", e );
+ }
+ }
+ }
+ }
+ }
+ catch ( RbacManagerException e )
+ {
+ List<Object> list = new ArrayList<Object>();
+ list.add( name );
+ list.add( e.getMessage() );
+ addActionError( getText( "cannot.get.role", list ) );
+ return ERROR;
+ }
+
+ return INPUT;
+ }
+
+ private boolean isAuthorized()
+ throws RbacManagerException
+ {
+ List<Role> assignableRoles = getFilteredRolesForCurrentUserAccess();
+ boolean updatableRole = false;
+ for ( Role r : assignableRoles )
+ {
+ if ( r.getName().equalsIgnoreCase( name ) )
+ {
+ updatableRole = true;
+ }
+ }
+
+ return updatableRole;
+ }
+
+ public String edit()
+ {
+ String result = input();
+ if ( ERROR.equals( result ) )
+ {
+ return result;
+ }
+
+ newDescription = description;
+
+ //TODO: Remove all users defined in parent roles too
+ allUsers = getUserManager().getUsers();
+
+ for ( User user : users )
+ {
+ if ( allUsers.contains( user ) )
+ {
+ allUsers.remove( user );
+ }
+ }
+
+ for ( User user : parentUsers )
+ {
+ if ( allUsers.contains( user ) )
+ {
+ allUsers.remove( user );
+ }
+ }
+
+ return result;
+ }
+
+ public String save()
+ {
+ String result = input();
+ if ( ERROR.equals( result ) )
+ {
+ return result;
+ }
+
+ if ( name == null )
+ {
+ addActionError( getText( "cannot.edit.null.role" ) );
+ return ERROR;
+ }
+
+ if ( StringUtils.isEmpty( name ) )
+ {
+ addActionError( getText( "cannot.edit.empty.role" ) );
+ return ERROR;
+ }
+
+ try
+ {
+ Role role;
+ if ( getManager().roleExists( name ) )
+ {
+ role = getManager().getRole( name );
+ }
+ else
+ {
+ role = getManager().createRole( name );
+ }
+
+ //TODO: allow to modify childRoleNames and permissions
+ role.setDescription( newDescription );
+ //role.setChildRoleNames( childRoleNames );
+ //role.setPermissions( permissions );
+
+ getManager().saveRole( role );
+
+ List<Object> list = new ArrayList<Object>();
+ list.add( name );
+ String currentUser = getCurrentUser();
+ AuditEvent event = new AuditEvent( getText( "log.role.edit" ) );
+ event.setRole( name );
+ event.setCurrentUser( currentUser );
+ event.log();
+ addActionMessage( getText( "save.role.success", list ) );
+ }
+ catch ( RbacManagerException e )
+ {
+ List<Object> list = new ArrayList<Object>();
+ list.add( name );
+ list.add( e.getMessage() );
+ addActionError( getText( "cannot.get.role", list ) );
+ return ERROR;
+ }
+
+ return SUCCESS;
+ }
+
+ public String addUsers()
+ {
+ if ( availableUsers == null || availableUsers.isEmpty() )
+ {
+ return INPUT;
+ }
+
+ for ( String principal : availableUsers )
+ {
+ if ( !getUserManager().userExists( principal ) )
+ {
+ // Means that the role name doesn't exist.
+ // We need to fail fast and return to the previous page.
+ List<Object> list = new ArrayList<Object>();
+ list.add( principal );
+ addActionError( getText( "user.does.not.exist", list ) );
+ return ERROR;
+ }
+
+ try
+ {
+ UserAssignment assignment;
+
+ if ( getManager().userAssignmentExists( principal ) )
+ {
+ assignment = getManager().getUserAssignment( principal );
+ }
+ else
+ {
+ assignment = getManager().createUserAssignment( principal );
+ }
+
+ assignment.addRoleName( name );
+ assignment = getManager().saveUserAssignment( assignment );
+ log.info( "{} role assigned to {}", name, principal );
+ }
+ catch ( RbacManagerException e )
+ {
+ List<Object> list = new ArrayList<Object>();
+ list.add( principal );
+ list.add( e.getMessage() );
+ addActionError( getText( "cannot.assign.role", list ) );
+ return ERROR;
+ }
+ }
+
+ edit();
+ return SUCCESS;
+ }
+
+ public String removeUsers()
+ {
+ if ( currentUsers == null || currentUsers.isEmpty() )
+ {
+ return INPUT;
+ }
+
+ for ( String principal : currentUsers )
+ {
+ if ( !getUserManager().userExists( principal ) )
+ {
+ // Means that the role name doesn't exist.
+ // We need to fail fast and return to the previous page.
+ List<Object> list = new ArrayList<Object>();
+ list.add( principal );
+ addActionError( getText( "user.does.not.exist", list ) );
+ return ERROR;
+ }
+
+ try
+ {
+ UserAssignment assignment;
+
+ if ( getManager().userAssignmentExists( principal ) )
+ {
+ assignment = getManager().getUserAssignment( principal );
+ }
+ else
+ {
+ assignment = getManager().createUserAssignment( principal );
+ }
+
+ assignment.removeRoleName( name );
+ assignment = getManager().saveUserAssignment( assignment );
+ log.info( "{} role unassigned to {}", name, principal );
+ }
+ catch ( RbacManagerException e )
+ {
+ List<Object> list = new ArrayList<Object>();
+ list.add( principal );
+ list.add( e.getMessage() );
+ addActionError( getText( "cannot.assign.role", list ) );
+ return ERROR;
+ }
+ }
+
+ edit();
+ return SUCCESS;
+ }
+
+ private UserManager getUserManager()
+ {
+ return securitySystem.getUserManager();
+ }
+
+ // ------------------------------------------------------------------
+ // Parameter Accessor Methods
+ // ------------------------------------------------------------------
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName( String roleName )
+ {
+ this.name = roleName;
+ }
+
+ public List<String> getChildRoleNames()
+ {
+ return childRoleNames;
+ }
+
+ public void setChildRoleNames( List<String> childRoleNames )
+ {
+ this.childRoleNames = childRoleNames;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+
+ public String getNewDescription()
+ {
+ return newDescription;
+ }
+
+ public void setNewDescription( String newDescription )
+ {
+ this.newDescription = newDescription;
+ }
+
+ public List<Permission> getPermissions()
+ {
+ return permissions;
+ }
+
+ public void setPermissions( List<Permission> permissions )
+ {
+ this.permissions = permissions;
+ }
+
+ public List<User> getUsers()
+ {
+ return users;
+ }
+
+ public void setUsers( List<User> users )
+ {
+ this.users = users;
+ }
+
+ public List<User> getAllUsers()
+ {
+ return allUsers;
+ }
+
+ public void setAllUsers( List<User> allUsers )
+ {
+ this.allUsers = allUsers;
+ }
+
+ public List<String> getUsersList()
+ {
+ return usersList;
+ }
+
+ public void setUsersList( List<String> usersList )
+ {
+ this.usersList = usersList;
+ }
+
+ public List<String> getAvailableUsers()
+ {
+ return availableUsers;
+ }
+
+ public void setAvailableUsers( List<String> availableUsers )
+ {
+ this.availableUsers = availableUsers;
+ }
+
+ public List<String> getCurrentUsers()
+ {
+ return currentUsers;
+ }
+
+ public void setCurrentUsers( List<String> currentUsers )
+ {
+ this.currentUsers = currentUsers;
+ }
+
+ public List<String> getParentRoleNames()
+ {
+ return parentRoleNames;
+ }
+
+ public void setParentRoleNames( List<String> parentRoleNames )
+ {
+ this.parentRoleNames = parentRoleNames;
+ }
+
+ public List<User> getParentUsers()
+ {
+ return parentUsers;
+ }
+
+ public void setParentUsers( List<User> parentUsers )
+ {
+ this.parentUsers = parentUsers;
+ }
+
+ // ------------------------------------------------------------------
+ // Internal Support Methods
+ // ------------------------------------------------------------------
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RedbackRoleConstants.USER_MANAGEMENT_ROLE_GRANT_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RedbackRoleConstants.USER_MANAGEMENT_ROLE_DROP_OPERATION, Resource.GLOBAL );
+ bundle.addRequiredAuthorization( RedbackRoleConstants.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/EditRoleAction.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/EditRoleAction.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/OperationsAction.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/OperationsAction.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/OperationsAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/OperationsAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,158 @@
+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.Operation;
+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.struts2.action.RedbackActionSupport;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.role.RoleConstants;
+import org.codehaus.redback.integration.util.OperationSorter;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * OperationsAction:
+ *
+ * @author Jesse McConnell <jm...@apache.org>
+ * @version $Id$
+ */
+@Controller( "redback-operations" )
+@Scope( "prototype" )
+public class OperationsAction
+ extends RedbackActionSupport
+{
+ private static final String LIST = "list";
+
+ /**
+ * role-hint="cached"
+ */
+ @Inject
+ @Named( value = "rBACManager#cached" )
+ private RBACManager manager;
+
+ private String operationName;
+
+ private String description;
+
+ private List<Operation> allOperations;
+
+ public String list()
+ {
+ try
+ {
+ allOperations = manager.getAllOperations();
+
+ if ( allOperations == null )
+ {
+ allOperations = Collections.emptyList();
+ }
+
+ Collections.sort( allOperations, new OperationSorter() );
+ }
+ catch ( RbacManagerException e )
+ {
+ addActionError( getText( "cannot.list.all.operations", Arrays.asList( (Object) e.getMessage() ) ) );
+ log.error( "System error:", e );
+ allOperations = Collections.emptyList();
+ }
+
+ return LIST;
+ }
+
+ public String save()
+ {
+ try
+ {
+ Operation temp = manager.createOperation( operationName );
+
+ temp.setDescription( description );
+
+ manager.saveOperation( temp );
+ }
+ catch ( RbacManagerException e )
+ {
+ addActionError( getText( "cannot.save.operation", Arrays.asList( (Object) operationName ) ) );
+ log.error( "System error:", e );
+ allOperations = Collections.emptyList();
+ }
+
+ return LIST;
+ }
+
+ public String remove()
+ {
+ try
+ {
+ manager.removeOperation( manager.getOperation( operationName ) );
+ }
+ catch ( RbacManagerException ne )
+ {
+ addActionError( getText( "cannot.remove.operation", Arrays.asList( (Object) operationName ) ) );
+ return ERROR;
+ }
+ return LIST;
+ }
+
+ public List<Operation> getAllOperations()
+ {
+ return allOperations;
+ }
+
+ public void setAllOperations( List<Operation> allOperations )
+ {
+ this.allOperations = allOperations;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+
+ public String getOperationName()
+ {
+ return operationName;
+ }
+
+ public void setOperationName( String operationName )
+ {
+ this.operationName = operationName;
+ }
+
+ 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/OperationsAction.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/OperationsAction.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/PermissionsAction.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/PermissionsAction.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/PermissionsAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/PermissionsAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,282 @@
+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.Operation;
+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.struts2.action.RedbackActionSupport;
+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.codehaus.redback.integration.util.PermissionSorter;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * PermissionsAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-permissions" )
+@Scope( "prototype" )
+public class PermissionsAction
+ extends RedbackActionSupport
+{
+ private static final String LIST = "list";
+
+ // ------------------------------------------------------------------
+ // Plexus Component Requirements
+ // ------------------------------------------------------------------
+
+ /**
+ * role-hint="cached"
+ */
+ @Inject
+ @Named( value = "rBACManager#cached" )
+ private RBACManager manager;
+
+ // ------------------------------------------------------------------
+ // Action Parameters
+ // ------------------------------------------------------------------
+
+ private String name;
+
+ private String description;
+
+ private String operationName;
+
+ private String operationDescription;
+
+ private String resourceIdentifier;
+
+ private List<Permission> allPermissions;
+
+ // ------------------------------------------------------------------
+ // Action Entry Points - (aka Names)
+ // ------------------------------------------------------------------
+
+ public String list()
+ {
+ try
+ {
+ allPermissions = manager.getAllPermissions();
+
+ if ( allPermissions == null )
+ {
+ allPermissions = Collections.emptyList();
+ }
+
+ Collections.sort( allPermissions, new PermissionSorter() );
+ }
+ catch ( RbacManagerException e )
+ {
+ addActionError( getText( "cannot.list.all.permissions", Arrays.asList( (Object) e.getMessage() ) ) );
+ log.error( "System error:", e );
+ allPermissions = Collections.emptyList();
+ }
+
+ return LIST;
+ }
+
+ public String input()
+ {
+ if ( name == null )
+ {
+ addActionError( getText( "cannot.edit.null.permission" ) );
+ return ERROR;
+ }
+
+ if ( StringUtils.isEmpty( name ) )
+ {
+ addActionError( getText( "cannot.edit.empty.permission" ) );
+ return ERROR;
+ }
+
+ if ( !manager.permissionExists( name ) )
+ {
+ // Means that the permission name doesn't exist.
+ // We should exit early and not attempt to look up the permission information.
+ return LIST;
+ }
+
+ try
+ {
+ Permission permission = manager.getPermission( name );
+ if ( permission == null )
+ {
+ addActionError( getText( "cannot.operate.null.permission" ) );
+ return ERROR;
+ }
+
+ description = permission.getDescription();
+ Operation operation = permission.getOperation();
+ if ( operation != null )
+ {
+ operationName = operation.getName();
+ operationDescription = operation.getDescription();
+ }
+
+ Resource resource = permission.getResource();
+ if ( resource != null )
+ {
+ resourceIdentifier = resource.getIdentifier();
+ }
+ }
+ catch ( RbacManagerException e )
+ {
+ addActionError( getText( "cannot.get.permission", Arrays.asList( (Object) name, e.getMessage() ) ) );
+ return ERROR;
+ }
+
+ return LIST;
+ }
+
+ public String submit()
+ {
+ if ( name == null )
+ {
+ addActionError( getText( "cannot.edit.null.permission" ) );
+ return ERROR;
+ }
+
+ if ( StringUtils.isEmpty( name ) )
+ {
+ addActionError( getText( "cannot.edit.empty.permission" ) );
+ return ERROR;
+ }
+
+ try
+ {
+ Permission permission;
+ if ( manager.permissionExists( name ) )
+ {
+ permission = manager.getPermission( name );
+ }
+ else
+ {
+ permission = manager.createPermission( name );
+ }
+
+ permission.setDescription( description );
+
+ Operation operation = manager.createOperation( operationName );
+ if ( StringUtils.isNotEmpty( operationDescription ) )
+ {
+ operation.setDescription( operationDescription );
+ }
+ permission.setOperation( manager.saveOperation( operation ) );
+
+ Resource resource = manager.createResource( resourceIdentifier );
+ permission.setResource( manager.saveResource( resource ) );
+
+ manager.savePermission( permission );
+
+ addActionMessage( getText( "save.permission.success", Arrays.asList( (Object) name ) ) );
+ }
+ catch ( RbacManagerException e )
+ {
+ addActionError( getText( "cannot.get.permission", Arrays.asList( (Object) name, e.getMessage() ) ) );
+ return ERROR;
+ }
+
+ return LIST;
+ }
+
+ // ------------------------------------------------------------------
+ // Parameter Accessor Methods
+ // ------------------------------------------------------------------
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ public String getOperationDescription()
+ {
+ return operationDescription;
+ }
+
+ public void setOperationDescription( String operationDescription )
+ {
+ this.operationDescription = operationDescription;
+ }
+
+ public String getOperationName()
+ {
+ return operationName;
+ }
+
+ public void setOperationName( String operationName )
+ {
+ this.operationName = operationName;
+ }
+
+ public String getResourceIdentifier()
+ {
+ return resourceIdentifier;
+ }
+
+ public void setResourceIdentifier( String resourceIdentifier )
+ {
+ this.resourceIdentifier = resourceIdentifier;
+ }
+
+ public List<Permission> getAllPermissions()
+ {
+ return allPermissions;
+ }
+
+ public void setAllPermissions( List<Permission> allPermissions )
+ {
+ this.allPermissions = allPermissions;
+ }
+
+ 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/PermissionsAction.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/PermissionsAction.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/ReportAction.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/ReportAction.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/ReportAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/ReportAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,144 @@
+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.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts2.ServletActionContext;
+import org.codehaus.plexus.redback.rbac.Resource;
+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.reports.Report;
+import org.codehaus.redback.integration.reports.ReportException;
+import org.codehaus.redback.integration.reports.ReportManager;
+import org.codehaus.redback.integration.role.RoleConstants;
+
+import com.opensymphony.module.sitemesh.filter.PageResponseWrapper;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+/**
+ * ReportAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller("redback-report")
+@Scope("prototype")
+public class ReportAction
+ extends AbstractSecurityAction
+{
+ /**
+ *
+ */
+ @Inject
+ private ReportManager reportManager;
+
+ private String reportId;
+
+ private String reportType;
+
+ public String generate()
+ {
+ Report report;
+ try
+ {
+ report = reportManager.findReport( reportId, reportType );
+ }
+ catch ( ReportException e )
+ {
+ addActionError( getText( "cannot.get.report", Arrays.asList( ( Object ) e.getMessage() ) ) );
+ return ERROR;
+ }
+
+ HttpServletResponse response = ServletActionContext.getResponse();
+
+ // HACK: Unwrap sitemesh response. (effectively disables sitemesh)
+ if ( response instanceof PageResponseWrapper )
+ {
+ response = (HttpServletResponse) ( (PageResponseWrapper) response ).getResponse();
+ }
+
+ try
+ {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ report.writeReport( os );
+
+ response.reset();
+ response.setContentType( report.getMimeType() );
+ response.addHeader( "Content-Disposition",
+ "attachment; filename=" + report.getId() + "." + report.getType() );
+ byte bytes[] = os.toByteArray();
+ response.setContentLength( bytes.length );
+ response.getOutputStream().write( bytes, 0, bytes.length );
+ response.getOutputStream().flush();
+ response.getOutputStream().close();
+
+ // Don't return a result.
+ return null;
+ }
+ catch ( ReportException e )
+ {
+ String emsg = getText( "cannot.generate.report" );
+ addActionError( emsg );
+ log.error( emsg, e );
+ return ERROR;
+ }
+ catch ( IOException e )
+ {
+ String emsg = getText( "cannot.generate.report" );
+ addActionError( emsg );
+ log.error( emsg, e );
+ return ERROR;
+ }
+ }
+
+ public SecureActionBundle initSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = new SecureActionBundle();
+ bundle.setRequiresAuthentication( true );
+ bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_LIST_OPERATION, Resource.GLOBAL );
+ return bundle;
+ }
+
+ public String getReportId()
+ {
+ return reportId;
+ }
+
+ public void setReportId( String reportId )
+ {
+ this.reportId = reportId;
+ }
+
+ public String getReportType()
+ {
+ return reportType;
+ }
+
+ public void setReportType( String reportType )
+ {
+ this.reportType = reportType;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/ReportAction.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/ReportAction.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/ResourcesAction.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/ResourcesAction.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/ResourcesAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/ResourcesAction.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,158 @@
+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.Resource;
+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.codehaus.redback.integration.util.ResourceSorter;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * OperationsAction:
+ *
+ * @author Jesse McConnell <jm...@apache.org>
+ * @version $Id$
+ */
+@Controller( "redback-resources" )
+@Scope( "prototype" )
+public class ResourcesAction
+ extends AbstractSecurityAction
+{
+ private static final String LIST = "list";
+
+ /**
+ * role-hint="cached"
+ */
+ @Inject
+ @Named( value = "rBACManager#cached" )
+ private RBACManager manager;
+
+ private String resourceIdentifier;
+
+ private boolean isPattern;
+
+ private List<Resource> allResources;
+
+ public String list()
+ {
+ try
+ {
+ allResources = manager.getAllResources();
+
+ if ( allResources == null )
+ {
+ allResources = Collections.emptyList();
+ }
+
+ Collections.sort( allResources, new ResourceSorter() );
+ }
+ catch ( RbacManagerException e )
+ {
+ addActionError( getText( "cannot.list.all.resources", Arrays.asList( (Object) e.getMessage() ) ) );
+ log.error( "System error:", e );
+ allResources = Collections.emptyList();
+ }
+
+ return LIST;
+ }
+
+ public String save()
+ {
+ try
+ {
+ Resource temp = manager.createResource( resourceIdentifier );
+
+ temp.setIdentifier( resourceIdentifier );
+ temp.setPattern( isPattern );
+
+ manager.saveResource( temp );
+ }
+ catch ( RbacManagerException e )
+ {
+ addActionError( getText( "cannot.save.resource", Arrays.asList( (Object) e.getMessage() ) ) );
+ log.error( "System error:", e );
+ allResources = Collections.emptyList();
+ }
+
+ return LIST;
+ }
+
+ public String remove()
+ {
+ try
+ {
+ manager.removeResource( manager.getResource( resourceIdentifier ) );
+ }
+ catch ( RbacManagerException ne )
+ {
+ addActionError( getText( "cannot.remove.resource", Arrays.asList( (Object) resourceIdentifier ) ) );
+ return ERROR;
+ }
+ return LIST;
+ }
+
+ public List<Resource> getAllResources()
+ {
+ return allResources;
+ }
+
+ public void setAllResources( List<Resource> allResources )
+ {
+ this.allResources = allResources;
+ }
+
+ public String getResourceIdentifier()
+ {
+ return resourceIdentifier;
+ }
+
+ public void setResourceIdentifier( String resourceIdentifier )
+ {
+ this.resourceIdentifier = resourceIdentifier;
+ }
+
+ public boolean isPattern()
+ {
+ return isPattern;
+ }
+
+ public void setPattern( boolean isPattern )
+ {
+ this.isPattern = isPattern;
+ }
+
+ 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/ResourcesAction.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/ResourcesAction.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision