Ignore:
Timestamp:
09/04/21 11:14:25 (3 years ago)
Author:
NikolaCenevski <cenevskinikola@…>
Branches:
master
Children:
ab49338
Parents:
194776a
Message:

Dodadeno posts to be approved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/it/finki/charitable/security/SecurityConfig.java

    r194776a r5306751  
    77import org.springframework.security.config.annotation.web.builders.HttpSecurity;
    88import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
     9import org.springframework.security.core.Authentication;
    910import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
     11import org.springframework.security.web.DefaultRedirectStrategy;
     12import org.springframework.security.web.RedirectStrategy;
     13import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
    1014import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
     15
     16import javax.servlet.ServletException;
     17import javax.servlet.http.HttpServletRequest;
     18import javax.servlet.http.HttpServletResponse;
     19import java.io.IOException;
    1120
    1221@Configuration
     
    4049                .authorizeRequests()
    4150                .antMatchers(publicMatchers).permitAll()
    42                 .antMatchers("/moderator-photos/**").hasAuthority(UserRole.MODERATOR.name())
    43                 .anyRequest().authenticated();
     51                .antMatchers("/moderator-photos/**", "/moderator/**").hasAuthority(UserRole.MODERATOR.name())
     52                .anyRequest().hasAuthority(UserRole.USER.name());
    4453
    4554        http
     
    4756                .cors().disable()
    4857                .formLogin().loginPage("/login")
    49                 .defaultSuccessUrl("/", true)
     58                .successHandler(authenticationSuccessHandler)
    5059                .and()
    5160                .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
     
    5564    }
    5665
     66    AuthenticationSuccessHandler authenticationSuccessHandler = (httpServletRequest, httpServletResponse, authentication) -> {
     67        RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
     68        if(authentication.getAuthorities().toString().contains("MODERATOR")) {
     69            redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/moderator/approval");
     70        } else {
     71            redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/");
     72        }
     73    };
     74
    5775    @Override
    5876    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
Note: See TracChangeset for help on using the changeset viewer.