Search in sources :

Example 1 with IniSecurityManagerFactory

use of org.apache.shiro.config.IniSecurityManagerFactory in project cas by apereo.

the class ShiroAuthenticationHandler method loadShiroConfiguration.

/**
     * Sets shiro configuration to the path of the resource
     * that points to the {@code shiro.ini} file.
     *
     * @param resource the resource
     */
public void loadShiroConfiguration(final Resource resource) {
    try {
        final Resource shiroResource = ResourceUtils.prepareClasspathResourceIfNeeded(resource);
        if (shiroResource != null && shiroResource.exists()) {
            final String location = shiroResource.getURI().toString();
            LOGGER.debug("Loading Shiro configuration from [{}]", location);
            final Factory<SecurityManager> factory = new IniSecurityManagerFactory(location);
            final SecurityManager securityManager = factory.getInstance();
            SecurityUtils.setSecurityManager(securityManager);
        } else {
            LOGGER.debug("Shiro configuration is not defined");
        }
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) SecurityManager(org.apache.shiro.mgt.SecurityManager) Resource(org.springframework.core.io.Resource) CredentialExpiredException(javax.security.auth.login.CredentialExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) IncorrectCredentialsException(org.apache.shiro.authc.IncorrectCredentialsException) DisabledAccountException(org.apache.shiro.authc.DisabledAccountException) FailedLoginException(javax.security.auth.login.FailedLoginException) ExcessiveAttemptsException(org.apache.shiro.authc.ExcessiveAttemptsException) AccountLockedException(javax.security.auth.login.AccountLockedException) AccountDisabledException(org.apereo.cas.authentication.exceptions.AccountDisabledException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) AuthenticationException(org.apache.shiro.authc.AuthenticationException) ExpiredCredentialsException(org.apache.shiro.authc.ExpiredCredentialsException) PreventedException(org.apereo.cas.authentication.PreventedException) LockedAccountException(org.apache.shiro.authc.LockedAccountException) UnknownAccountException(org.apache.shiro.authc.UnknownAccountException)

Example 2 with IniSecurityManagerFactory

use of org.apache.shiro.config.IniSecurityManagerFactory in project killbill by killbill.

the class EntitlementTestSuiteWithEmbeddedDB method configureShiro.

protected void configureShiro() {
    final Ini config = new Ini();
    config.addSection("users");
    config.getSection("users").put("EntitlementUser", "password, entitlement");
    config.addSection("roles");
    config.getSection("roles").put("entitlement", Permission.ACCOUNT_CAN_CREATE.toString() + "," + Permission.ENTITLEMENT_CAN_CREATE.toString() + "," + Permission.ENTITLEMENT_CAN_CHANGE_PLAN.toString() + "," + Permission.ENTITLEMENT_CAN_PAUSE_RESUME.toString() + "," + Permission.ENTITLEMENT_CAN_TRANSFER.toString() + "," + Permission.ENTITLEMENT_CAN_CANCEL.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 3 with IniSecurityManagerFactory

use of org.apache.shiro.config.IniSecurityManagerFactory 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 4 with IniSecurityManagerFactory

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

Example 5 with IniSecurityManagerFactory

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

IniSecurityManagerFactory (org.apache.shiro.config.IniSecurityManagerFactory)8 SecurityManager (org.apache.shiro.mgt.SecurityManager)6 Ini (org.apache.shiro.config.Ini)2 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)2 GeneralSecurityException (java.security.GeneralSecurityException)1 AccountLockedException (javax.security.auth.login.AccountLockedException)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 CredentialExpiredException (javax.security.auth.login.CredentialExpiredException)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 PostProcessor (org.apache.geode.security.PostProcessor)1 SecurityManager (org.apache.geode.security.SecurityManager)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 DisabledAccountException (org.apache.shiro.authc.DisabledAccountException)1 ExcessiveAttemptsException (org.apache.shiro.authc.ExcessiveAttemptsException)1 ExpiredCredentialsException (org.apache.shiro.authc.ExpiredCredentialsException)1 IncorrectCredentialsException (org.apache.shiro.authc.IncorrectCredentialsException)1 LockedAccountException (org.apache.shiro.authc.LockedAccountException)1 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 ConfigurationException (org.apache.shiro.config.ConfigurationException)1