ec.gob.senescyt.sniese.commons.security.shiro.ShiroBundle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sniese-commons Show documentation
Show all versions of sniese-commons Show documentation
Librería que contiene clases de uso comun para sniese hechos en dropwizard
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