Example usage for org.apache.shiro.web.env WebEnvironment getSecurityManager

List of usage examples for org.apache.shiro.web.env WebEnvironment getSecurityManager

Introduction

In this page you can find the example usage for org.apache.shiro.web.env WebEnvironment getSecurityManager.

Prototype

SecurityManager getSecurityManager();

Source Link

Document

Returns the application's SecurityManager instance.

Usage

From source file:com.github.mizool.technology.web.shiro.AbstractEnvironmentLoaderListener.java

License:Apache License

@Override
protected WebEnvironment createEnvironment(ServletContext pServletContext) {
    WebEnvironment environment = super.createEnvironment(pServletContext);
    AuthorizingSecurityManager securityManager = (AuthorizingSecurityManager) environment.getSecurityManager();
    securityManager.setRealms(getRealms());
    securityManager.setAuthorizer(getAuthorizer());

    return environment;
}

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  ww  . j av  a 2  s .com
    realms.add(managerJPARealm);
    rsm.setRealms(realms);

    rsm.setCacheManager(new MemoryConstrainedCacheManager());

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

    return environment;
}

From source file:com.josue.shiro.cdi.custom.CustomEnvironmentLoaderListener.java

@Override
protected WebEnvironment createEnvironment(ServletContext pServletContext) {
    WebEnvironment environment = super.createEnvironment(pServletContext);
    RealmSecurityManager rsm = (RealmSecurityManager) environment.getSecurityManager();

    PasswordService passwordService = new DefaultPasswordService();
    PasswordMatcher passwordMatcher = new PasswordMatcher();
    passwordMatcher.setPasswordService(passwordService);

    jpaRealm.setCredentialsMatcher(passwordMatcher);
    rsm.setRealm(jpaRealm);//from   w  w w.  j  a v a2 s  . co m
    ((DefaultWebEnvironment) environment).setSecurityManager(rsm);
    return environment;
}

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

License:Apache License

/**
 * Obtains the Shiro RealmSecurityManager for this Servlet container.
 *
 * @param  sce A context event notifying what this Servlet container is.
 *
 * @return The Shiro RealmSecurityManager for this Servlet container.
 *///  w w  w . jav a 2s  .  c  o  m
protected RealmSecurityManager getRealmSecurityManager(ServletContextEvent sce) {
    LOG.fine("protected RealmSecurityManager getRealmSecurityManager(ServletContextEvent sce): called");

    WebEnvironment we = WebUtils.getWebEnvironment(sce.getServletContext());

    return (RealmSecurityManager) we.getSecurityManager();
}

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

From source file:net.scran24.user.server.services.InitListener.java

License:Apache License

public void contextInitialized(ServletContextEvent contextEvent) {
    ServletContext context = contextEvent.getServletContext();

    Map<String, String> configParams = new HashMap<String, String>();

    Enumeration<String> paramNames = context.getInitParameterNames();

    while (paramNames.hasMoreElements()) {
        String name = paramNames.nextElement();
        configParams.put(name, context.getInitParameter(name));
    }//from   w  w  w  .ja  v  a2 s  .c o  m

    AbstractModule configModule;

    try {
        Constructor<?> ctor = Class.forName(context.getInitParameter("config-module"))
                .getConstructor(Map.class);
        configModule = (AbstractModule) ctor.newInstance(configParams);
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException
            | SecurityException | IllegalArgumentException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }

    Injector injector = Guice.createInjector(configModule);

    context.setAttribute("intake24.injector", injector);

    WebEnvironment shiroEnvironment = (WebEnvironment) context
            .getAttribute(EnvironmentLoader.ENVIRONMENT_ATTRIBUTE_KEY);
    RealmSecurityManager securityManager = (RealmSecurityManager) shiroEnvironment.getSecurityManager();

    ScranAuthRealm securityRealm = new ScranAuthRealm(injector.getInstance(DataStore.class));

    HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
    credentialsMatcher.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);
    credentialsMatcher.setStoredCredentialsHexEncoded(false);
    credentialsMatcher.setHashIterations(1024);

    securityRealm.setCredentialsMatcher(credentialsMatcher);
    securityManager.setRealm(securityRealm);

}