mirror of https://github.com/apache/archiva.git
add a lot of missing eol-style native
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1176606 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b3a0ceb37d
commit
3c247ba1f8
|
@ -1,355 +1,355 @@
|
||||||
package org.apache.archiva.web.action;
|
package org.apache.archiva.web.action;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.opensymphony.xwork2.ActionContext;
|
import com.opensymphony.xwork2.ActionContext;
|
||||||
import com.opensymphony.xwork2.ActionSupport;
|
import com.opensymphony.xwork2.ActionSupport;
|
||||||
import org.apache.archiva.admin.model.AuditInformation;
|
import org.apache.archiva.admin.model.AuditInformation;
|
||||||
import org.apache.archiva.audit.AuditEvent;
|
import org.apache.archiva.audit.AuditEvent;
|
||||||
import org.apache.archiva.audit.AuditListener;
|
import org.apache.archiva.audit.AuditListener;
|
||||||
import org.apache.archiva.audit.Auditable;
|
import org.apache.archiva.audit.Auditable;
|
||||||
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
|
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
|
||||||
import org.apache.archiva.security.ArchivaXworkUser;
|
import org.apache.archiva.security.ArchivaXworkUser;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.struts2.ServletActionContext;
|
import org.apache.struts2.ServletActionContext;
|
||||||
import org.apache.struts2.interceptor.SessionAware;
|
import org.apache.struts2.interceptor.SessionAware;
|
||||||
import org.codehaus.plexus.redback.users.User;
|
import org.codehaus.plexus.redback.users.User;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LogEnabled and SessionAware ActionSupport
|
* LogEnabled and SessionAware ActionSupport
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractActionSupport
|
public abstract class AbstractActionSupport
|
||||||
extends ActionSupport
|
extends ActionSupport
|
||||||
implements SessionAware, Auditable
|
implements SessionAware, Auditable
|
||||||
{
|
{
|
||||||
protected Map<?, ?> session;
|
protected Map<?, ?> session;
|
||||||
|
|
||||||
protected Logger log = LoggerFactory.getLogger( getClass() );
|
protected Logger log = LoggerFactory.getLogger( getClass() );
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
|
private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "repositorySessionFactory" )
|
@Named( value = "repositorySessionFactory" )
|
||||||
protected RepositorySessionFactory repositorySessionFactory;
|
protected RepositorySessionFactory repositorySessionFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected ApplicationContext applicationContext;
|
protected ApplicationContext applicationContext;
|
||||||
|
|
||||||
private String principal;
|
private String principal;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initialize()
|
public void initialize()
|
||||||
{
|
{
|
||||||
// no op
|
// no op
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
public void setSession( Map map )
|
public void setSession( Map map )
|
||||||
{
|
{
|
||||||
this.session = map;
|
this.session = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAuditListener( AuditListener listener )
|
public void addAuditListener( AuditListener listener )
|
||||||
{
|
{
|
||||||
this.auditListeners.add( listener );
|
this.auditListeners.add( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearAuditListeners()
|
public void clearAuditListeners()
|
||||||
{
|
{
|
||||||
this.auditListeners.clear();
|
this.auditListeners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAuditListener( AuditListener listener )
|
public void removeAuditListener( AuditListener listener )
|
||||||
{
|
{
|
||||||
this.auditListeners.remove( listener );
|
this.auditListeners.remove( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void triggerAuditEvent( String repositoryId, String resource, String action )
|
protected void triggerAuditEvent( String repositoryId, String resource, String action )
|
||||||
{
|
{
|
||||||
AuditEvent event = new AuditEvent( repositoryId, getPrincipal(), resource, action );
|
AuditEvent event = new AuditEvent( repositoryId, getPrincipal(), resource, action );
|
||||||
event.setRemoteIP( getRemoteAddr() );
|
event.setRemoteIP( getRemoteAddr() );
|
||||||
|
|
||||||
for ( AuditListener listener : auditListeners )
|
for ( AuditListener listener : auditListeners )
|
||||||
{
|
{
|
||||||
listener.auditEvent( event );
|
listener.auditEvent( event );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void triggerAuditEvent( String resource, String action )
|
protected void triggerAuditEvent( String resource, String action )
|
||||||
{
|
{
|
||||||
AuditEvent event = new AuditEvent( null, getPrincipal(), resource, action );
|
AuditEvent event = new AuditEvent( null, getPrincipal(), resource, action );
|
||||||
event.setRemoteIP( getRemoteAddr() );
|
event.setRemoteIP( getRemoteAddr() );
|
||||||
|
|
||||||
for ( AuditListener listener : auditListeners )
|
for ( AuditListener listener : auditListeners )
|
||||||
{
|
{
|
||||||
listener.auditEvent( event );
|
listener.auditEvent( event );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void triggerAuditEvent( String action )
|
protected void triggerAuditEvent( String action )
|
||||||
{
|
{
|
||||||
AuditEvent event = new AuditEvent( null, getPrincipal(), null, action );
|
AuditEvent event = new AuditEvent( null, getPrincipal(), null, action );
|
||||||
event.setRemoteIP( getRemoteAddr() );
|
event.setRemoteIP( getRemoteAddr() );
|
||||||
|
|
||||||
for ( AuditListener listener : auditListeners )
|
for ( AuditListener listener : auditListeners )
|
||||||
{
|
{
|
||||||
listener.auditEvent( event );
|
listener.auditEvent( event );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRemoteAddr()
|
private String getRemoteAddr()
|
||||||
{
|
{
|
||||||
HttpServletRequest request = ServletActionContext.getRequest();
|
HttpServletRequest request = ServletActionContext.getRequest();
|
||||||
return request != null ? request.getRemoteAddr() : null;
|
return request != null ? request.getRemoteAddr() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
protected String getPrincipal()
|
protected String getPrincipal()
|
||||||
{
|
{
|
||||||
if ( principal != null )
|
if ( principal != null )
|
||||||
{
|
{
|
||||||
return principal;
|
return principal;
|
||||||
}
|
}
|
||||||
return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
|
return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPrincipal( String principal )
|
void setPrincipal( String principal )
|
||||||
{
|
{
|
||||||
this.principal = principal;
|
this.principal = principal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuditListeners( List<AuditListener> auditListeners )
|
public void setAuditListeners( List<AuditListener> auditListeners )
|
||||||
{
|
{
|
||||||
this.auditListeners = auditListeners;
|
this.auditListeners = auditListeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory )
|
public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory )
|
||||||
{
|
{
|
||||||
this.repositorySessionFactory = repositorySessionFactory;
|
this.repositorySessionFactory = repositorySessionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> Map<String, T> getBeansOfType( Class<T> clazz )
|
protected <T> Map<String, T> getBeansOfType( Class<T> clazz )
|
||||||
{
|
{
|
||||||
//TODO do some caching here !!!
|
//TODO do some caching here !!!
|
||||||
// olamy : with plexus we get only roleHint
|
// olamy : with plexus we get only roleHint
|
||||||
// as per convention we named spring bean role#hint remove role# if exists
|
// as per convention we named spring bean role#hint remove role# if exists
|
||||||
Map<String, T> springBeans = applicationContext.getBeansOfType( clazz );
|
Map<String, T> springBeans = applicationContext.getBeansOfType( clazz );
|
||||||
|
|
||||||
Map<String, T> beans = new HashMap<String, T>( springBeans.size() );
|
Map<String, T> beans = new HashMap<String, T>( springBeans.size() );
|
||||||
|
|
||||||
for ( Map.Entry<String, T> entry : springBeans.entrySet() )
|
for ( Map.Entry<String, T> entry : springBeans.entrySet() )
|
||||||
{
|
{
|
||||||
String key = StringUtils.substringAfterLast( entry.getKey(), "#" );
|
String key = StringUtils.substringAfterLast( entry.getKey(), "#" );
|
||||||
beans.put( key, entry.getValue() );
|
beans.put( key, entry.getValue() );
|
||||||
}
|
}
|
||||||
return beans;
|
return beans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected AuditInformation getAuditInformation()
|
protected AuditInformation getAuditInformation()
|
||||||
{
|
{
|
||||||
AuditInformation auditInformation = new AuditInformation( new SimpleUser( getPrincipal() ), getRemoteAddr() );
|
AuditInformation auditInformation = new AuditInformation( new SimpleUser( getPrincipal() ), getRemoteAddr() );
|
||||||
|
|
||||||
return auditInformation;
|
return auditInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dummy information for audit events
|
* dummy information for audit events
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
private static class SimpleUser
|
private static class SimpleUser
|
||||||
implements User
|
implements User
|
||||||
{
|
{
|
||||||
|
|
||||||
private String principal;
|
private String principal;
|
||||||
|
|
||||||
protected SimpleUser( String principal )
|
protected SimpleUser( String principal )
|
||||||
{
|
{
|
||||||
this.principal = principal;
|
this.principal = principal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getPrincipal()
|
public Object getPrincipal()
|
||||||
{
|
{
|
||||||
return this.principal;
|
return this.principal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername()
|
public String getUsername()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsername( String name )
|
public void setUsername( String name )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFullName()
|
public String getFullName()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFullName( String name )
|
public void setFullName( String name )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmail()
|
public String getEmail()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEmail( String address )
|
public void setEmail( String address )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword()
|
public String getPassword()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword( String rawPassword )
|
public void setPassword( String rawPassword )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEncodedPassword()
|
public String getEncodedPassword()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEncodedPassword( String encodedPassword )
|
public void setEncodedPassword( String encodedPassword )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getLastPasswordChange()
|
public Date getLastPasswordChange()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastPasswordChange( Date passwordChangeDate )
|
public void setLastPasswordChange( Date passwordChangeDate )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPreviousEncodedPasswords()
|
public List<String> getPreviousEncodedPasswords()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
|
public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPreviousEncodedPassword( String encodedPassword )
|
public void addPreviousEncodedPassword( String encodedPassword )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPermanent()
|
public boolean isPermanent()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPermanent( boolean permanent )
|
public void setPermanent( boolean permanent )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLocked()
|
public boolean isLocked()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocked( boolean locked )
|
public void setLocked( boolean locked )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPasswordChangeRequired()
|
public boolean isPasswordChangeRequired()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPasswordChangeRequired( boolean changeRequired )
|
public void setPasswordChangeRequired( boolean changeRequired )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidated()
|
public boolean isValidated()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValidated( boolean valid )
|
public void setValidated( boolean valid )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCountFailedLoginAttempts()
|
public int getCountFailedLoginAttempts()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCountFailedLoginAttempts( int count )
|
public void setCountFailedLoginAttempts( int count )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getAccountCreationDate()
|
public Date getAccountCreationDate()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccountCreationDate( Date date )
|
public void setAccountCreationDate( Date date )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getLastLoginDate()
|
public Date getLastLoginDate()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastLoginDate( Date date )
|
public void setLastLoginDate( Date date )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,80 +1,80 @@
|
||||||
package org.apache.archiva.web.action.admin.legacy;
|
package org.apache.archiva.web.action.admin.legacy;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
import org.apache.archiva.admin.model.RepositoryAdminException;
|
||||||
import org.apache.archiva.admin.model.admin.ArchivaAdministration;
|
import org.apache.archiva.admin.model.admin.ArchivaAdministration;
|
||||||
import org.apache.archiva.web.action.AbstractActionSupport;
|
import org.apache.archiva.web.action.AbstractActionSupport;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a LegacyArtifactPath to archiva configuration
|
* Delete a LegacyArtifactPath to archiva configuration
|
||||||
*
|
*
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
@Controller( "deleteLegacyArtifactPathAction" )
|
@Controller( "deleteLegacyArtifactPathAction" )
|
||||||
@Scope( "prototype" )
|
@Scope( "prototype" )
|
||||||
public class DeleteLegacyArtifactPathAction
|
public class DeleteLegacyArtifactPathAction
|
||||||
extends AbstractActionSupport
|
extends AbstractActionSupport
|
||||||
{
|
{
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ArchivaAdministration archivaAdministration;
|
private ArchivaAdministration archivaAdministration;
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
public String delete()
|
public String delete()
|
||||||
{
|
{
|
||||||
log.info( "remove [" + path + "] from legacy artifact path resolution" );
|
log.info( "remove [" + path + "] from legacy artifact path resolution" );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
getArchivaAdministration().deleteLegacyArtifactPath( path, getAuditInformation() );
|
getArchivaAdministration().deleteLegacyArtifactPath( path, getAuditInformation() );
|
||||||
}
|
}
|
||||||
catch ( RepositoryAdminException e )
|
catch ( RepositoryAdminException e )
|
||||||
{
|
{
|
||||||
log.error( e.getMessage(), e );
|
log.error( e.getMessage(), e );
|
||||||
addActionError( "Exception during delete " + e.getMessage() );
|
addActionError( "Exception during delete " + e.getMessage() );
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath()
|
public String getPath()
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPath( String path )
|
public void setPath( String path )
|
||||||
{
|
{
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArchivaAdministration getArchivaAdministration()
|
public ArchivaAdministration getArchivaAdministration()
|
||||||
{
|
{
|
||||||
return archivaAdministration;
|
return archivaAdministration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArchivaAdministration( ArchivaAdministration archivaAdministration )
|
public void setArchivaAdministration( ArchivaAdministration archivaAdministration )
|
||||||
{
|
{
|
||||||
this.archivaAdministration = archivaAdministration;
|
this.archivaAdministration = archivaAdministration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,106 +1,106 @@
|
||||||
package org.apache.archiva.web.action.admin.legacy;
|
package org.apache.archiva.web.action.admin.legacy;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.opensymphony.xwork2.Preparable;
|
import com.opensymphony.xwork2.Preparable;
|
||||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
import org.apache.archiva.admin.model.RepositoryAdminException;
|
||||||
import org.apache.archiva.admin.model.admin.ArchivaAdministration;
|
import org.apache.archiva.admin.model.admin.ArchivaAdministration;
|
||||||
import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
|
import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
|
||||||
import org.apache.archiva.security.common.ArchivaRoleConstants;
|
import org.apache.archiva.security.common.ArchivaRoleConstants;
|
||||||
import org.apache.archiva.web.util.ContextUtils;
|
import org.apache.archiva.web.util.ContextUtils;
|
||||||
import org.apache.archiva.web.action.AbstractActionSupport;
|
import org.apache.archiva.web.action.AbstractActionSupport;
|
||||||
import org.apache.struts2.interceptor.ServletRequestAware;
|
import org.apache.struts2.interceptor.ServletRequestAware;
|
||||||
import org.codehaus.plexus.redback.rbac.Resource;
|
import org.codehaus.plexus.redback.rbac.Resource;
|
||||||
import org.codehaus.redback.integration.interceptor.SecureAction;
|
import org.codehaus.redback.integration.interceptor.SecureAction;
|
||||||
import org.codehaus.redback.integration.interceptor.SecureActionBundle;
|
import org.codehaus.redback.integration.interceptor.SecureActionBundle;
|
||||||
import org.codehaus.redback.integration.interceptor.SecureActionException;
|
import org.codehaus.redback.integration.interceptor.SecureActionException;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the LegacyArtifactPath Tab for the administrator.
|
* Shows the LegacyArtifactPath Tab for the administrator.
|
||||||
*
|
*
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
@Controller( "legacyArtifactPathAction" )
|
@Controller( "legacyArtifactPathAction" )
|
||||||
@Scope( "prototype" )
|
@Scope( "prototype" )
|
||||||
public class LegacyArtifactPathAction
|
public class LegacyArtifactPathAction
|
||||||
extends AbstractActionSupport
|
extends AbstractActionSupport
|
||||||
implements SecureAction, ServletRequestAware, Preparable
|
implements SecureAction, ServletRequestAware, Preparable
|
||||||
{
|
{
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ArchivaAdministration archivaAdministration;
|
private ArchivaAdministration archivaAdministration;
|
||||||
|
|
||||||
private List<LegacyArtifactPath> legacyArtifactPaths;
|
private List<LegacyArtifactPath> legacyArtifactPaths;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to construct the repository WebDAV URL in the repository action.
|
* Used to construct the repository WebDAV URL in the repository action.
|
||||||
*/
|
*/
|
||||||
private String baseUrl;
|
private String baseUrl;
|
||||||
|
|
||||||
public void setServletRequest( HttpServletRequest request )
|
public void setServletRequest( HttpServletRequest request )
|
||||||
{
|
{
|
||||||
// TODO: is there a better way to do this?
|
// TODO: is there a better way to do this?
|
||||||
this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
|
this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecureActionBundle getSecureActionBundle()
|
public SecureActionBundle getSecureActionBundle()
|
||||||
throws SecureActionException
|
throws SecureActionException
|
||||||
{
|
{
|
||||||
SecureActionBundle bundle = new SecureActionBundle();
|
SecureActionBundle bundle = new SecureActionBundle();
|
||||||
|
|
||||||
bundle.setRequiresAuthentication( true );
|
bundle.setRequiresAuthentication( true );
|
||||||
bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
|
bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
|
||||||
|
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prepare()
|
public void prepare()
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
legacyArtifactPaths = new ArrayList<LegacyArtifactPath>( getArchivaAdministration().getLegacyArtifactPaths() );
|
legacyArtifactPaths = new ArrayList<LegacyArtifactPath>( getArchivaAdministration().getLegacyArtifactPaths() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LegacyArtifactPath> getLegacyArtifactPaths()
|
public List<LegacyArtifactPath> getLegacyArtifactPaths()
|
||||||
{
|
{
|
||||||
return legacyArtifactPaths;
|
return legacyArtifactPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBaseUrl()
|
public String getBaseUrl()
|
||||||
{
|
{
|
||||||
return baseUrl;
|
return baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArchivaAdministration getArchivaAdministration()
|
public ArchivaAdministration getArchivaAdministration()
|
||||||
{
|
{
|
||||||
return archivaAdministration;
|
return archivaAdministration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArchivaAdministration( ArchivaAdministration archivaAdministration )
|
public void setArchivaAdministration( ArchivaAdministration archivaAdministration )
|
||||||
{
|
{
|
||||||
this.archivaAdministration = archivaAdministration;
|
this.archivaAdministration = archivaAdministration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,155 +1,155 @@
|
||||||
package org.apache.archiva.web.xmlrpc.security;
|
package org.apache.archiva.web.xmlrpc.security;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.archiva.security.ArchivaRoleConstants;
|
import org.apache.archiva.security.ArchivaRoleConstants;
|
||||||
import org.apache.archiva.security.ArchivaSecurityException;
|
import org.apache.archiva.security.ArchivaSecurityException;
|
||||||
import org.apache.archiva.security.UserRepositories;
|
import org.apache.archiva.security.UserRepositories;
|
||||||
import org.apache.xmlrpc.XmlRpcException;
|
import org.apache.xmlrpc.XmlRpcException;
|
||||||
import org.apache.xmlrpc.XmlRpcRequest;
|
import org.apache.xmlrpc.XmlRpcRequest;
|
||||||
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
|
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
|
||||||
import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
|
import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
|
||||||
import org.codehaus.plexus.redback.authentication.AuthenticationException;
|
import org.codehaus.plexus.redback.authentication.AuthenticationException;
|
||||||
import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
|
import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
|
||||||
import org.codehaus.plexus.redback.authorization.AuthorizationException;
|
import org.codehaus.plexus.redback.authorization.AuthorizationException;
|
||||||
import org.codehaus.plexus.redback.authorization.AuthorizationResult;
|
import org.codehaus.plexus.redback.authorization.AuthorizationResult;
|
||||||
import org.codehaus.plexus.redback.policy.PolicyViolationException;
|
import org.codehaus.plexus.redback.policy.PolicyViolationException;
|
||||||
import org.codehaus.plexus.redback.system.SecuritySession;
|
import org.codehaus.plexus.redback.system.SecuritySession;
|
||||||
import org.codehaus.plexus.redback.system.SecuritySystem;
|
import org.codehaus.plexus.redback.system.SecuritySystem;
|
||||||
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XmlRpcAuthenticator
|
* XmlRpcAuthenticator
|
||||||
*
|
*
|
||||||
* Custom authentication and authorization handler for xmlrpc requests.
|
* Custom authentication and authorization handler for xmlrpc requests.
|
||||||
*
|
*
|
||||||
* @version $Id
|
* @version $Id
|
||||||
*/
|
*/
|
||||||
public class XmlRpcAuthenticator
|
public class XmlRpcAuthenticator
|
||||||
implements AuthenticationHandler
|
implements AuthenticationHandler
|
||||||
{
|
{
|
||||||
private final SecuritySystem securitySystem;
|
private final SecuritySystem securitySystem;
|
||||||
|
|
||||||
private UserRepositories userRepositories;
|
private UserRepositories userRepositories;
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
public XmlRpcAuthenticator( SecuritySystem securitySystem, UserRepositories userRepositories )
|
public XmlRpcAuthenticator( SecuritySystem securitySystem, UserRepositories userRepositories )
|
||||||
{
|
{
|
||||||
this.securitySystem = securitySystem;
|
this.securitySystem = securitySystem;
|
||||||
this.userRepositories = userRepositories;
|
this.userRepositories = userRepositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthorized( XmlRpcRequest pRequest )
|
public boolean isAuthorized( XmlRpcRequest pRequest )
|
||||||
throws XmlRpcException
|
throws XmlRpcException
|
||||||
{
|
{
|
||||||
if ( pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl )
|
if ( pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl )
|
||||||
{
|
{
|
||||||
XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl) pRequest.getConfig();
|
XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl) pRequest.getConfig();
|
||||||
username = config.getBasicUserName();
|
username = config.getBasicUserName();
|
||||||
SecuritySession session =
|
SecuritySession session =
|
||||||
authenticate( new PasswordBasedAuthenticationDataSource( username,
|
authenticate( new PasswordBasedAuthenticationDataSource( username,
|
||||||
config.getBasicPassword() ) );
|
config.getBasicPassword() ) );
|
||||||
|
|
||||||
String method = pRequest.getMethodName();
|
String method = pRequest.getMethodName();
|
||||||
AuthorizationResult result = authorize( session, method, username );
|
AuthorizationResult result = authorize( session, method, username );
|
||||||
|
|
||||||
return result.isAuthorized();
|
return result.isAuthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new XmlRpcException( "Unsupported transport (must be http)" );
|
throw new XmlRpcException( "Unsupported transport (must be http)" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private SecuritySession authenticate( PasswordBasedAuthenticationDataSource authenticationDataSource )
|
private SecuritySession authenticate( PasswordBasedAuthenticationDataSource authenticationDataSource )
|
||||||
throws XmlRpcException
|
throws XmlRpcException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return securitySystem.authenticate( authenticationDataSource );
|
return securitySystem.authenticate( authenticationDataSource );
|
||||||
}
|
}
|
||||||
catch ( PolicyViolationException e )
|
catch ( PolicyViolationException e )
|
||||||
{
|
{
|
||||||
throw new XmlRpcException( 401, e.getMessage(), e );
|
throw new XmlRpcException( 401, e.getMessage(), e );
|
||||||
}
|
}
|
||||||
catch ( AuthenticationException e )
|
catch ( AuthenticationException e )
|
||||||
{
|
{
|
||||||
throw new XmlRpcException( 401, e.getMessage(), e );
|
throw new XmlRpcException( 401, e.getMessage(), e );
|
||||||
}
|
}
|
||||||
catch ( UserNotFoundException e )
|
catch ( UserNotFoundException e )
|
||||||
{
|
{
|
||||||
throw new XmlRpcException( 401, e.getMessage(), e );
|
throw new XmlRpcException( 401, e.getMessage(), e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuthorizationResult authorize( SecuritySession session, String methodName, String username )
|
private AuthorizationResult authorize( SecuritySession session, String methodName, String username )
|
||||||
throws XmlRpcException
|
throws XmlRpcException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// sample attempt at simplifying authorization checking of requested service method
|
// sample attempt at simplifying authorization checking of requested service method
|
||||||
if ( ServiceMethodsPermissionsMapping.SERVICE_METHODS_FOR_OPERATION_MANAGE_CONFIGURATION.contains( methodName ) )
|
if ( ServiceMethodsPermissionsMapping.SERVICE_METHODS_FOR_OPERATION_MANAGE_CONFIGURATION.contains( methodName ) )
|
||||||
{
|
{
|
||||||
return securitySystem.authorize( session, ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION );
|
return securitySystem.authorize( session, ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION );
|
||||||
}
|
}
|
||||||
else if ( ServiceMethodsPermissionsMapping.SERVICE_METHODS_FOR_OPERATION_RUN_INDEXER.contains( methodName ) )
|
else if ( ServiceMethodsPermissionsMapping.SERVICE_METHODS_FOR_OPERATION_RUN_INDEXER.contains( methodName ) )
|
||||||
{
|
{
|
||||||
return securitySystem.authorize( session, ArchivaRoleConstants.OPERATION_RUN_INDEXER );
|
return securitySystem.authorize( session, ArchivaRoleConstants.OPERATION_RUN_INDEXER );
|
||||||
}
|
}
|
||||||
else if ( ServiceMethodsPermissionsMapping.SERVICE_METHODS_FOR_OPERATION_REPOSITORY_ACCESS.contains( methodName ) )
|
else if ( ServiceMethodsPermissionsMapping.SERVICE_METHODS_FOR_OPERATION_REPOSITORY_ACCESS.contains( methodName ) )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<String> observableRepos = userRepositories.getObservableRepositoryIds( username );
|
List<String> observableRepos = userRepositories.getObservableRepositoryIds( username );
|
||||||
if( observableRepos != null && observableRepos.size() > 1 )
|
if( observableRepos != null && observableRepos.size() > 1 )
|
||||||
{
|
{
|
||||||
return new AuthorizationResult( true, username, null );
|
return new AuthorizationResult( true, username, null );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new AuthorizationResult( false, username, null );
|
return new AuthorizationResult( false, username, null );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( ArchivaSecurityException e )
|
catch ( ArchivaSecurityException e )
|
||||||
{
|
{
|
||||||
throw new XmlRpcException( 401, e.getMessage() );
|
throw new XmlRpcException( 401, e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( methodName.equals( ServiceMethodsPermissionsMapping.PING ) )
|
else if ( methodName.equals( ServiceMethodsPermissionsMapping.PING ) )
|
||||||
{
|
{
|
||||||
return new AuthorizationResult( true, username, null );
|
return new AuthorizationResult( true, username, null );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return securitySystem.authorize( session, ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE );
|
return securitySystem.authorize( session, ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( AuthorizationException e )
|
catch ( AuthorizationException e )
|
||||||
{
|
{
|
||||||
throw new XmlRpcException( 401, e.getMessage(), e );
|
throw new XmlRpcException( 401, e.getMessage(), e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getActiveUser()
|
public String getActiveUser()
|
||||||
{
|
{
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,240 +1,240 @@
|
||||||
package org.apache.archiva.xmlrpc.security;
|
package org.apache.archiva.xmlrpc.security;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.apache.archiva.web.xmlrpc.security.XmlRpcAuthenticator;
|
import org.apache.archiva.web.xmlrpc.security.XmlRpcAuthenticator;
|
||||||
import org.apache.archiva.security.ArchivaRoleConstants;
|
import org.apache.archiva.security.ArchivaRoleConstants;
|
||||||
import org.apache.xmlrpc.XmlRpcRequest;
|
import org.apache.xmlrpc.XmlRpcRequest;
|
||||||
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
|
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
|
||||||
import org.codehaus.plexus.redback.role.RoleManager;
|
import org.codehaus.plexus.redback.role.RoleManager;
|
||||||
import org.codehaus.plexus.redback.system.SecuritySystem;
|
import org.codehaus.plexus.redback.system.SecuritySystem;
|
||||||
import org.codehaus.plexus.redback.users.User;
|
import org.codehaus.plexus.redback.users.User;
|
||||||
import org.codehaus.plexus.redback.users.UserManager;
|
import org.codehaus.plexus.redback.users.UserManager;
|
||||||
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
||||||
import org.easymock.MockControl;
|
import org.easymock.MockControl;
|
||||||
import org.easymock.classextension.MockClassControl;
|
import org.easymock.classextension.MockClassControl;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XmlRpcAuthenticatorTest
|
* XmlRpcAuthenticatorTest
|
||||||
*
|
*
|
||||||
* @version $Id XmlRpcAuthenticatorTest.java
|
* @version $Id XmlRpcAuthenticatorTest.java
|
||||||
*/
|
*/
|
||||||
@RunWith( SpringJUnit4ClassRunner.class )
|
@RunWith( SpringJUnit4ClassRunner.class )
|
||||||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
||||||
public class XmlRpcAuthenticatorTest
|
public class XmlRpcAuthenticatorTest
|
||||||
extends TestCase
|
extends TestCase
|
||||||
{
|
{
|
||||||
protected static final String USER_GUEST = "guest";
|
protected static final String USER_GUEST = "guest";
|
||||||
|
|
||||||
protected static final String USER_ADMIN = "admin";
|
protected static final String USER_ADMIN = "admin";
|
||||||
|
|
||||||
protected static final String USER_ALPACA = "alpaca";
|
protected static final String USER_ALPACA = "alpaca";
|
||||||
|
|
||||||
private static final String PASSWORD = "password123";
|
private static final String PASSWORD = "password123";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "securitySystem#testable" )
|
@Named( value = "securitySystem#testable" )
|
||||||
protected SecuritySystem securitySystem;
|
protected SecuritySystem securitySystem;
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "roleManager#testable" )
|
@Named( value = "roleManager#testable" )
|
||||||
protected RoleManager roleManager;
|
protected RoleManager roleManager;
|
||||||
|
|
||||||
private MockControl xmlRpcRequestControl;
|
private MockControl xmlRpcRequestControl;
|
||||||
|
|
||||||
private XmlRpcRequest xmlRpcRequest;
|
private XmlRpcRequest xmlRpcRequest;
|
||||||
|
|
||||||
private XmlRpcAuthenticator authenticator;
|
private XmlRpcAuthenticator authenticator;
|
||||||
|
|
||||||
private MockControl configControl;
|
private MockControl configControl;
|
||||||
|
|
||||||
private XmlRpcHttpRequestConfigImpl config;
|
private XmlRpcHttpRequestConfigImpl config;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
//securitySystem = (SecuritySystem) lookup( SecuritySystem.class, "testable" );
|
//securitySystem = (SecuritySystem) lookup( SecuritySystem.class, "testable" );
|
||||||
//roleManager = (RoleManager) lookup( RoleManager.class, "default" );
|
//roleManager = (RoleManager) lookup( RoleManager.class, "default" );
|
||||||
|
|
||||||
// Some basic asserts.
|
// Some basic asserts.
|
||||||
assertNotNull( securitySystem );
|
assertNotNull( securitySystem );
|
||||||
assertNotNull( roleManager );
|
assertNotNull( roleManager );
|
||||||
|
|
||||||
// Setup Admin User.
|
// Setup Admin User.
|
||||||
User adminUser = createUser( USER_ADMIN, "Admin User", null );
|
User adminUser = createUser( USER_ADMIN, "Admin User", null );
|
||||||
roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_SYSTEM_ADMIN, adminUser.getPrincipal().toString() );
|
roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_SYSTEM_ADMIN, adminUser.getPrincipal().toString() );
|
||||||
|
|
||||||
// Setup Guest User.
|
// Setup Guest User.
|
||||||
User guestUser = createUser( USER_GUEST, "Guest User", null );
|
User guestUser = createUser( USER_GUEST, "Guest User", null );
|
||||||
roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_GUEST, guestUser.getPrincipal().toString() );
|
roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_GUEST, guestUser.getPrincipal().toString() );
|
||||||
|
|
||||||
configControl = MockClassControl.createControl( XmlRpcHttpRequestConfigImpl.class );
|
configControl = MockClassControl.createControl( XmlRpcHttpRequestConfigImpl.class );
|
||||||
config = (XmlRpcHttpRequestConfigImpl) configControl.getMock();
|
config = (XmlRpcHttpRequestConfigImpl) configControl.getMock();
|
||||||
|
|
||||||
xmlRpcRequestControl = MockControl.createControl( XmlRpcRequest.class );
|
xmlRpcRequestControl = MockControl.createControl( XmlRpcRequest.class );
|
||||||
xmlRpcRequest = (XmlRpcRequest) xmlRpcRequestControl.getMock();
|
xmlRpcRequest = (XmlRpcRequest) xmlRpcRequestControl.getMock();
|
||||||
|
|
||||||
authenticator = new XmlRpcAuthenticator( securitySystem, null );
|
authenticator = new XmlRpcAuthenticator( securitySystem, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
private User createUser( String principal, String fullname, String password )
|
private User createUser( String principal, String fullname, String password )
|
||||||
throws UserNotFoundException
|
throws UserNotFoundException
|
||||||
{
|
{
|
||||||
UserManager userManager = securitySystem.getUserManager();
|
UserManager userManager = securitySystem.getUserManager();
|
||||||
|
|
||||||
User user = userManager.createUser( principal, fullname, principal + "@testable.archiva.apache.org" );
|
User user = userManager.createUser( principal, fullname, principal + "@testable.archiva.apache.org" );
|
||||||
securitySystem.getPolicy().setEnabled( false );
|
securitySystem.getPolicy().setEnabled( false );
|
||||||
userManager.addUser( user );
|
userManager.addUser( user );
|
||||||
securitySystem.getPolicy().setEnabled( true );
|
securitySystem.getPolicy().setEnabled( true );
|
||||||
|
|
||||||
user.setPassword( password );
|
user.setPassword( password );
|
||||||
userManager.updateUser( user );
|
userManager.updateUser( user );
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAuthorizedUserExistsButNotAuthorized()
|
public void testIsAuthorizedUserExistsButNotAuthorized()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
createUser( USER_ALPACA, "Al 'Archiva' Paca", PASSWORD );
|
createUser( USER_ALPACA, "Al 'Archiva' Paca", PASSWORD );
|
||||||
|
|
||||||
UserManager userManager = securitySystem.getUserManager();
|
UserManager userManager = securitySystem.getUserManager();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
User user = userManager.findUser( USER_ALPACA );
|
User user = userManager.findUser( USER_ALPACA );
|
||||||
assertEquals( USER_ALPACA, user.getPrincipal() );
|
assertEquals( USER_ALPACA, user.getPrincipal() );
|
||||||
}
|
}
|
||||||
catch ( UserNotFoundException e )
|
catch ( UserNotFoundException e )
|
||||||
{
|
{
|
||||||
fail( "User should exist in the database." );
|
fail( "User should exist in the database." );
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getConfig(), config, 2 );
|
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getConfig(), config, 2 );
|
||||||
|
|
||||||
configControl.expectAndReturn( config.getBasicUserName(), USER_ALPACA );
|
configControl.expectAndReturn( config.getBasicUserName(), USER_ALPACA );
|
||||||
|
|
||||||
configControl.expectAndReturn( config.getBasicPassword(), PASSWORD );
|
configControl.expectAndReturn( config.getBasicPassword(), PASSWORD );
|
||||||
|
|
||||||
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getMethodName(),
|
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getMethodName(),
|
||||||
"AdministrationService.getAllManagedRepositories" );
|
"AdministrationService.getAllManagedRepositories" );
|
||||||
|
|
||||||
xmlRpcRequestControl.replay();
|
xmlRpcRequestControl.replay();
|
||||||
configControl.replay();
|
configControl.replay();
|
||||||
|
|
||||||
boolean isAuthorized = authenticator.isAuthorized( xmlRpcRequest );
|
boolean isAuthorized = authenticator.isAuthorized( xmlRpcRequest );
|
||||||
|
|
||||||
xmlRpcRequestControl.verify();
|
xmlRpcRequestControl.verify();
|
||||||
configControl.verify();
|
configControl.verify();
|
||||||
|
|
||||||
assertFalse( isAuthorized );
|
assertFalse( isAuthorized );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAuthorizedUserExistsAndAuthorized()
|
public void testIsAuthorizedUserExistsAndAuthorized()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
createUser( USER_ALPACA, "Al 'Archiva' Paca", PASSWORD );
|
createUser( USER_ALPACA, "Al 'Archiva' Paca", PASSWORD );
|
||||||
|
|
||||||
UserManager userManager = securitySystem.getUserManager();
|
UserManager userManager = securitySystem.getUserManager();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
User user = userManager.findUser( USER_ALPACA );
|
User user = userManager.findUser( USER_ALPACA );
|
||||||
assertEquals( USER_ALPACA, user.getPrincipal() );
|
assertEquals( USER_ALPACA, user.getPrincipal() );
|
||||||
}
|
}
|
||||||
catch ( UserNotFoundException e )
|
catch ( UserNotFoundException e )
|
||||||
{
|
{
|
||||||
fail( "User should exist in the database." );
|
fail( "User should exist in the database." );
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO cannot assign global repo manager role - it says role does not exist :|
|
//TODO cannot assign global repo manager role - it says role does not exist :|
|
||||||
|
|
||||||
//roleManager.assignRole( ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE, USER_ALPACA );
|
//roleManager.assignRole( ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE, USER_ALPACA );
|
||||||
|
|
||||||
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getConfig(), config, 2 );
|
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getConfig(), config, 2 );
|
||||||
|
|
||||||
configControl.expectAndReturn( config.getBasicUserName(), USER_ALPACA );
|
configControl.expectAndReturn( config.getBasicUserName(), USER_ALPACA );
|
||||||
|
|
||||||
configControl.expectAndReturn( config.getBasicPassword(), PASSWORD );
|
configControl.expectAndReturn( config.getBasicPassword(), PASSWORD );
|
||||||
|
|
||||||
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getMethodName(),
|
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getMethodName(),
|
||||||
"AdministrationService.getAllManagedRepositories" );
|
"AdministrationService.getAllManagedRepositories" );
|
||||||
|
|
||||||
xmlRpcRequestControl.replay();
|
xmlRpcRequestControl.replay();
|
||||||
configControl.replay();
|
configControl.replay();
|
||||||
|
|
||||||
@SuppressWarnings( "unused" ) boolean isAuthorized = authenticator.isAuthorized( xmlRpcRequest );
|
@SuppressWarnings( "unused" ) boolean isAuthorized = authenticator.isAuthorized( xmlRpcRequest );
|
||||||
// TODO: broken or bad test?
|
// TODO: broken or bad test?
|
||||||
// assertTrue( isAuthorized );
|
// assertTrue( isAuthorized );
|
||||||
|
|
||||||
xmlRpcRequestControl.verify();
|
xmlRpcRequestControl.verify();
|
||||||
configControl.verify();
|
configControl.verify();
|
||||||
|
|
||||||
userManager.deleteUser( USER_ALPACA );
|
userManager.deleteUser( USER_ALPACA );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAuthorizedUserDoesNotExist()
|
public void testIsAuthorizedUserDoesNotExist()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
UserManager userManager = securitySystem.getUserManager();
|
UserManager userManager = securitySystem.getUserManager();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
userManager.findUser( USER_ALPACA );
|
userManager.findUser( USER_ALPACA );
|
||||||
fail( "User should not exist in the database." );
|
fail( "User should not exist in the database." );
|
||||||
}
|
}
|
||||||
catch ( UserNotFoundException e )
|
catch ( UserNotFoundException e )
|
||||||
{
|
{
|
||||||
assertEquals( "Unable to find user 'alpaca'", e.getMessage() );
|
assertEquals( "Unable to find user 'alpaca'", e.getMessage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getConfig(), config, 2 );
|
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getConfig(), config, 2 );
|
||||||
|
|
||||||
configControl.expectAndReturn( config.getBasicUserName(), USER_ALPACA );
|
configControl.expectAndReturn( config.getBasicUserName(), USER_ALPACA );
|
||||||
|
|
||||||
configControl.expectAndReturn( config.getBasicPassword(), PASSWORD );
|
configControl.expectAndReturn( config.getBasicPassword(), PASSWORD );
|
||||||
|
|
||||||
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getMethodName(),
|
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getMethodName(),
|
||||||
"AdministrationService.getAllManagedRepositories" );
|
"AdministrationService.getAllManagedRepositories" );
|
||||||
|
|
||||||
xmlRpcRequestControl.replay();
|
xmlRpcRequestControl.replay();
|
||||||
configControl.replay();
|
configControl.replay();
|
||||||
|
|
||||||
boolean isAuthorized = authenticator.isAuthorized( xmlRpcRequest );
|
boolean isAuthorized = authenticator.isAuthorized( xmlRpcRequest );
|
||||||
|
|
||||||
xmlRpcRequestControl.verify();
|
xmlRpcRequestControl.verify();
|
||||||
configControl.verify();
|
configControl.verify();
|
||||||
|
|
||||||
assertFalse( isAuthorized );
|
assertFalse( isAuthorized );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
package org.apache.archiva.web.xmlrpc.services;
|
package org.apache.archiva.web.xmlrpc.services;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.archiva.web.xmlrpc.api.PingService;
|
import org.apache.archiva.web.xmlrpc.api.PingService;
|
||||||
|
|
||||||
public class PingServiceImpl implements PingService
|
public class PingServiceImpl implements PingService
|
||||||
{
|
{
|
||||||
public String ping()
|
public String ping()
|
||||||
{
|
{
|
||||||
return "pong";
|
return "pong";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue