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

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

Introduction

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

Prototype

public Collection<Realm> getRealms() 

Source Link

Document

Returns the Realm Realm s managed by this SecurityManager instance.

Usage

From source file:Global.java

License:Open Source License

@Override
public void onStop(Application application) {

    Logger.debug("DOING ON STOP");

    HibernateSessionFactory.closeSession();
    HibernateSessionFactory.unloadAll();
    DatabaseManager dbManager = DatabaseManager.getInstance();
    dbManager.initialize("default");
    dbManager.closeIfConnectionOpen();/*  w w w. j a  va 2 s .  c o  m*/
    dbManager.unloadAll();

    RealmSecurityManager mgr = (RealmSecurityManager) SecurityUtils.getSecurityManager();

    Collection<Realm> realmCollection = mgr.getRealms();
    realmCollection.clear();

    /*
    Iterator<Realm> i = realmCollection.iterator();
            
    //There should be only one realm?
    while(i.hasNext()) {
            
    try {
        SampleRealm r = (SampleRealm) i.next();
            
        r.invalidateUser(SecurityUtils.getSubject().getPrincipals());
    } catch (Exception ee) {
            
    }
            
    }*/

    mgr.destroy();

    super.onStop(application);
}

From source file:cn.powerdash.libsystem.common.security.SecurityContext.java

License:Open Source License

/**
 * Description: ??//from ww w .j a  v  a  2s .  c  o m
 * 
 * @param userId
 */
public static void clearAuthzCache(String userName) {
    RealmSecurityManager sm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    for (Realm realm : sm.getRealms()) {
        if (realm instanceof ShiroJdbcRealm) {
            ShiroJdbcRealm jdbcRealm = (ShiroJdbcRealm) realm;
            SimplePrincipalCollection spc = new SimplePrincipalCollection(userName, realm.getName());
            jdbcRealm.clearAuthorizationCache(spc);
        }
    }
    LOGGER.info("Authorization cache cleared for user: {}", userName);
}

From source file:cn.powerdash.libsystem.common.security.SecurityContext.java

License:Open Source License

/**
 * Description: ??/*from   ww  w .j av  a  2s  . c  o  m*/
 * 
 * @param userId
 */
public static void clearAuthcCache(String userName) {
    RealmSecurityManager sm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    for (Realm realm : sm.getRealms()) {
        if (realm instanceof ShiroJdbcRealm) {
            ShiroJdbcRealm jdbcRealm = (ShiroJdbcRealm) realm;
            SimplePrincipalCollection spc = new SimplePrincipalCollection(userName, realm.getName());
            jdbcRealm.clearAuthenticationCache(spc);
        }
    }
}

From source file:com.sonicle.webtop.core.app.shiro.ShiroUtils.java

License:Open Source License

public static Realm getRealmByName(String name) {
    RealmSecurityManager realmMgr = getRealmSecurityManager();
    for (Realm realm : realmMgr.getRealms()) {
        if (realm.getName().equals(name))
            return realm;
    }/*from   ww  w  .  j  a  v a 2s  . co  m*/
    return null;
}

From source file:com.thesett.util.security.web.ShiroDBRealmSetupListener.java

License:Apache License

/**
 * {@inheritDoc}/*  w w  w .  j a  v  a 2  s.  c  o m*/
 *
 * <p/>Initializes the Shiro DB realms.
 */
public void contextInitialized(ServletContextEvent sce) {
    LOG.fine("public void contextInitialized(ServletContextEvent sce): called");

    RealmSecurityManager rsm = getRealmSecurityManager(sce);

    for (Realm r : rsm.getRealms()) {
        if (r instanceof ShiroDBRealm) {
            initializeRealm((ShiroDBRealm) r);

            if (initFirstRealmOnly) {
                break;
            }
        }
    }
}

From source file:com.thesett.util.security.web.ShiroDBRealmSetupListener.java

License:Apache License

/**
 * {@inheritDoc}//from   w w w. j  a v a  2 s  .  c o  m
 *
 * <p/>Destroys the Shiro DB realms.
 */
public void contextDestroyed(ServletContextEvent sce) {
    LOG.fine("public void contextDestroyed(ServletContextEvent sce): called");

    RealmSecurityManager rsm = getRealmSecurityManager(sce);

    for (Realm r : rsm.getRealms()) {
        if (r instanceof ShiroDBRealm) {
            destroyRealm((ShiroDBRealm) r);

            if (initFirstRealmOnly) {
                break;
            }
        }
    }
}

From source file:com.thesett.util.security.web.ShiroJWTRealmSetupListener.java

License:Apache License

/**
 * {@inheritDoc}/*from   ww w .java  2  s  . c om*/
 *
 * <p/>Initializes the Shiro DB realms.
 */
public void contextInitialized(ServletContextEvent sce) {
    LOG.fine("public void contextInitialized(ServletContextEvent sce): called");

    RealmSecurityManager rsm = getRealmSecurityManager(sce);

    for (Realm r : rsm.getRealms()) {
        if (r instanceof ShiroJWTRealm) {
            initializeRealm((ShiroJWTRealm) r);

            if (initFirstRealmOnly) {
                break;
            }
        }
    }
}

From source file:com.thesett.util.security.web.ShiroJWTRealmSetupListener.java

License:Apache License

/**
 * {@inheritDoc}/* w  w  w  .j  a v a  2 s  . co m*/
 *
 * <p/>Destroys the Shiro DB realms.
 */
public void contextDestroyed(ServletContextEvent sce) {
    LOG.fine("public void contextDestroyed(ServletContextEvent sce): called");

    RealmSecurityManager rsm = getRealmSecurityManager(sce);

    for (Realm r : rsm.getRealms()) {
        if (r instanceof ShiroJWTRealm) {
            destroyRealm((ShiroJWTRealm) r);

            if (initFirstRealmOnly) {
                break;
            }
        }
    }
}

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);//  w  ww  . j  a v  a  2  s . c o  m
    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);/*  w ww  .j av a 2s .c o m*/
    rsm.setRealms(realms);
    ((DefaultWebEnvironment) webEnvironment).setSecurityManager(rsm);
    return webEnvironment;
}