mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
Security System: Query permission.xmls from uber classloader.
Allows for finding permission.xmls from plugins. Adds an examplary permission.xml for git plugin.
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
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.dd7s
|
||||||
|
|
||||||
|
http://bitbucket.org/sdorra/scm-manager
|
||||||
|
|
||||||
|
|
||||||
|
-->
|
||||||
|
<permissions>
|
||||||
|
|
||||||
|
<permission>
|
||||||
|
<display-name>Git config (read)</display-name>
|
||||||
|
<description>Read access to git config</description>
|
||||||
|
<value>configuration:read:git</value>
|
||||||
|
</permission>
|
||||||
|
|
||||||
|
<permission>
|
||||||
|
<display-name>Git config (write)</display-name>
|
||||||
|
<description>Write access to git config</description>
|
||||||
|
<value>configuration:write:git</value>
|
||||||
|
</permission>
|
||||||
|
|
||||||
|
</permissions>
|
||||||
@@ -36,7 +36,6 @@ package sonia.scm.security;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.github.legman.Subscribe;
|
import com.github.legman.Subscribe;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
@@ -44,30 +43,16 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import com.google.common.collect.ImmutableList.Builder;
|
import com.google.common.collect.ImmutableList.Builder;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.HandlerEventType;
|
import sonia.scm.HandlerEventType;
|
||||||
import sonia.scm.event.ScmEventBus;
|
import sonia.scm.event.ScmEventBus;
|
||||||
import sonia.scm.group.GroupEvent;
|
import sonia.scm.group.GroupEvent;
|
||||||
|
import sonia.scm.plugin.PluginLoader;
|
||||||
import sonia.scm.store.ConfigurationEntryStore;
|
import sonia.scm.store.ConfigurationEntryStore;
|
||||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||||
import sonia.scm.user.UserEvent;
|
import sonia.scm.user.UserEvent;
|
||||||
import sonia.scm.util.ClassLoaders;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
@@ -75,6 +60,14 @@ import javax.xml.bind.annotation.XmlAccessType;
|
|||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO add events
|
* TODO add events
|
||||||
@@ -99,6 +92,8 @@ public class DefaultSecuritySystem implements SecuritySystem
|
|||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(DefaultSecuritySystem.class);
|
LoggerFactory.getLogger(DefaultSecuritySystem.class);
|
||||||
|
|
||||||
|
private PluginLoader pluginLoader;
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,12 +104,13 @@ public class DefaultSecuritySystem implements SecuritySystem
|
|||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory)
|
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory, PluginLoader pluginLoader)
|
||||||
{
|
{
|
||||||
store = storeFactory
|
store = storeFactory
|
||||||
.withType(AssignedPermission.class)
|
.withType(AssignedPermission.class)
|
||||||
.withName(NAME)
|
.withName(NAME)
|
||||||
.build();
|
.build();
|
||||||
|
this.pluginLoader = pluginLoader;
|
||||||
readAvailablePermissions();
|
readAvailablePermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,9 +405,9 @@ public class DefaultSecuritySystem implements SecuritySystem
|
|||||||
JAXBContext context =
|
JAXBContext context =
|
||||||
JAXBContext.newInstance(PermissionDescriptors.class);
|
JAXBContext.newInstance(PermissionDescriptors.class);
|
||||||
|
|
||||||
|
// Querying permissions from uberClassLoader returns also the permissions from plugin
|
||||||
Enumeration<URL> descirptorEnum =
|
Enumeration<URL> descirptorEnum =
|
||||||
ClassLoaders.getContextClassLoader(
|
pluginLoader.getUberClassLoader().getResources(PERMISSION_DESCRIPTOR);
|
||||||
DefaultSecuritySystem.class).getResources(PERMISSION_DESCRIPTOR);
|
|
||||||
|
|
||||||
while (descirptorEnum.hasMoreElements())
|
while (descirptorEnum.hasMoreElements())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,26 +35,28 @@ package sonia.scm.security;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
import org.apache.shiro.authz.UnauthorizedException;
|
import org.apache.shiro.authz.UnauthorizedException;
|
||||||
import org.apache.shiro.mgt.DefaultSecurityManager;
|
import org.apache.shiro.mgt.DefaultSecurityManager;
|
||||||
import org.apache.shiro.realm.SimpleAccountRealm;
|
import org.apache.shiro.realm.SimpleAccountRealm;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import sonia.scm.AbstractTestBase;
|
import sonia.scm.AbstractTestBase;
|
||||||
|
import sonia.scm.plugin.PluginLoader;
|
||||||
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
||||||
|
import sonia.scm.util.ClassLoaders;
|
||||||
import sonia.scm.util.MockUtil;
|
import sonia.scm.util.MockUtil;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -62,6 +64,12 @@ import java.util.List;
|
|||||||
public class DefaultSecuritySystemTest extends AbstractTestBase
|
public class DefaultSecuritySystemTest extends AbstractTestBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private JAXBConfigurationEntryStoreFactory jaxbConfigurationEntryStoreFactory;
|
||||||
|
private PluginLoader pluginLoader;
|
||||||
|
@InjectMocks
|
||||||
|
private DefaultSecuritySystem securitySystem;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -69,12 +77,12 @@ public class DefaultSecuritySystemTest extends AbstractTestBase
|
|||||||
@Before
|
@Before
|
||||||
public void createSecuritySystem()
|
public void createSecuritySystem()
|
||||||
{
|
{
|
||||||
JAXBConfigurationEntryStoreFactory factory =
|
jaxbConfigurationEntryStoreFactory =
|
||||||
new JAXBConfigurationEntryStoreFactory(contextProvider , repositoryLocationResolver, new UUIDKeyGenerator() );
|
spy(new JAXBConfigurationEntryStoreFactory(contextProvider , repositoryLocationResolver, new UUIDKeyGenerator() ) {});
|
||||||
|
pluginLoader = mock(PluginLoader.class);
|
||||||
|
when(pluginLoader.getUberClassLoader()).thenReturn(ClassLoaders.getContextClassLoader(DefaultSecuritySystem.class));
|
||||||
|
|
||||||
securitySystem = new DefaultSecuritySystem(factory);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
// ScmEventBus.getInstance().register(listener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -325,9 +333,4 @@ public class DefaultSecuritySystemTest extends AbstractTestBase
|
|||||||
|
|
||||||
setSubject(MockUtil.createUserSubject(sm));
|
setSubject(MockUtil.createUserSubject(sm));
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private DefaultSecuritySystem securitySystem;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user