1 package org.apache.archiva.redback.struts2.action.admin;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.redback.rbac.RBACManager;
23 import org.apache.archiva.redback.rbac.RbacObjectInvalidException;
24 import org.apache.archiva.redback.rbac.Resource;
25 import org.apache.archiva.redback.struts2.action.AbstractSecurityAction;
26 import org.apache.archiva.redback.users.User;
27 import org.apache.archiva.redback.users.UserManager;
28 import org.apache.archiva.redback.rbac.RbacManagerException;
29 import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
30 import org.apache.archiva.redback.struts2.action.AuditEvent;
31 import org.apache.archiva.redback.struts2.action.CancellableAction;
32 import org.apache.archiva.redback.users.UserNotFoundException;
33 import org.codehaus.plexus.util.StringUtils;
34 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
35 import org.apache.archiva.redback.integration.interceptor.SecureActionException;
36 import org.apache.archiva.redback.integration.role.RoleConstants;
37 import org.springframework.context.annotation.Scope;
38 import org.springframework.stereotype.Controller;
40 import javax.inject.Inject;
41 import javax.inject.Named;
42 import java.util.Arrays;
47 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
50 @Controller( "redback-admin-user-delete" )
52 public class UserDeleteAction
53 extends AbstractSecurityAction
54 implements CancellableAction
56 // ------------------------------------------------------------------
57 // Component Requirements
58 // ------------------------------------------------------------------
61 * role-hint="configurable"
64 @Named( value = "userManager#configurable" )
65 private UserManager userManager;
71 @Named( value = "rBACManager#cached" )
72 private RBACManager rbacManager;
74 // ------------------------------------------------------------------
76 // ------------------------------------------------------------------
78 private String username;
82 // ------------------------------------------------------------------
83 // Action Entry Points - (aka Names)
84 // ------------------------------------------------------------------
86 public String confirm()
88 if ( username == null )
90 addActionError( getText( "cannot.remove.user.null.username" ) );
96 user = userManager.findUser( username );
98 catch ( UserNotFoundException e )
100 addActionError( getText( "cannot.remove.user.not.found", Arrays.asList( (Object) username ) ) );
107 public String submit()
109 if ( username == null )
111 addActionError( getText( "invalid.user.credentials" ) );
115 if ( StringUtils.isEmpty( username ) )
117 addActionError( getText( "cannot.remove.user.empty.username" ) );
123 rbacManager.removeUserAssignment( username );
125 catch ( RbacObjectNotFoundException e )
127 // ignore, this is possible since the user may never have had roles assigned
129 catch ( RbacObjectInvalidException e )
131 addActionError( getText( "cannot.remove.user.role", Arrays.asList( (Object) username, e.getMessage() ) ) );
133 catch ( RbacManagerException e )
135 addActionError( getText( "cannot.remove.user.role", Arrays.asList( (Object) username, e.getMessage() ) ) );
138 if ( getActionErrors().isEmpty() )
142 userManager.deleteUser( username );
144 catch ( UserNotFoundException e )
146 addActionError( getText( "cannot.remove.user.non.existent", Arrays.asList( (Object) username ) ) );
149 String currentUser = getCurrentUser();
151 AuditEvent event = new AuditEvent( getText( "log.account.delete" ) );
152 event.setAffectedUser( username );
153 event.setCurrentUser( currentUser );
160 * Returns the cancel result. <p/> A basic implementation would simply be to return CANCEL.
164 public String cancel()
169 // ------------------------------------------------------------------
170 // Parameter Accessor Methods
171 // ------------------------------------------------------------------
173 public String getUsername()
178 public void setUsername( String username )
180 this.username = username;
183 public User getUser()
188 public void setUser( User user )
193 public SecureActionBundle initSecureActionBundle()
194 throws SecureActionException
196 SecureActionBundle bundle = new SecureActionBundle();
197 bundle.setRequiresAuthentication( true );
198 bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_DELETE_OPERATION, Resource.GLOBAL );