This commit is contained in:
Thorsten Ludewig
2011-02-02 09:41:03 +01:00
73 changed files with 1793 additions and 545 deletions

View File

@@ -6,13 +6,13 @@
<parent>
<groupId>sonia.scm</groupId>
<artifactId>scm</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-plugins</artifactId>
<packaging>pom</packaging>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<name>scm-plugins</name>
<modules>
@@ -31,7 +31,7 @@
<dependency>
<groupId>sonia.scm</groupId>
<artifactId>scm-core</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@@ -7,12 +7,12 @@
<parent>
<artifactId>scm-plugins</artifactId>
<groupId>sonia.scm.plugins</groupId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-activedirectory-auth-plugin</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<name>scm-activedirectory-auth-plugin</name>
<url>https://bitbucket.org/sdorra/scm-manager</url>
<description>
@@ -32,7 +32,7 @@
<dependency>
<groupId>sonia.scm</groupId>
<artifactId>scm-core</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</dependency>
<dependency>

View File

@@ -6,13 +6,13 @@
<parent>
<artifactId>scm-plugins</artifactId>
<groupId>sonia.scm.plugins</groupId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-auth-ldap-plugin</artifactId>
<packaging>jar</packaging>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>plugin description</description>
@@ -30,7 +30,7 @@
<dependency>
<groupId>sonia.scm</groupId>
<artifactId>scm-test</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View File

@@ -49,6 +49,7 @@ import sonia.scm.user.User;
import sonia.scm.util.AssertUtil;
import sonia.scm.web.security.AuthenticationHandler;
import sonia.scm.web.security.AuthenticationResult;
import sonia.scm.web.security.AuthenticationState;
//~--- JDK imports ------------------------------------------------------------
@@ -57,8 +58,10 @@ import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
@@ -136,7 +139,8 @@ public class LDAPAuthenticationHandler implements AuthenticationHandler
searchControls.setCountLimit(1);
searchControls.setReturningAttributes(new String[] {
config.getAttributeNameId(),
config.getAttributeNameFullname(), config.getAttributeNameMail() });
config.getAttributeNameFullname(), config.getAttributeNameMail(),
config.getAttributeNameGroup() });
String filter = MessageFormat.format(config.getSearchFilter(), username);
String baseDn = config.getUnitPeople() + "," + config.getBaseDn();
@@ -177,7 +181,7 @@ public class LDAPAuthenticationHandler implements AuthenticationHandler
user.setType(TYPE);
//
ArrayList<String> groups = new ArrayList<String>();
HashSet<String> groups = new HashSet<String>();
searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
@@ -190,7 +194,6 @@ public class LDAPAuthenticationHandler implements AuthenticationHandler
+ userDn + "))", searchControls);
//
while (searchResult2.hasMore())
{
SearchResult sr2 = searchResult2.next();
@@ -209,9 +212,9 @@ public class LDAPAuthenticationHandler implements AuthenticationHandler
}
//
result = new AuthenticationResult(user, groups);
getGroups(userAttributes, groups);
user.setAdmin(isAdmin(user.getName(), groups));
//
result = new AuthenticationResult(user, groups);
}
catch (NamingException ex)
@@ -370,6 +373,39 @@ public class LDAPAuthenticationHandler implements AuthenticationHandler
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param userAttributes
* @param groups
*
* @throws NamingException
*/
private void getGroups(Attributes userAttributes, HashSet<String> groups)
throws NamingException
{
Attribute groupsAttribute =
userAttributes.get(config.getAttributeNameGroup());
if (groupsAttribute != null)
{
NamingEnumeration<?> userGroups =
(NamingEnumeration<?>) groupsAttribute.getAll();
while (userGroups.hasMore())
{
groups.add((String) userGroups.next());
}
userGroups.close();
}
else
{
logger.info("user has no groups assigned");
}
}
/**
* Method description
*
@@ -379,7 +415,7 @@ public class LDAPAuthenticationHandler implements AuthenticationHandler
*
* @return
*/
private boolean isAdmin(String userName, List<String> groups)
private boolean isAdmin(String userName, Set<String> groups)
{
boolean admin = false;

View File

@@ -118,6 +118,10 @@ public class LDAPConfig
return attributeNameMail;
}
public String getAttributeNameGroup() {
return attributeNameGroup;
}
/**
* Method description
*
@@ -306,6 +310,9 @@ public class LDAPConfig
/** Field description */
@XmlElement(name = "attribute-name-mail")
private String attributeNameMail = "mail";
@XmlElement(name = "attribute-name-group")
private String attributeNameGroup = "group";
/** Field description */
@XmlElement(name = "base-dn")

