mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
move admin user and group configuration from plugins to core
This commit is contained in:
@@ -37,14 +37,19 @@ package sonia.scm.config;
|
|||||||
|
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import sonia.scm.xml.XmlSetStringAdapter;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
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 javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -80,10 +85,34 @@ public class ScmConfiguration
|
|||||||
this.enableSSL = other.enableSSL;
|
this.enableSSL = other.enableSSL;
|
||||||
this.port = other.port;
|
this.port = other.port;
|
||||||
this.anonymousAccessEnabled = other.anonymousAccessEnabled;
|
this.anonymousAccessEnabled = other.anonymousAccessEnabled;
|
||||||
|
this.adminUsers = other.adminUsers;
|
||||||
|
this.adminGroups = other.adminGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<String> getAdminGroups()
|
||||||
|
{
|
||||||
|
return adminGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<String> getAdminUsers()
|
||||||
|
{
|
||||||
|
return adminUsers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -152,6 +181,28 @@ public class ScmConfiguration
|
|||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param adminGroups
|
||||||
|
*/
|
||||||
|
public void setAdminGroups(Set<String> adminGroups)
|
||||||
|
{
|
||||||
|
this.adminGroups = adminGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param adminUsers
|
||||||
|
*/
|
||||||
|
public void setAdminUsers(Set<String> adminUsers)
|
||||||
|
{
|
||||||
|
this.adminUsers = adminUsers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -220,6 +271,16 @@ public class ScmConfiguration
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "admin-groups")
|
||||||
|
@XmlJavaTypeAdapter(XmlSetStringAdapter.class)
|
||||||
|
private Set<String> adminGroups;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "admin-users")
|
||||||
|
@XmlJavaTypeAdapter(XmlSetStringAdapter.class)
|
||||||
|
private Set<String> adminUsers;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@XmlElement(name = "plugin-url")
|
@XmlElement(name = "plugin-url")
|
||||||
private String pluginUrl = DEFAULT_PLUGINURL;
|
private String pluginUrl = DEFAULT_PLUGINURL;
|
||||||
|
|||||||
@@ -84,6 +84,34 @@ public class Util
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param collection
|
||||||
|
* @param other
|
||||||
|
* @param <T>
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> boolean containsOne(Collection<T> collection,
|
||||||
|
Collection<T> other)
|
||||||
|
{
|
||||||
|
boolean result = false;
|
||||||
|
|
||||||
|
for (T item : collection)
|
||||||
|
{
|
||||||
|
if (other.contains(item))
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
107
scm-core/src/main/java/sonia/scm/xml/XmlSetStringAdapter.java
Normal file
107
scm-core/src/main/java/sonia/scm/xml/XmlSetStringAdapter.java
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
/**
|
||||||
|
* 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.xml;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class XmlSetStringAdapter extends XmlAdapter<String, Set<String>>
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String marshal(Set<String> value) throws Exception
|
||||||
|
{
|
||||||
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
Iterator<String> it = value.iterator();
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
buffer.append(it.next());
|
||||||
|
|
||||||
|
if (it.hasNext())
|
||||||
|
{
|
||||||
|
buffer.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param rawString
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Set<String> unmarshal(String rawString) throws Exception
|
||||||
|
{
|
||||||
|
Set<String> tokens = new HashSet<String>();
|
||||||
|
|
||||||
|
for (String token : rawString.split(","))
|
||||||
|
{
|
||||||
|
token = token.trim();
|
||||||
|
|
||||||
|
if (token.length() > 0)
|
||||||
|
{
|
||||||
|
tokens.add(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -145,6 +145,11 @@ public class BasicSecurityContext implements WebSecurityContext
|
|||||||
|
|
||||||
loadGroups();
|
loadGroups();
|
||||||
|
|
||||||
|
if (!user.isAdmin())
|
||||||
|
{
|
||||||
|
user.setAdmin(isAdmin());
|
||||||
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logGroups();
|
logGroups();
|
||||||
@@ -283,6 +288,26 @@ public class BasicSecurityContext implements WebSecurityContext
|
|||||||
logger.debug(msg.toString());
|
logger.debug(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isAdmin()
|
||||||
|
{
|
||||||
|
boolean result = configuration.getAdminUsers().contains(user.getName());
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
result = Util.containsOne(configuration.getAdminGroups(), groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
|||||||
@@ -124,6 +124,16 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
|
|||||||
fieldLabel: 'SSL Port',
|
fieldLabel: 'SSL Port',
|
||||||
name: 'sslPort',
|
name: 'sslPort',
|
||||||
allowBlank: false
|
allowBlank: false
|
||||||
|
},{
|
||||||
|
xtype : 'textfield',
|
||||||
|
fieldLabel : 'Admin Groups',
|
||||||
|
name : 'admin-groups',
|
||||||
|
allowBlank : true
|
||||||
|
},{
|
||||||
|
xtype : 'textfield',
|
||||||
|
fieldLabel : 'Admin Users',
|
||||||
|
name : 'admin-users',
|
||||||
|
allowBlank : true
|
||||||
}],
|
}],
|
||||||
|
|
||||||
onSubmit: function(values){
|
onSubmit: function(values){
|
||||||
|
|||||||
Reference in New Issue
Block a user