Example usage for org.apache.shiro.cache MemoryConstrainedCacheManager MemoryConstrainedCacheManager

List of usage examples for org.apache.shiro.cache MemoryConstrainedCacheManager MemoryConstrainedCacheManager

Introduction

In this page you can find the example usage for org.apache.shiro.cache MemoryConstrainedCacheManager MemoryConstrainedCacheManager.

Prototype

MemoryConstrainedCacheManager

Source Link

Usage

From source file:br.com.criativasoft.opendevice.wsrest.AbstractAtmosphereConnection.java

License:Open Source License

private void initConnection() throws IOException {
    if (server == null) {
        OpenDeviceConfig odevc = ODev.getConfig();

        Config.Builder conf = new Config.Builder();
        conf.port(port);/*from   w w  w  .  j  av a2  s  . c o m*/
        conf.supportChunking(true);
        conf.maxChunkContentLength(5 * 1024 * 1024); // 5BM

        //conf.host("::0"); // bind all local IPs
        conf.host("0.0.0.0"); // bind all local IPs
        configure(conf);

        conf.resource(JacksonProvider.class);

        // Custom static resources
        for (String resource : webresources) {
            conf.resource(resource);
        }

        // Jersey
        for (Class<?> resource : resources) {
            conf.resource(resource);
        }

        conf.initParam("com.sun.jersey.api.json.POJOMappingFeature", "true");
        conf.initParam(ApplicationConfig.BROADCASTER_MESSAGE_PROCESSING_THREADPOOL_MAXSIZE, "10");
        conf.initParam(ApplicationConfig.BROADCASTER_ASYNC_WRITE_THREADPOOL_MAXSIZE, "10");
        conf.initParam(ApplicationConfig.SCAN_CLASSPATH, "false");
        conf.initParam(ApplicationConfig.ANALYTICS, "false");
        // conf.initParam(ApplicationConfig.DROP_ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "false");

        // conf.initParam("com.sun.jersey.spi.container.ResourceMethodDispatchProvider", "true");
        //.initParam(ApplicationConfig.OBJECT_FACTORY, GuiceConfigFactory.class.getName())
        conf.interceptor(new CrossOriginInterceptor());
        if (odevc.isAuthRequired())
            conf.interceptor(new NewShiroInterceptor());
        //            conf.interceptor(new JacksonFilterInterceptor());
        conf.interceptor(this); // add this as interceptor

        // SSL Support
        String certificate = odevc.getCertificateFile();
        if (!StringUtils.isEmpty(certificate)) {
            //                File cert = new File(certificate);
            //                if(!cert.exists()) throw new IllegalArgumentException("Certificate not found !");
            //                File key = new File(odevc.getCertificateKey());
            //                if(!key.exists()) throw new IllegalArgumentException("Certificate key must be provided !");
            //
            //                SslContext sslContext = SslContext.newServerContext(SslProvider.JDK, cert, key, odevc.getCertificatePass());
            //                conf.sslContext(sslContext);
        }

        // Authentication
        if (odevc.isAuthRequired()) {
            List<Realm> realms = new LinkedList<Realm>();
            realms.add(new BearerAuthRealm((DeviceManager) getConnectionManager()));
            realms.add(new GoogleAuthRealm((DeviceManager) getConnectionManager()));
            realms.add(new AccountDaoRealm((DeviceManager) getConnectionManager()));

            RestWebSecurityManager securityManager = new RestWebSecurityManager(realms);
            securityManager.setCacheManager(new MemoryConstrainedCacheManager());
            securityManager.setSessionManager(new DefaultWebSessionManager());

            Authenticator authenticator = securityManager.getAuthenticator();
            if (authenticator instanceof ModularRealmAuthenticator) {
                ((ModularRealmAuthenticator) authenticator)
                        .setAuthenticationStrategy(new FirstSuccessfulStrategy());
            }

            // NOTE: Works with ShiroResourceFilterFactory, registred in AppResourceConfigurator
            SecurityUtils.setSecurityManager(securityManager);

        }

        server = new Nettosphere.Builder().config(conf.build()).build();

        broadcasterFactory = server.framework().getBroadcasterFactory();
    }
}

From source file:cn.fh.starter.shiro.autoconfigure.ShiroManager.java

License:Apache License