View File

@@ -69,6 +69,12 @@ registerGeneralConfigPanel({
name : 'attribute-name-mail',
allowBlank : true
}
,{
xtype : 'textfield',
fieldLabel : 'Group Attribute Name',
name : 'attribute-name-group',
allowBlank : true
}
,{
xtype : 'textfield',
fieldLabel : 'Base DN',

View File

@@ -7,12 +7,12 @@
<parent>
<artifactId>scm-plugins</artifactId>
<groupId>sonia.scm.plugins</groupId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-bzr-plugin</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<name>scm-bzr-plugin</name>
<url>https://bitbucket.org/sdorra/scm-manager</url>
<description>Plugin for the version control system Bazaar</description>

View File

@@ -36,15 +36,16 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.Type;
import sonia.scm.io.ExtendedCommand;
import sonia.scm.io.FileSystem;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.store.StoreFactory;
import sonia.scm.util.SecurityUtil;
import sonia.scm.web.security.WebSecurityContext;
//~--- JDK imports ------------------------------------------------------------
@@ -60,6 +61,9 @@ public class BzrRepositoryHandler
extends AbstractSimpleRepositoryHandler<BzrConfig>
{
/** Field description */
public static final String PUBLIC_RESOURCEPATH_BASE = "/public/bzr/";
/** Field description */
public static final String TYPE_DISPLAYNAME = "Bazaar";
@@ -69,10 +73,6 @@ public class BzrRepositoryHandler
/** Field description */
public static final Type TYPE = new Type(TYPE_NAME, TYPE_DISPLAYNAME);
/** the logger for BzrRepositoryHandler */
private static final Logger logger =
LoggerFactory.getLogger(BzrRepositoryHandler.class);
//~--- constructors ---------------------------------------------------------
/**
@@ -80,11 +80,43 @@ public class BzrRepositoryHandler
*
*
* @param storeFactory
* @param fileSystem
* @param securityContextProvider
*/
@Inject
public BzrRepositoryHandler(StoreFactory storeFactory)
public BzrRepositoryHandler(
StoreFactory storeFactory, FileSystem fileSystem,
Provider<WebSecurityContext> securityContextProvider)
{
super(storeFactory);
super(storeFactory, fileSystem);
this.securityContextProvider = securityContextProvider;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param repository
*
* @return
*/
@Override
public String createResourcePath(Repository repository)
{
String resourcePath = null;
if (SecurityUtil.isAnonymous(securityContextProvider))
{
resourcePath = PUBLIC_RESOURCEPATH_BASE.concat(repository.getName());
}
else
{
resourcePath = super.createResourcePath(repository);
}
return resourcePath;
}
//~--- get methods ----------------------------------------------------------
@@ -145,4 +177,9 @@ public class BzrRepositoryHandler
{
return BzrConfig.class;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Provider<WebSecurityContext> securityContextProvider;
}

View File

@@ -0,0 +1,131 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Singleton;
import sonia.scm.repository.BzrRepositoryHandler;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.util.HttpUtil;
import sonia.scm.web.filter.HttpFilter;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class BzrPublicFilter extends HttpFilter
{
/** Field description */
private static final Pattern REGEX_REPOSITORYNAME =
Pattern.compile("/public/bzr/([^/]+)");
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param repositoryManager
*/
@Inject
public BzrPublicFilter(RepositoryManager repositoryManager)
{
this.repositoryManager = repositoryManager;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param request
* @param response
* @param chain
*
* @throws IOException
* @throws ServletException
*/
@Override
protected void doFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain chain)
throws IOException, ServletException
{
String requestURI = HttpUtil.getStrippedURI(request);
Matcher m = REGEX_REPOSITORYNAME.matcher(requestURI);
if (m.find())
{
String name = m.group(1);
Repository repository =
repositoryManager.get(BzrRepositoryHandler.TYPE_NAME, name);
if ((repository != null) && repository.isPublicReadable())
{
chain.doFilter(request, response);
}
else
{
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
}
else
{
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private RepositoryManager repositoryManager;
}

View File

@@ -51,6 +51,9 @@ public class BzrServletModule extends ServletModule
/** Field description */
public static final String MAPPING_BZR = "/bzr/*";
/** Field description */
public static final String MAPPING_PUBLICBZR = "/public/bzr/*";
//~--- methods --------------------------------------------------------------
/**
@@ -60,8 +63,10 @@ public class BzrServletModule extends ServletModule
@Override
protected void configureServlets()
{
filter(MAPPING_BZR).through(BasicAuthenticationFilter.class);
filter(MAPPING_BZR,
MAPPING_PUBLICBZR).through(BasicAuthenticationFilter.class);
filter(MAPPING_BZR).through(BzrPermissionFilter.class);
serve(MAPPING_BZR).with(BzrCGIServlet.class);
filter(MAPPING_PUBLICBZR).through(BzrPublicFilter.class);
serve(MAPPING_BZR, MAPPING_PUBLICBZR).with(BzrCGIServlet.class);
}
}

View File

@@ -7,12 +7,12 @@
<parent>
<artifactId>scm-plugins</artifactId>
<groupId>sonia.scm.plugins</groupId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-git-plugin</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<name>scm-git-plugin</name>
<url>https://bitbucket.org/sdorra/scm-manager</url>
<description>Plugin for the version control system Git</description>
@@ -50,7 +50,7 @@
<dependency>
<groupId>sonia.scm</groupId>
<artifactId>scm-test</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View File

@@ -41,6 +41,7 @@ import com.google.inject.Singleton;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import sonia.scm.Type;
import sonia.scm.io.FileSystem;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.store.StoreFactory;
@@ -75,11 +76,12 @@ public class GitRepositoryHandler
*
*
* @param storeFactory
* @param fileSystem
*/
@Inject
public GitRepositoryHandler(StoreFactory storeFactory)
public GitRepositoryHandler(StoreFactory storeFactory, FileSystem fileSystem)
{
super(storeFactory);
super(storeFactory, fileSystem);
}
//~--- get methods ----------------------------------------------------------

View File

@@ -35,6 +35,7 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.io.DefaultFileSystem;
import sonia.scm.store.StoreFactory;
import static org.junit.Assert.*;
@@ -88,7 +89,8 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
protected RepositoryHandler createRepositoryHandler(StoreFactory factory,
File directory)
{
GitRepositoryHandler repositoryHandler = new GitRepositoryHandler(factory);
GitRepositoryHandler repositoryHandler = new GitRepositoryHandler(factory,
new DefaultFileSystem());
repositoryHandler.init(contextProvider);

View File

@@ -7,12 +7,12 @@
<parent>
<artifactId>scm-plugins</artifactId>
<groupId>sonia.scm.plugins</groupId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-graph-plugin</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<name>scm-graph-plugin</name>
<description>Creates an Google Guice injection graph</description>
<url>https://bitbucket.org/sdorra/scm-manager</url>

View File

@@ -7,12 +7,12 @@
<parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-plugins</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-hg-plugin</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<name>scm-hg-plugin</name>
<url>https://bitbucket.org/sdorra/scm-manager</url>
<description>Plugin for the version control system Mercurial</description>
@@ -37,7 +37,7 @@
<dependency>
<groupId>sonia.scm</groupId>
<artifactId>scm-test</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View File

@@ -57,6 +57,7 @@ import sonia.scm.web.HgWebConfigWriter;
import java.io.File;
import java.io.IOException;
import sonia.scm.io.FileSystem;
/**
*
@@ -90,9 +91,9 @@ public class HgRepositoryHandler
* @param storeFactory
*/
@Inject
public HgRepositoryHandler(StoreFactory storeFactory)
public HgRepositoryHandler(StoreFactory storeFactory, FileSystem fileSystem)
{
super(storeFactory);
super(storeFactory, fileSystem);
}
//~--- methods --------------------------------------------------------------

View File

@@ -35,6 +35,7 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.io.DefaultFileSystem;
import sonia.scm.store.StoreFactory;
import sonia.scm.util.Util;
@@ -86,7 +87,8 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
protected RepositoryHandler createRepositoryHandler(StoreFactory factory,
File directory)
{
HgRepositoryHandler handler = new HgRepositoryHandler(factory);
HgRepositoryHandler handler = new HgRepositoryHandler(factory,
new DefaultFileSystem());
handler.init(contextProvider);
handler.getConfig().setRepositoryDirectory(directory);

View File

@@ -7,12 +7,12 @@
<parent>
<artifactId>scm-plugins</artifactId>
<groupId>sonia.scm.plugins</groupId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-pam-plugin</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<name>scm-pam-plugin</name>
<url>https://bitbucket.org/sdorra/scm-manager</url>
<description>Using pam as an authentication handler.</description>

View File

@@ -7,12 +7,12 @@
<parent>
<artifactId>scm-plugins</artifactId>
<groupId>sonia.scm.plugins</groupId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
</parent>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-svn-plugin</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<name>scm-svn-plugin</name>
<url>https://bitbucket.org/sdorra/scm-manager</url>
<description>Plugin for the version control system Subversion</description>
@@ -47,7 +47,7 @@
<dependency>
<groupId>sonia.scm</groupId>
<artifactId>scm-test</artifactId>
<version>1.0-M7-SNAPSHOT</version>
<version>1.0-RC1-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View File

@@ -42,35 +42,4 @@ import javax.xml.bind.annotation.XmlRootElement;
* @author Sebastian Sdorra
*/
@XmlRootElement(name = "config")
public class SvnConfig extends SimpleRepositoryConfig
{
/**
* Method description
*
*
* @return
*/
public String getSvnAccessFile()
{
return svnAccessFile;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param svnAccessFile
*/
public void setSvnAccessFile(String svnAccessFile)
{
this.svnAccessFile = svnAccessFile;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String svnAccessFile;
}
public class SvnConfig extends SimpleRepositoryConfig {}

View File

@@ -42,6 +42,7 @@ import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import sonia.scm.Type;
import sonia.scm.io.FileSystem;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.store.StoreFactory;
@@ -76,11 +77,12 @@ public class SvnRepositoryHandler
*
*
* @param storeFactory
* @param fileSystem
*/
@Inject
public SvnRepositoryHandler(StoreFactory storeFactory)
public SvnRepositoryHandler(StoreFactory storeFactory, FileSystem fileSystem)
{
super(storeFactory);
super(storeFactory, fileSystem);
}
//~--- get methods ----------------------------------------------------------

View File

@@ -35,6 +35,7 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.io.DefaultFileSystem;
import sonia.scm.store.StoreFactory;
import static org.junit.Assert.*;
@@ -83,7 +84,8 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
protected RepositoryHandler createRepositoryHandler(StoreFactory factory,
File directory)
{
SvnRepositoryHandler handler = new SvnRepositoryHandler(factory);
SvnRepositoryHandler handler = new SvnRepositoryHandler(factory,
new DefaultFileSystem());
handler.init(contextProvider);