Search in sources :

Example 1 with LogoutHandler

use of eu.openanalytics.shinyproxy.auth.LogoutHandler in project shinyproxy by openanalytics.

the class WebSecurityConfig method configure.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable().headers().frameOptions().disable();
    if (auth.hasAuthorization()) {
        // Limit access to the app pages
        http.authorizeRequests().antMatchers("/login", "/signin/**", "/signup").permitAll();
        for (ShinyApp app : appService.getApps()) {
            String[] groups = app.getGroups();
            if (groups == null || groups.length == 0)
                continue;
            String[] appGroups = Arrays.stream(groups).map(s -> s.toUpperCase()).toArray(i -> new String[i]);
            http.authorizeRequests().antMatchers("/app/" + app.getName()).hasAnyRole(appGroups);
        }
        // Limit access to the admin pages
        http.authorizeRequests().antMatchers("/admin").hasAnyRole(userService.getAdminGroups());
        // All other pages are available to authenticated users
        http.authorizeRequests().anyRequest().fullyAuthenticated();
        http.formLogin().loginPage("/login").and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessHandler(logoutHandler).logoutSuccessUrl("/login");
    }
    auth.configureHttpSecurity(http);
}
Also used : Arrays(java.util.Arrays) AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) WebSecurity(org.springframework.security.config.annotation.web.builders.WebSecurity) ShinyApp(eu.openanalytics.shinyproxy.services.AppService.ShinyApp) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) IAuthenticationBackend(eu.openanalytics.shinyproxy.auth.IAuthenticationBackend) GlobalAuthenticationConfigurerAdapter(org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter) Inject(javax.inject.Inject) Configuration(org.springframework.context.annotation.Configuration) WebSecurityConfigurerAdapter(org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter) AppService(eu.openanalytics.shinyproxy.services.AppService) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) UserService(eu.openanalytics.shinyproxy.services.UserService) EnableWebSecurity(org.springframework.security.config.annotation.web.configuration.EnableWebSecurity) Bean(org.springframework.context.annotation.Bean) AuthenticationEventPublisher(org.springframework.security.authentication.AuthenticationEventPublisher) LogoutHandler(eu.openanalytics.shinyproxy.auth.LogoutHandler) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) ShinyApp(eu.openanalytics.shinyproxy.services.AppService.ShinyApp)

Aggregations

IAuthenticationBackend (eu.openanalytics.shinyproxy.auth.IAuthenticationBackend)1 LogoutHandler (eu.openanalytics.shinyproxy.auth.LogoutHandler)1 AppService (eu.openanalytics.shinyproxy.services.AppService)1 ShinyApp (eu.openanalytics.shinyproxy.services.AppService.ShinyApp)1 UserService (eu.openanalytics.shinyproxy.services.UserService)1 Arrays (java.util.Arrays)1 Inject (javax.inject.Inject)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1 AuthenticationEventPublisher (org.springframework.security.authentication.AuthenticationEventPublisher)1 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 AuthenticationManagerBuilder (org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder)1 GlobalAuthenticationConfigurerAdapter (org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter)1 HttpSecurity (org.springframework.security.config.annotation.web.builders.HttpSecurity)1 WebSecurity (org.springframework.security.config.annotation.web.builders.WebSecurity)1 EnableWebSecurity (org.springframework.security.config.annotation.web.configuration.EnableWebSecurity)1 WebSecurityConfigurerAdapter (org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter)1 AntPathRequestMatcher (org.springframework.security.web.util.matcher.AntPathRequestMatcher)1