mirror of https://github.com/apache/archiva.git
UserManagementAction is now implementing the SecureAction interface from plexus-security, all action statements in the xwork.xml using this Action now require authenticated sessions and that the user using them has edit-user or edit-all-users operations granted. Before we go any further on these I am hoping folks can take a peek and see if its too clunky or if perhaps we should change the interfaces for this type of functionality.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@443495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8f32614cf9
commit
4ef19c632b
|
@ -1,21 +1,20 @@
|
||||||
package org.apache.maven.archiva.web.action.admin;
|
package org.apache.maven.archiva.web.action.admin;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2005 The Apache Software Foundation.
|
* Copyright 2005 The Apache Software Foundation.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.opensymphony.xwork.Preparable;
|
import com.opensymphony.xwork.Preparable;
|
||||||
import org.codehaus.plexus.security.rbac.RBACManager;
|
import org.codehaus.plexus.security.rbac.RBACManager;
|
||||||
|
@ -23,6 +22,9 @@ import org.codehaus.plexus.security.system.SecuritySession;
|
||||||
import org.codehaus.plexus.security.user.User;
|
import org.codehaus.plexus.security.user.User;
|
||||||
import org.codehaus.plexus.security.user.UserManager;
|
import org.codehaus.plexus.security.user.UserManager;
|
||||||
import org.codehaus.plexus.security.user.UserNotFoundException;
|
import org.codehaus.plexus.security.user.UserNotFoundException;
|
||||||
|
import org.codehaus.plexus.security.user.UserManagerException;
|
||||||
|
import org.codehaus.plexus.security.authorization.rbac.web.interceptor.SecureAction;
|
||||||
|
import org.codehaus.plexus.security.authorization.rbac.web.interceptor.SecureActionException;
|
||||||
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
|
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -38,7 +40,8 @@ import java.util.List;
|
||||||
* role-hint="userManagement"
|
* role-hint="userManagement"
|
||||||
*/
|
*/
|
||||||
public class UserManagementAction
|
public class UserManagementAction
|
||||||
extends PlexusActionSupport implements Preparable
|
extends PlexusActionSupport
|
||||||
|
implements Preparable, SecureAction
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @plexus.requirement
|
* @plexus.requirement
|
||||||
|
@ -73,38 +76,51 @@ public class UserManagementAction
|
||||||
public void prepare()
|
public void prepare()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
if ( username == null || "".equals( username ) )
|
try
|
||||||
{
|
{
|
||||||
user = userManager.findUser( (String) session.get( "MANAGED_USERNAME" ) );
|
if ( username == null || "".equals( username ) )
|
||||||
username = user.getUsername();
|
{
|
||||||
|
user = userManager.findUser( (String) session.get( "MANAGED_USERNAME" ) );
|
||||||
|
username = user.getUsername();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
user = userManager.findUser( username );
|
||||||
|
}
|
||||||
|
|
||||||
|
session.put( "MANAGED_USERNAME", username );
|
||||||
|
|
||||||
|
principal = user.getPrincipal().toString();
|
||||||
|
fullName = user.getFullName();
|
||||||
|
email = user.getEmail();
|
||||||
|
|
||||||
|
if ( principal != null && rbacManager.userAssignmentExists( principal ) )
|
||||||
|
{
|
||||||
|
assignedRoles = new ArrayList( rbacManager.getAssignedRoles( principal ) );
|
||||||
|
availableRoles = new ArrayList( rbacManager.getUnassignedRoles( principal ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assignedRoles = new ArrayList();
|
||||||
|
availableRoles = rbacManager.getAllAssignableRoles();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch ( UserNotFoundException ne )
|
||||||
{
|
{
|
||||||
user = userManager.findUser( username );
|
addActionError( "user cound not found" );
|
||||||
|
assignedRoles = new ArrayList();
|
||||||
|
availableRoles = new ArrayList();
|
||||||
}
|
}
|
||||||
|
catch ( UserManagerException ume )
|
||||||
session.put( "MANAGED_USERNAME", username );
|
|
||||||
|
|
||||||
principal = user.getPrincipal().toString();
|
|
||||||
fullName = user.getFullName();
|
|
||||||
email = user.getEmail();
|
|
||||||
|
|
||||||
if ( principal != null && rbacManager.userAssignmentExists( principal ) )
|
|
||||||
{
|
|
||||||
assignedRoles = new ArrayList( rbacManager.getAssignedRoles( principal ) );
|
|
||||||
availableRoles = new ArrayList( rbacManager.getUnassignedRoles( principal ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
assignedRoles = new ArrayList();
|
assignedRoles = new ArrayList();
|
||||||
availableRoles = rbacManager.getAllAssignableRoles();
|
availableRoles = new ArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for this method username should be populated
|
* for this method username should be populated
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String findUser()
|
public String findUser()
|
||||||
|
@ -124,7 +140,7 @@ public class UserManagementAction
|
||||||
}
|
}
|
||||||
catch ( UserNotFoundException ne )
|
catch ( UserNotFoundException ne )
|
||||||
{
|
{
|
||||||
addActionError( "user could not be found " + username );
|
addActionError( "user could not be found " + username );
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,6 +178,39 @@ public class UserManagementAction
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List getRequiredOperations()
|
||||||
|
throws SecureActionException
|
||||||
|
{
|
||||||
|
List operations = new ArrayList();
|
||||||
|
operations.add( "edit-all-users" );
|
||||||
|
operations.add( "edit-user" );
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRequiredResource()
|
||||||
|
throws SecureActionException
|
||||||
|
{
|
||||||
|
SecuritySession securitySession = (SecuritySession) session.get( SecuritySession.ROLE );
|
||||||
|
|
||||||
|
User user = securitySession.getUser();
|
||||||
|
|
||||||
|
if ( user != null )
|
||||||
|
{
|
||||||
|
return user.getPrincipal().toString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new SecureActionException( "unable to obtain principal from users session" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean authenticationRequired()
|
||||||
|
throws SecureActionException
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUsername()
|
public String getUsername()
|
||||||
{
|
{
|
||||||
return username;
|
return username;
|
||||||
|
|
|
@ -26,13 +26,16 @@
|
||||||
<package name="base" extends="webwork-default">
|
<package name="base" extends="webwork-default">
|
||||||
<interceptors>
|
<interceptors>
|
||||||
<interceptor name="configuration" class="configurationInterceptor"/>
|
<interceptor name="configuration" class="configurationInterceptor"/>
|
||||||
|
<interceptor name="pssSecureActions" class="pssSecureActionInterceptor"/>
|
||||||
<interceptor-stack name="configuredStack">
|
<interceptor-stack name="configuredStack">
|
||||||
<interceptor-ref name="defaultStack"/>
|
<interceptor-ref name="defaultStack"/>
|
||||||
<interceptor-ref name="configuration"/>
|
<interceptor-ref name="configuration"/>
|
||||||
|
<interceptor-ref name="pssSecureActions"/>
|
||||||
</interceptor-stack>
|
</interceptor-stack>
|
||||||
<interceptor-stack name="configuredPrepareParamsStack">
|
<interceptor-stack name="configuredPrepareParamsStack">
|
||||||
<interceptor-ref name="paramsPrepareParamsStack"/>
|
<interceptor-ref name="paramsPrepareParamsStack"/>
|
||||||
<interceptor-ref name="configuration"/>
|
<interceptor-ref name="configuration"/>
|
||||||
|
<interceptor-ref name="pssSecureActions"/>
|
||||||
</interceptor-stack>
|
</interceptor-stack>
|
||||||
</interceptors>
|
</interceptors>
|
||||||
|
|
||||||
|
@ -57,6 +60,8 @@
|
||||||
<param name="method">input</param>
|
<param name="method">input</param>
|
||||||
</result>
|
</result>
|
||||||
<result name="error">/WEB-INF/jsp/generalError.jsp</result>
|
<result name="error">/WEB-INF/jsp/generalError.jsp</result>
|
||||||
|
<result name="requires-authentication">/WEB-INF/jsp/alert.jsp</result>
|
||||||
|
<result name="requires-authorization">/WEB-INF/jsp/alert.jsp</result>
|
||||||
</global-results>
|
</global-results>
|
||||||
</package>
|
</package>
|
||||||
|
|
||||||
|
@ -67,6 +72,7 @@
|
||||||
<interceptor-stack name="configuredStack">
|
<interceptor-stack name="configuredStack">
|
||||||
<interceptor-ref name="defaultStack"/>
|
<interceptor-ref name="defaultStack"/>
|
||||||
<interceptor-ref name="configuration"/>
|
<interceptor-ref name="configuration"/>
|
||||||
|
<interceptor-ref name="pssSecureActions"/>
|
||||||
</interceptor-stack>
|
</interceptor-stack>
|
||||||
</interceptors>
|
</interceptors>
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
|
|
||||||
<div id="contentArea">
|
<div id="contentArea">
|
||||||
<div id="searchBox">
|
<div id="searchBox">
|
||||||
|
<div id="results">
|
||||||
|
<ww:actionerror/>
|
||||||
|
</div>
|
||||||
<ww:form action="userManagement" method="post" namespace="/admin">
|
<ww:form action="userManagement" method="post" namespace="/admin">
|
||||||
<p>
|
<p>
|
||||||
<ww:textfield label="Find a user" name="username"/>
|
<ww:textfield label="Find a user" name="username"/>
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<%--
|
||||||
|
~ Copyright 2005-2006 The Apache Software 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.
|
||||||
|
--%>
|
||||||
|
|
||||||
|
<%@ taglib prefix="ww" uri="/webwork" %>
|
||||||
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Security Alert Page</title>
|
||||||
|
<ww:head/>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="contentArea">
|
||||||
|
<div id="searchBox">
|
||||||
|
<div id="results">
|
||||||
|
You are not authorized for this activity.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="clear">
|
||||||
|
<hr/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in New Issue