Example usage for org.apache.shiro.config IniSecurityManagerFactory getBeans

List of usage examples for org.apache.shiro.config IniSecurityManagerFactory getBeans

Introduction

In this page you can find the example usage for org.apache.shiro.config IniSecurityManagerFactory getBeans.

Prototype

public Map<String, ?> getBeans() 

Source Link

Usage

From source file:org.apache.activemq.shiro.env.IniEnvironment.java

License:Apache License

private Map<String, ?> createObjects(Ini ini) {
    IniSecurityManagerFactory factory = new IniSecurityManagerFactory(ini) {

        @Override//www .  j a va2s .  c  o m
        protected SecurityManager createDefaultInstance() {
            return new DefaultActiveMqSecurityManager();
        }

        @Override
        protected Realm createRealm(Ini ini) {
            IniRealm realm = (IniRealm) super.createRealm(ini);
            realm.setPermissionResolver(new ActiveMQPermissionResolver());
            return realm;
        }
    };
    factory.getInstance(); //trigger beans creation
    return factory.getBeans();
}

From source file:org.openiot.security.client.AccessControlUtilRest.java

License:Open Source License

AccessControlUtilRest(String moduleName, String configDir) {
    String key = null;//from w ww  . ja  v a2 s .  c om
    String secret = null;

    IniSecurityManagerFactory factory = null;
    if (moduleName != null) {
        if (configDir != null) {
            String iniFilePath = configDir + "/rest-client-" + moduleName + ".ini";
            Path path = Paths.get(iniFilePath);
            if (!Files.exists(path) || Files.isDirectory(path)) {
                logger.warn("The configuration file {} is not found.", iniFilePath);
            } else {
                factory = new IniSecurityManagerFactory("file:" + iniFilePath);
            }
        }
        PropertyManagement props = new PropertyManagement();
        key = props.getProperty("casOauthClient.key." + moduleName, null);
        secret = props.getProperty("casOauthClient.secret." + moduleName, null);
    }
    if (factory == null) {
        logger.info("Falling back to the rest-client.ini in the class path");
        String confFilePath = "classpath:rest-client.ini";
        factory = new IniSecurityManagerFactory(confFilePath);
    }

    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    if (key != null && secret != null) {
        CasOAuthWrapperClientRest bean = (CasOAuthWrapperClientRest) factory.getBeans().get("casOauthClient");
        bean.setKey(key);
        bean.setSecret(secret);
    } else if (moduleName != null) {
        logger.warn(
                "casOauthClient.key.{} or/and casOauthClient.secret.{} is not set in the global properties file",
                moduleName, moduleName);
    }

}

From source file:org.ops4j.pax.shiro.cdi.web.CdiIniWebEnvironment.java

License:Apache License

@Override
protected WebSecurityManager createWebSecurityManager() {
    Ini ini = getIni();/*from  w w  w.  j ava2s  . c om*/

    if (CollectionUtils.isEmpty(ini)) {
        ini = null;
    }

    BeanManager beanManager = BeanManagerProvider.getBeanManager();
    IniSecurityManagerFactory factory = new CdiWebIniSecurityManagerFactory(beanManager);
    factory.setIni(ini);

    WebSecurityManager wsm = (WebSecurityManager) factory.getInstance();
    Map<String, ?> beans = factory.getBeans();
    if (!CollectionUtils.isEmpty(beans)) {
        this.objects.putAll(beans);
    }

    return wsm;
}