Example usage for org.apache.shiro.mgt RealmSecurityManager setRealms

List of usage examples for org.apache.shiro.mgt RealmSecurityManager setRealms

Introduction

In this page you can find the example usage for org.apache.shiro.mgt RealmSecurityManager setRealms.

Prototype

public void setRealms(Collection<Realm> realms) 

Source Link

Document

Sets the realms managed by this SecurityManager instance.

Usage

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);/*from   w  w  w.j  a  v  a2s  .c  o m*/
    realms.add(managerJPARealm);
    rsm.setRealms(realms);

    rsm.setCacheManager(new MemoryConstrainedCacheManager());

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

    return environment;
}

From source file:de.fatalix.app.bl.authentication.CDIAwareShiroEnvironmentLoader.java

@Override
protected WebEnvironment createEnvironment(ServletContext sc) {
    WebEnvironment webEnvironment = super.createEnvironment(sc);

    RealmSecurityManager rsm = (RealmSecurityManager) webEnvironment.getSecurityManager();
    SimpleCredentialsMatcher credentialsMatcher = new SimpleCredentialsMatcher();

    jpaRealm.setCredentialsMatcher(credentialsMatcher);
    Collection<Realm> realms = rsm.getRealms();
    realms.add(jpaRealm);/*from  w  w w.j  av  a  2s.  com*/
    rsm.setRealms(realms);

    ((DefaultWebEnvironment) webEnvironment).setSecurityManager(rsm);
    return webEnvironment;
}

From source file:de.fatalix.bookery.bl.authentication.CDIAwareShiroEnvironmentLoader.java

License:Open Source License

@Override
protected WebEnvironment createEnvironment(ServletContext sc) {
    WebEnvironment webEnvironment = super.createEnvironment(sc);
    RealmSecurityManager rsm = (RealmSecurityManager) webEnvironment.getSecurityManager();
    HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(HASHING_ALGORITHM);
    hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true);
    jpaRealm.setCredentialsMatcher(hashedCredentialsMatcher);
    Collection<Realm> realms = rsm.getRealms();
    realms.add(jpaRealm);/*from  ww  w.j a va  2  s.  co m*/
    rsm.setRealms(realms);
    ((DefaultWebEnvironment) webEnvironment).setSecurityManager(rsm);
    return webEnvironment;
}

From source file:org.panifex.security.shiro.env.ModularWebEnvironment.java

License:Open Source License

/**
 * Synchronizes the realm's map with the security manager.
 *//*from www . j  a  va 2  s .co m*/
protected final void synchronizeRealms() {
    RealmSecurityManager securityManager = (RealmSecurityManager) getSecurityManager();

    if (securityManager != null) {
        if (!realms.isEmpty()) {
            securityManager.setRealms(realms.values());
        } else {
            // bind simple realm because it should be at least one realm
            securityManager.setRealm(new SimpleAccountRealm());
        }
    } else {
        log.warn("Realm security manager is not available. Realms is not updated");
    }
}