Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 22A88200B50 for ; Fri, 24 Jun 2016 01:12:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 218D6160A59; Thu, 23 Jun 2016 23:12:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 73169160A68 for ; Fri, 24 Jun 2016 01:12:17 +0200 (CEST) Received: (qmail 25816 invoked by uid 500); 23 Jun 2016 23:12:16 -0000 Mailing-List: contact dev-help@shiro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@shiro.apache.org Delivered-To: mailing list dev@shiro.apache.org Received: (qmail 25709 invoked by uid 99); 23 Jun 2016 23:12:16 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jun 2016 23:12:16 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 6E7FB2C14F8 for ; Thu, 23 Jun 2016 23:12:16 +0000 (UTC) Date: Thu, 23 Jun 2016 23:12:16 +0000 (UTC) From: "Brian Demers (JIRA)" To: dev@shiro.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (SHIRO-435) SecurityManager is not a singleton in ShiroWebModule MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 23 Jun 2016 23:12:18 -0000 [ https://issues.apache.org/jira/browse/SHIRO-435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Brian Demers updated SHIRO-435: ------------------------------- Labels: patch patch-with-test (was: ) > SecurityManager is not a singleton in ShiroWebModule > ---------------------------------------------------- > > Key: SHIRO-435 > URL: https://issues.apache.org/jira/browse/SHIRO-435 > Project: Shiro > Issue Type: Bug > Components: Integration: Guice > Affects Versions: 1.2.1 > Reporter: Laszlo Ferenczi > Assignee: Jared Bunting > Labels: patch, patch-with-test > Attachments: SHIRO-435.path > > > While integrating Shiro to our guice based webapp I've noticed > something strange. The module setup is pretty much the same as the > example in the Guice page of Shiro's documentation. Only extra code is > that I'm exposing the WebSecurityManager like this: > public class AuthModule extends ShiroWebModule { > public AuthModule(ServletContext servletContext) { > super(servletContext); > } > @Override > @SuppressWarnings("unchecked") > protected void configureShiroWeb() { > IniRealm iniRealm = new IniRealm(Ini.fromResourcePath("classpath:shiro.ini")); > bindRealm().toInstance(iniRealm); > expose(WebSecurityManager.class); > } > } > A guice injected SecurityManager instance is not the same as the > cached static SecurityManager in SecurityUtils. > @Path("/Ping") > @Singleton > public class PingResource { > @Inject > SecurityManager sec; > @Inject > WebSecurityManager websec; > @GET > public void ping() { > SecurityManager man = SecurityUtils.getSecurityManager(); > assert(man == websec); > assert(man == sec); > } > } > First assert passes, second fails. Debugger confirms that there are 2 > instances in memory, both of them are of type > DefaultWebSecurityManager but only the WebSecurityManager instance > works. Any meaningful operation on "sec" will fail (like an > authorization check). > I think the problem might be the double binding of SecurityManager(s). > One is bound in ShiroModule another is in ShiroWebModule: > in ShiroModule: > public void configure() { > // setup security manager > bindSecurityManager(bind(SecurityManager.class)); > in ShiroWebModule: > protected final void configureShiro() { > .... > bindWebSecurityManager(bind(WebSecurityManager.class)); > Both of these methods are running at init time, hence the duplicated singletons. > It might be better if ShiroWebModule would overrinde the standard > configure() method to avoid this double-binding. -- This message was sent by Atlassian JIRA (v6.3.4#6332)