Search in sources :

Example 16 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project killbill by killbill.

the class UtilTestSuiteNoDB method configureShiro.

protected void configureShiro() {
    final Ini config = new Ini();
    config.addSection("users");
    config.getSection("users").put("pierre", "password, creditor");
    config.getSection("users").put("stephane", "password, refunder");
    config.addSection("roles");
    config.getSection("roles").put("creditor", Permission.INVOICE_CAN_CREDIT.toString() + "," + Permission.INVOICE_CAN_ITEM_ADJUST.toString());
    config.getSection("roles").put("refunder", Permission.PAYMENT_CAN_REFUND.toString());
    // Reset the security manager
    ThreadContext.unbindSecurityManager();
    final Factory<SecurityManager> factory = new IniSecurityManagerFactory(config);
    final SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) SecurityManager(org.apache.shiro.mgt.SecurityManager) Ini(org.apache.shiro.config.Ini)

Example 17 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project SSM by Intel-bigdata.

the class SecurityUtils method initSecurityManager.

public static void initSecurityManager(String shiroPath) {
    IniSecurityManagerFactory factory = new IniSecurityManagerFactory("file:" + shiroPath);
    SecurityManager securityManager = factory.getInstance();
    org.apache.shiro.SecurityUtils.setSecurityManager(securityManager);
    isEnabled = true;
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) SecurityManager(org.apache.shiro.mgt.SecurityManager) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager)

Example 18 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project mica2 by obiba.

the class AbstractShiroTest method tearDownShiro.

@AfterClass
public static void tearDownShiro() {
    doClearSubject();
    try {
        SecurityManager securityManager = getSecurityManager();
        LifecycleUtils.destroy(securityManager);
    } catch (UnavailableSecurityManagerException e) {
    // we don't care about this when cleaning up the test environment
    // (for example, maybe the subclass is a unit test and it didn't
    // need a SecurityManager instance because it was using only
    // mock Subject instances)
    }
    setSecurityManager(null);
}
Also used : SecurityManager(org.apache.shiro.mgt.SecurityManager) UnavailableSecurityManagerException(org.apache.shiro.UnavailableSecurityManagerException) AfterClass(org.junit.AfterClass)

Example 19 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project killbill by killbill.

the class IniRealmProvider method get.

@Override
public IniRealm get() {
    try {
        final Factory<SecurityManager> factory = new IniSecurityManagerFactory(securityConfig.getShiroResourcePath());
        // TODO Pierre hack - lame cast here, but we need to have Shiro go through its reflection magic
        // to parse the [main] section of the ini file. Without duplicating code, this seems to be possible only
        // by going through IniSecurityManagerFactory.
        final DefaultSecurityManager securityManager = (DefaultSecurityManager) factory.getInstance();
        final Collection<Realm> realms = securityManager.getRealms();
        IniRealm iniRealm = null;
        if (realms == null || realms.isEmpty()) {
            iniRealm = new IniRealm(securityConfig.getShiroResourcePath());
        } else {
            for (final Realm cur : realms) {
                if (cur instanceof IniRealm) {
                    iniRealm = (IniRealm) cur;
                    break;
                }
            }
        }
        if (iniRealm != null) {
            // See JavaDoc warning: https://shiro.apache.org/static/1.2.3/apidocs/org/apache/shiro/realm/AuthenticatingRealm.html
            iniRealm.setAuthenticationCachingEnabled(true);
            return iniRealm;
        } else {
            throw new ConfigurationException();
        }
    } catch (final ConfigurationException e) {
        log.warn("Unable to configure RBAC", e);
        return new IniRealm();
    }
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) SecurityManager(org.apache.shiro.mgt.SecurityManager) ConfigurationException(org.apache.shiro.config.ConfigurationException) IniRealm(org.apache.shiro.realm.text.IniRealm) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) IniRealm(org.apache.shiro.realm.text.IniRealm) Realm(org.apache.shiro.realm.Realm)

Example 20 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project zeppelin by apache.

the class SecurityUtils method initSecurityManager.

public static void initSecurityManager(String shiroPath) {
    IniSecurityManagerFactory factory = new IniSecurityManagerFactory("file:" + shiroPath);
    SecurityManager securityManager = factory.getInstance();
    org.apache.shiro.SecurityUtils.setSecurityManager(securityManager);
    isEnabled = true;
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) SecurityManager(org.apache.shiro.mgt.SecurityManager) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager)

Aggregations

SecurityManager (org.apache.shiro.mgt.SecurityManager)36 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)13 IniSecurityManagerFactory (org.apache.shiro.config.IniSecurityManagerFactory)11 Test (org.junit.Test)11 Injector (com.google.inject.Injector)8 Provides (com.google.inject.Provides)6 Subject (org.apache.shiro.subject.Subject)6 Session (org.apache.shiro.session.Session)5 WebSecurityManager (org.apache.shiro.web.mgt.WebSecurityManager)5 Realm (org.apache.shiro.realm.Realm)4 IniRealm (org.apache.shiro.realm.text.IniRealm)4 DefaultWebSecurityManager (org.apache.shiro.web.mgt.DefaultWebSecurityManager)4 UnavailableSecurityManagerException (org.apache.shiro.UnavailableSecurityManagerException)3 Ini (org.apache.shiro.config.Ini)3 DelegatingSubject (org.apache.shiro.subject.support.DelegatingSubject)3 AfterClass (org.junit.AfterClass)3 Callable (java.util.concurrent.Callable)2 ServletContext (javax.servlet.ServletContext)2 ConfigurationException (org.apache.shiro.config.ConfigurationException)2 ShiroModuleTest (org.apache.shiro.guice.ShiroModuleTest)2