/**
 * ??Cache/*from   w w w  .j av  a2s .c  o m*/
 */
@Bean(name = "shiroCacheManager")
@ConditionalOnMissingBean
public CacheManager cacheManager() {
    return new MemoryConstrainedCacheManager();
}

From source file:com.aegeus.core.AuthenticationConfiguration.java

License:Apache License

@Bean
public WebSecurityManager securityManager() {
    DefaultWebSecurityManager manager = new DefaultWebSecurityManager(realm());
    manager.setCacheManager(new MemoryConstrainedCacheManager());

    /**//w  ww  .ja v a  2 s .co  m
     * Set security manager
     */
    SecurityUtils.setSecurityManager(manager);

    return manager;
}

From source file:com.josue.kingdom.security.CustomEnvironmentLoaderListener.java

@Override
protected WebEnvironment createEnvironment(ServletContext pServletContext) {

    LOG.log(Level.INFO, "########## INITIALIZING CUSTOMENVIRONMENTLOADERLISTENER ##########");

    WebEnvironment environment = super.createEnvironment(pServletContext);
    RealmSecurityManager rsm = (RealmSecurityManager) environment.getSecurityManager();
    //TODO check for how to read from shiro.ini

    //        PasswordService passwordService = new DefaultPasswordService();
    //        PasswordMatcher passwordMatcher = new PasswordMatcher();
    //        passwordMatcher.setPasswordService(passwordService);
    //        jpaRealm.setCredentialsMatcher(passwordMatcher);
    //TODO add another realms here
    Set<Realm> realms = new HashSet<>();
    realms.add(apiCredentialJPARealm);/*  w  w  w  .j a  va 2  s  . c  o  m*/
    realms.add(managerJPARealm);
    rsm.setRealms(realms);

    rsm.setCacheManager(new MemoryConstrainedCacheManager());

    ((DefaultWebEnvironment) environment).setSecurityManager(rsm);

    return environment;
}

From source file:com.metropolitan.methotels727.services.UserRealm.java

public UserRealm(Session session) {
    super(new MemoryConstrainedCacheManager());
    setName("localaccounts");
    this.session = session;
    setAuthenticationTokenClass(UsernamePasswordToken.class);
    setCredentialsMatcher(new HashedCredentialsMatcher(Md5Hash.ALGORITHM_NAME));
}

From source file:com.milospaunovic.sedam.services.UserRealm.java

public UserRealm(Session session) {
    super(new MemoryConstrainedCacheManager());
    this.session = session;
    setName("localaccounts");
    // setName("localaccounts");
    this.session = session;
    setAuthenticationTokenClass(UsernamePasswordToken.class);
    setCredentialsMatcher(new HashedCredentialsMatcher(Md5Hash.ALGORITHM_NAME));
}

From source file:com.sonicle.webtop.core.app.WebTopApp.java

License:Open Source License

private DefaultSecurityManager buildSecurityManager() {
    DefaultSecurityManager newSecurityManager = new DefaultSecurityManager(new WTRealm());
    newSecurityManager.setCacheManager(new MemoryConstrainedCacheManager());
    DefaultSessionManager sessionManager = (DefaultSessionManager) newSecurityManager.getSessionManager();
    sessionManager.setGlobalSessionTimeout(-1);
    sessionManager.setDeleteInvalidSessions(false);
    sessionManager.setSessionValidationSchedulerEnabled(false);
    return newSecurityManager;
}

From source file:com.stormpath.sample.conf.CacheConfiguration.java

License:Apache License

@Bean
public CacheManager cacheManager() {
    return new MemoryConstrainedCacheManager();
}

From source file:com.stormpath.shiro.spring.config.CacheManagerConfiguration.java

License:Apache License

@Bean
CacheManager getCacheManager() {
    return new MemoryConstrainedCacheManager();
}

From source file:com.vectorization.server.node.AppInjector.java

License:Open Source License

@Singleton
@Provides//from  w w w  .j  a va2s .  c  o m
Realm provideRealm(DataSource dataSource) {
    JdbcRealm realm = new JdbcRealm();
    realm.setPermissionsLookupEnabled(true);
    realm.setDataSource(dataSource);
    realm.setCacheManager(new MemoryConstrainedCacheManager());
    return realm;
}