2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
2012-08-27 08:04:44 +02:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
2012-08-27 08:04:44 +02:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2012-08-27 08:04:44 +02:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
2012-08-27 08:04:44 +02:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2012-08-27 08:04:44 +02:00
|
|
|
*/
|
2020-03-23 15:35:58 +01:00
|
|
|
|
2019-06-25 09:49:52 +02:00
|
|
|
package sonia.scm.lifecycle.modules;
|
2012-08-27 08:04:44 +02:00
|
|
|
|
|
|
|
|
//~--- non-JDK imports --------------------------------------------------------
|
|
|
|
|
|
2013-02-17 13:59:00 +01:00
|
|
|
import com.google.inject.name.Names;
|
|
|
|
|
|
2014-12-14 12:26:03 +01:00
|
|
|
import org.apache.shiro.authc.credential.DefaultPasswordService;
|
|
|
|
|
import org.apache.shiro.authc.credential.PasswordService;
|
|
|
|
|
import org.apache.shiro.crypto.hash.DefaultHashService;
|
2012-08-27 08:04:44 +02:00
|
|
|
import org.apache.shiro.guice.web.ShiroWebModule;
|
2014-12-19 17:52:44 +01:00
|
|
|
import org.apache.shiro.realm.Realm;
|
2012-08-27 08:04:44 +02:00
|
|
|
|
2014-12-19 17:52:44 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import sonia.scm.plugin.ExtensionProcessor;
|
2012-08-27 08:04:44 +02:00
|
|
|
|
|
|
|
|
//~--- JDK imports ------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletContext;
|
2015-03-21 17:03:23 +01:00
|
|
|
import org.apache.shiro.mgt.RememberMeManager;
|
|
|
|
|
import sonia.scm.security.DisabledRememberMeManager;
|
2012-08-27 08:04:44 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Sebastian Sdorra
|
|
|
|
|
*/
|
|
|
|
|
public class ScmSecurityModule extends ShiroWebModule
|
|
|
|
|
{
|
|
|
|
|
|
2014-12-14 12:26:03 +01:00
|
|
|
/** Field description */
|
|
|
|
|
private static final int ITERATIONS = 8192;
|
|
|
|
|
|
2014-12-19 17:52:44 +01:00
|
|
|
/**
|
|
|
|
|
* the logger for ScmSecurityModule
|
|
|
|
|
*/
|
|
|
|
|
private static final Logger logger =
|
|
|
|
|
LoggerFactory.getLogger(ScmSecurityModule.class);
|
|
|
|
|
|
2014-12-14 12:26:03 +01:00
|
|
|
//~--- constructors ---------------------------------------------------------
|
|
|
|
|
|
2012-08-27 08:04:44 +02:00
|
|
|
/**
|
|
|
|
|
* Constructs ...
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param servletContext
|
2014-12-19 17:52:44 +01:00
|
|
|
* @param extensionProcessor
|
2012-08-27 08:04:44 +02:00
|
|
|
*/
|
2019-06-24 16:59:28 +02:00
|
|
|
public ScmSecurityModule(ServletContext servletContext, ExtensionProcessor extensionProcessor)
|
2012-08-27 08:04:44 +02:00
|
|
|
{
|
|
|
|
|
super(servletContext);
|
2014-12-19 17:52:44 +01:00
|
|
|
this.extensionProcessor = extensionProcessor;
|
2012-08-27 08:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//~--- methods --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2014-01-11 15:17:44 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2012-08-27 08:04:44 +02:00
|
|
|
protected void configureShiroWeb()
|
|
|
|
|
{
|
2014-12-14 12:26:03 +01:00
|
|
|
bind(PasswordService.class).toInstance(createPasswordService());
|
|
|
|
|
|
|
|
|
|
// expose password service to global injector
|
|
|
|
|
expose(PasswordService.class);
|
2015-03-21 17:03:23 +01:00
|
|
|
|
|
|
|
|
// disable remember me cookie generation
|
|
|
|
|
bind(RememberMeManager.class).to(DisabledRememberMeManager.class);
|
2013-02-17 13:59:00 +01:00
|
|
|
|
|
|
|
|
// bind realm
|
2014-12-21 00:42:21 +01:00
|
|
|
for (Class<? extends Realm> realm : extensionProcessor.byExtensionPoint(Realm.class))
|
2014-12-19 17:52:44 +01:00
|
|
|
{
|
|
|
|
|
logger.info("bind security realm {}", realm);
|
|
|
|
|
bindRealm().to(realm);
|
|
|
|
|
}
|
2013-02-17 13:59:00 +01:00
|
|
|
|
|
|
|
|
// bind constant
|
|
|
|
|
bindConstant().annotatedWith(Names.named("shiro.loginUrl")).to(
|
|
|
|
|
"/index.html");
|
|
|
|
|
|
|
|
|
|
// disable access to mustache resources
|
2016-12-11 21:30:33 +01:00
|
|
|
addFilterChain("/**.mustache", filterConfig(ROLES, "nobody"));
|
2015-03-15 11:40:29 +01:00
|
|
|
|
|
|
|
|
// disable session
|
2015-03-21 16:06:17 +01:00
|
|
|
addFilterChain("/**", NO_SESSION_CREATION);
|
2012-08-27 08:04:44 +02:00
|
|
|
}
|
2014-12-14 12:26:03 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a {@link PasswordService} with a smaller size of iteration, because
|
|
|
|
|
* large iterations will slow down subversion.
|
|
|
|
|
*
|
|
|
|
|
* @return instance of {@link PasswordService}
|
|
|
|
|
*/
|
|
|
|
|
private PasswordService createPasswordService()
|
|
|
|
|
{
|
|
|
|
|
DefaultPasswordService passwordService = new DefaultPasswordService();
|
|
|
|
|
DefaultHashService hashService = new DefaultHashService();
|
|
|
|
|
|
|
|
|
|
hashService.setHashIterations(ITERATIONS);
|
|
|
|
|
passwordService.setHashService(hashService);
|
|
|
|
|
|
|
|
|
|
return passwordService;
|
|
|
|
|
}
|
2014-12-19 17:52:44 +01:00
|
|
|
|
|
|
|
|
//~--- fields ---------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/** Field description */
|
|
|
|
|
private final ExtensionProcessor extensionProcessor;
|
2012-08-27 08:04:44 +02:00
|
|
|
}
|