List of usage examples for org.apache.shiro.authc.pam FirstSuccessfulStrategy FirstSuccessfulStrategy
FirstSuccessfulStrategy
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);/* w w w . jav a 2s .co 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:org.graylog2.bindings.providers.DefaultSecurityManagerProvider.java
License:Open Source License
@Inject public DefaultSecurityManagerProvider(MongoDbSessionDAO mongoDbSessionDAO, PasswordAuthenticator passwordAuthenticator, MongoDbAuthorizationRealm mongoDbAuthorizationRealm, LdapUserAuthenticator ldapUserAuthenticator, SessionAuthenticator sessionAuthenticator, AccessTokenAuthenticator accessTokenAuthenticator, Configuration configuration) { final GraylogSimpleAccountRealm inMemoryRealm = new GraylogSimpleAccountRealm(); inMemoryRealm.setCachingEnabled(false); inMemoryRealm.addRootAccount(configuration.getRootUsername(), configuration.getRootPasswordSha2()); inMemoryRealm.setCredentialsMatcher(new HashedCredentialsMatcher("SHA-256")); passwordAuthenticator.setCachingEnabled(false); passwordAuthenticator.setCredentialsMatcher(new HashedCredentialsMatcher("SHA-1")); mongoDbAuthorizationRealm.setCachingEnabled(false); ldapUserAuthenticator.setCachingEnabled(false); sessionAuthenticator.setCachingEnabled(false); accessTokenAuthenticator.setCachingEnabled(false); sm = new DefaultSecurityManager(Lists.<Realm>newArrayList(sessionAuthenticator, accessTokenAuthenticator, ldapUserAuthenticator, passwordAuthenticator, inMemoryRealm)); final Authenticator authenticator = sm.getAuthenticator(); if (authenticator instanceof ModularRealmAuthenticator) { ((ModularRealmAuthenticator) authenticator).setAuthenticationStrategy(new FirstSuccessfulStrategy()); }// ww w.java 2s . c o m sm.setAuthorizer( new ModularRealmAuthorizer(Lists.<Realm>newArrayList(mongoDbAuthorizationRealm, inMemoryRealm))); final DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO(); final DefaultSessionStorageEvaluator sessionStorageEvaluator = new DefaultSessionStorageEvaluator() { @Override public boolean isSessionStorageEnabled(Subject subject) { // save to session if we already have a session. do not create on just for saving the subject return (subject.getSession(false) != null); } }; sessionStorageEvaluator.setSessionStorageEnabled(false); subjectDAO.setSessionStorageEvaluator(sessionStorageEvaluator); sm.setSubjectDAO(subjectDAO); final DefaultSessionManager defaultSessionManager = (DefaultSessionManager) sm.getSessionManager(); defaultSessionManager.setSessionDAO(mongoDbSessionDAO); defaultSessionManager.setDeleteInvalidSessions(true); defaultSessionManager.setCacheManager(new MemoryConstrainedCacheManager()); // DO NOT USE global session timeout!!! It's fucky. //defaultSessionManager.setGlobalSessionTimeout(TimeUnit.SECONDS.toMillis(5)); SecurityUtils.setSecurityManager(sm); }
From source file:org.obiba.mica.security.SecurityManagerFactory.java
License:Open Source License
private void initializeAuthenticator(DefaultWebSecurityManager dsm) { if (dsm.getAuthenticator() instanceof ModularRealmAuthenticator) { ((ModularRealmAuthenticator) dsm.getAuthenticator()) .setAuthenticationStrategy(new FirstSuccessfulStrategy()); }/*w w w. ja v a2 s . c o m*/ }
From source file:org.owasp.dependencytrack.config.SecurityConfiguration.java
License:Open Source License
@Bean public FirstSuccessfulStrategy firstSuccessfulStrategy() { return new FirstSuccessfulStrategy(); }