All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ec.gob.senescyt.sniese.commons.security.shiro.ShiroBundle Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
package ec.gob.senescyt.sniese.commons.security.shiro;

import ec.gob.senescyt.sniese.commons.configurations.ConfiguracionSnieseBase;
import ec.gob.senescyt.sniese.commons.security.exceptions.ConfigurationNoEncontrada;
import io.dropwizard.ConfiguredBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.apache.shiro.web.env.EnvironmentLoaderListener;
import org.apache.shiro.web.servlet.ShiroFilter;
import org.eclipse.jetty.server.session.SessionHandler;

import javax.servlet.DispatcherType;
import java.util.EnumSet;

public class ShiroBundle implements ConfiguredBundle {

    @Override
    public void run(T configuracion, Environment ambiente) throws ConfigurationNoEncontrada {
        if (configuracion.getConfiguracionSegura().getPreferenciasShiro() == null) {
            throw new ConfigurationNoEncontrada();
        }

        inicializarShiro(configuracion.getConfiguracionSegura().getPreferenciasShiro(), ambiente);
    }

    @Override
    public void initialize(Bootstrap bootstrap) {
        // Do nothing
    }

    private void inicializarShiro(final PreferenciasShiro configuracion, Environment ambiente) {

        ambiente.servlets().addServletListeners(new EnvironmentLoaderListener());
        final String filterUrlPattern = configuracion.getSecuredUrlPattern();

        ambiente.servlets()
                .addFilter("shiro-filter", new ShiroFilter())
                .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, filterUrlPattern);

        ambiente.getApplicationContext().setSessionHandler(new SessionHandler());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy