Search in sources :

Example 1 with ConfigurationException

use of org.apache.shiro.config.ConfigurationException 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)

Aggregations

ConfigurationException (org.apache.shiro.config.ConfigurationException)1 IniSecurityManagerFactory (org.apache.shiro.config.IniSecurityManagerFactory)1 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)1 SecurityManager (org.apache.shiro.mgt.SecurityManager)1 Realm (org.apache.shiro.realm.Realm)1 IniRealm (org.apache.shiro.realm.text.IniRealm)1