fork download
  1. package pl.relayonit.prtr.configuration;
  2.  
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.http.HttpStatus;
  6. import org.springframework.security.authentication.AuthenticationManager;
  7. import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  8. import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
  9. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  10. import org.springframework.security.config.annotation.web.builders.WebSecurity;
  11. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  12. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  13. import org.springframework.security.config.http.SessionCreationPolicy;
  14. import org.springframework.security.crypto.password.PasswordEncoder;
  15. import org.springframework.security.web.AuthenticationEntryPoint;
  16. import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
  17. import org.springframework.security.web.authentication.HttpStatusEntryPoint;
  18. import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
  19. import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
  20. import org.springframework.security.web.util.matcher.NegatedRequestMatcher;
  21. import org.springframework.security.web.util.matcher.OrRequestMatcher;
  22. import org.springframework.security.web.util.matcher.RequestMatcher;
  23. import pl.relayonit.prtr.repository.UserRepository;
  24. import pl.relayonit.prtr.security.JwtConfigurer;
  25. import pl.relayonit.prtr.security.JwtTokenProvider;
  26. import pl.relayonit.prtr.security.NoRedirectStrategy;
  27.  
  28. import javax.servlet.http.HttpServletResponse;
  29.  
  30.  
  31. @Configuration
  32. @EnableWebSecurity
  33. @EnableGlobalMethodSecurity(prePostEnabled = true)
  34. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  35.  
  36. private static final RequestMatcher PUBLIC_URL = new OrRequestMatcher( new AntPathRequestMatcher("/auth/**"));
  37. private static final RequestMatcher PROTECTED_URL = new NegatedRequestMatcher(PUBLIC_URL);
  38.  
  39. private final JwtTokenProvider jwtTokenProvider;
  40.  
  41.  
  42. private final PasswordEncoder passwordEncoder;
  43.  
  44. public WebSecurityConfig(JwtTokenProvider jwtTokenProvider, PasswordEncoder passwordEncoder) {
  45. this.jwtTokenProvider = jwtTokenProvider;
  46. //this.userDetailsService = userDetailsService;
  47. this.passwordEncoder = passwordEncoder;
  48. }
  49.  
  50.  
  51. @Bean
  52. @Override
  53. public AuthenticationManager authenticationManagerBean() throws Exception {
  54. return super.authenticationManagerBean();
  55. }
  56.  
  57. @Bean
  58. public AuthenticationEntryPoint unauthorizedEntryPoint() {
  59. return (request, response, authExcepition) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
  60. }
  61.  
  62. @Override
  63. protected void configure(AuthenticationManagerBuilder auth) throws Exception
  64. {
  65. auth.userDetailsService(userDetailsService()).passwordEncoder((PasswordEncoder) passwordEncoder);
  66. }
  67.  
  68. @Override
  69. public void configure(final WebSecurity web) throws Exception
  70. {
  71. web.ignoring().requestMatchers(PUBLIC_URL);
  72. }
  73.  
  74. @Override
  75. protected void configure(final HttpSecurity http) throws Exception
  76. {
  77. http
  78. .httpBasic().disable()
  79. .csrf().disable()
  80. .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
  81. .and()
  82. .authorizeRequests()
  83. .antMatchers("/auth/login", "/auth/register").permitAll()
  84. .antMatchers("/api/v1/**").hasRole("ADMIN")
  85. .antMatchers("/api/v1/**").hasRole("GIOS_ADMIN")
  86. .antMatchers("/api/v1/**").hasRole("OPERATOR_WIOS")
  87. .antMatchers("/api/v1/**").hasRole("OPERATOR_INSTALACJI")
  88. .anyRequest().authenticated()
  89. .and()
  90. .csrf().disable()
  91. .exceptionHandling().authenticationEntryPoint(unauthorizedEntryPoint())
  92. .and()
  93. .apply(new JwtConfigurer(jwtTokenProvider));
  94.  
  95. /* http.authorizeRequests()
  96.   .antMatchers("/oauth/token").permitAll()
  97.   .anyRequest().authenticated()
  98.   .and()
  99.   .httpBasic()
  100.   .and()
  101.   .csrf().disable()
  102.   .formLogin().disable();*/
  103. }
  104.  
  105. @Bean
  106. AuthenticationSuccessHandler successHandler() {
  107. final SimpleUrlAuthenticationSuccessHandler successHandler = new SimpleUrlAuthenticationSuccessHandler();
  108. successHandler.setRedirectStrategy(new NoRedirectStrategy());
  109. return successHandler;
  110. }
  111.  
  112. @Bean
  113. AuthenticationEntryPoint forbiddenEntyry() {
  114. return new HttpStatusEntryPoint(HttpStatus.FORBIDDEN);
  115. }
  116.  
  117.  
  118. }
  119.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:34: error: class WebSecurityConfig is public, should be declared in a file named WebSecurityConfig.java
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
       ^
Main.java:3: error: package org.springframework.context.annotation does not exist
import org.springframework.context.annotation.Bean;
                                             ^
Main.java:4: error: package org.springframework.context.annotation does not exist
import org.springframework.context.annotation.Configuration;
                                             ^
Main.java:5: error: package org.springframework.http does not exist
import org.springframework.http.HttpStatus;
                               ^
Main.java:6: error: package org.springframework.security.authentication does not exist
import org.springframework.security.authentication.AuthenticationManager;
                                                  ^
Main.java:7: error: package org.springframework.security.config.annotation.authentication.builders does not exist
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
                                                                             ^
Main.java:8: error: package org.springframework.security.config.annotation.method.configuration does not exist
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
                                                                          ^
Main.java:9: error: package org.springframework.security.config.annotation.web.builders does not exist
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
                                                                  ^
Main.java:10: error: package org.springframework.security.config.annotation.web.builders does not exist
import org.springframework.security.config.annotation.web.builders.WebSecurity;
                                                                  ^
Main.java:11: error: package org.springframework.security.config.annotation.web.configuration does not exist
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
                                                                       ^
Main.java:12: error: package org.springframework.security.config.annotation.web.configuration does not exist
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
                                                                       ^
Main.java:13: error: package org.springframework.security.config.http does not exist
import org.springframework.security.config.http.SessionCreationPolicy;
                                               ^
Main.java:14: error: package org.springframework.security.crypto.password does not exist
import org.springframework.security.crypto.password.PasswordEncoder;
                                                   ^
Main.java:15: error: package org.springframework.security.web does not exist
import org.springframework.security.web.AuthenticationEntryPoint;
                                       ^
Main.java:16: error: package org.springframework.security.web.authentication does not exist
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
                                                      ^
Main.java:17: error: package org.springframework.security.web.authentication does not exist
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
                                                      ^
Main.java:18: error: package org.springframework.security.web.authentication does not exist
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
                                                      ^
Main.java:19: error: package org.springframework.security.web.util.matcher does not exist
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
                                                    ^
Main.java:20: error: package org.springframework.security.web.util.matcher does not exist
import org.springframework.security.web.util.matcher.NegatedRequestMatcher;
                                                    ^
Main.java:21: error: package org.springframework.security.web.util.matcher does not exist
import org.springframework.security.web.util.matcher.OrRequestMatcher;
                                                    ^
Main.java:22: error: package org.springframework.security.web.util.matcher does not exist
import org.springframework.security.web.util.matcher.RequestMatcher;
                                                    ^
Main.java:23: error: package pl.relayonit.prtr.repository does not exist
import pl.relayonit.prtr.repository.UserRepository;
                                   ^
Main.java:24: error: package pl.relayonit.prtr.security does not exist
import pl.relayonit.prtr.security.JwtConfigurer;
                                 ^
Main.java:25: error: package pl.relayonit.prtr.security does not exist
import pl.relayonit.prtr.security.JwtTokenProvider;
                                 ^
Main.java:26: error: package pl.relayonit.prtr.security does not exist
import pl.relayonit.prtr.security.NoRedirectStrategy;
                                 ^
Main.java:28: error: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
                         ^
Main.java:34: error: cannot find symbol
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                                       ^
  symbol: class WebSecurityConfigurerAdapter
Main.java:31: error: cannot find symbol
@Configuration
 ^
  symbol: class Configuration
Main.java:32: error: cannot find symbol
@EnableWebSecurity
 ^
  symbol: class EnableWebSecurity
Main.java:33: error: cannot find symbol
@EnableGlobalMethodSecurity(prePostEnabled = true)
 ^
  symbol: class EnableGlobalMethodSecurity
Main.java:36: error: cannot find symbol
    private static final RequestMatcher PUBLIC_URL = new OrRequestMatcher( new AntPathRequestMatcher("/auth/**"));
                         ^
  symbol:   class RequestMatcher
  location: class WebSecurityConfig
Main.java:37: error: cannot find symbol
    private static final RequestMatcher PROTECTED_URL = new NegatedRequestMatcher(PUBLIC_URL);
                         ^
  symbol:   class RequestMatcher
  location: class WebSecurityConfig
Main.java:39: error: cannot find symbol
    private final JwtTokenProvider jwtTokenProvider;
                  ^
  symbol:   class JwtTokenProvider
  location: class WebSecurityConfig
Main.java:42: error: cannot find symbol
    private final PasswordEncoder passwordEncoder;
                  ^
  symbol:   class PasswordEncoder
  location: class WebSecurityConfig
Main.java:44: error: cannot find symbol
    public WebSecurityConfig(JwtTokenProvider jwtTokenProvider, PasswordEncoder passwordEncoder) {
                             ^
  symbol:   class JwtTokenProvider
  location: class WebSecurityConfig
Main.java:44: error: cannot find symbol
    public WebSecurityConfig(JwtTokenProvider jwtTokenProvider, PasswordEncoder passwordEncoder) {
                                                                ^
  symbol:   class PasswordEncoder
  location: class WebSecurityConfig
Main.java:53: error: cannot find symbol
    public AuthenticationManager authenticationManagerBean() throws Exception {
           ^
  symbol:   class AuthenticationManager
  location: class WebSecurityConfig
Main.java:58: error: cannot find symbol
    public AuthenticationEntryPoint unauthorizedEntryPoint() {
           ^
  symbol:   class AuthenticationEntryPoint
  location: class WebSecurityConfig
Main.java:63: error: cannot find symbol
    protected void configure(AuthenticationManagerBuilder auth) throws Exception
                             ^
  symbol:   class AuthenticationManagerBuilder
  location: class WebSecurityConfig
Main.java:69: error: cannot find symbol
    public void configure(final WebSecurity web) throws Exception
                                ^
  symbol:   class WebSecurity
  location: class WebSecurityConfig
Main.java:75: error: cannot find symbol
    protected void configure(final HttpSecurity http) throws Exception
                                   ^
  symbol:   class HttpSecurity
  location: class WebSecurityConfig
Main.java:106: error: cannot find symbol
    AuthenticationSuccessHandler successHandler() {
    ^
  symbol:   class AuthenticationSuccessHandler
  location: class WebSecurityConfig
Main.java:113: error: cannot find symbol
    AuthenticationEntryPoint forbiddenEntyry() {
    ^
  symbol:   class AuthenticationEntryPoint
  location: class WebSecurityConfig
Main.java:51: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class WebSecurityConfig
Main.java:57: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class WebSecurityConfig
Main.java:105: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class WebSecurityConfig
Main.java:112: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class WebSecurityConfig
Main.java:36: error: cannot find symbol
    private static final RequestMatcher PUBLIC_URL = new OrRequestMatcher( new AntPathRequestMatcher("/auth/**"));
                                                         ^
  symbol:   class OrRequestMatcher
  location: class WebSecurityConfig
Main.java:36: error: cannot find symbol
    private static final RequestMatcher PUBLIC_URL = new OrRequestMatcher( new AntPathRequestMatcher("/auth/**"));
                                                                               ^
  symbol:   class AntPathRequestMatcher
  location: class WebSecurityConfig
Main.java:37: error: cannot find symbol
    private static final RequestMatcher PROTECTED_URL = new NegatedRequestMatcher(PUBLIC_URL);
                                                            ^
  symbol:   class NegatedRequestMatcher
  location: class WebSecurityConfig
Main.java:52: error: method does not override or implement a method from a supertype
    @Override
    ^
Main.java:54: error: cannot find symbol
        return super.authenticationManagerBean();
               ^
  symbol:   variable super
  location: class WebSecurityConfig
Main.java:59: error: cannot find symbol
        return (request, response, authExcepition) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
                                                                         ^
  symbol:   variable HttpServletResponse
  location: class WebSecurityConfig
Main.java:62: error: method does not override or implement a method from a supertype
    @Override
    ^
Main.java:65: error: cannot find symbol
        auth.userDetailsService(userDetailsService()).passwordEncoder((PasswordEncoder) passwordEncoder);
                                                                       ^
  symbol:   class PasswordEncoder
  location: class WebSecurityConfig
Main.java:65: error: cannot find symbol
        auth.userDetailsService(userDetailsService()).passwordEncoder((PasswordEncoder) passwordEncoder);
                                ^
  symbol:   method userDetailsService()
  location: class WebSecurityConfig
Main.java:68: error: method does not override or implement a method from a supertype
    @Override
    ^
Main.java:74: error: method does not override or implement a method from a supertype
    @Override
    ^
Main.java:93: error: cannot find symbol
                .apply(new JwtConfigurer(jwtTokenProvider));
                           ^
  symbol:   class JwtConfigurer
  location: class WebSecurityConfig
Main.java:80: error: cannot find symbol
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                                                           ^
  symbol:   variable SessionCreationPolicy
  location: class WebSecurityConfig
Main.java:107: error: cannot find symbol
        final SimpleUrlAuthenticationSuccessHandler successHandler = new SimpleUrlAuthenticationSuccessHandler();
              ^
  symbol:   class SimpleUrlAuthenticationSuccessHandler
  location: class WebSecurityConfig
Main.java:107: error: cannot find symbol
        final SimpleUrlAuthenticationSuccessHandler successHandler = new SimpleUrlAuthenticationSuccessHandler();
                                                                         ^
  symbol:   class SimpleUrlAuthenticationSuccessHandler
  location: class WebSecurityConfig
Main.java:108: error: cannot find symbol
        successHandler.setRedirectStrategy(new NoRedirectStrategy());
                                               ^
  symbol:   class NoRedirectStrategy
  location: class WebSecurityConfig
Main.java:114: error: cannot find symbol
        return  new HttpStatusEntryPoint(HttpStatus.FORBIDDEN);
                    ^
  symbol:   class HttpStatusEntryPoint
  location: class WebSecurityConfig
Main.java:114: error: cannot find symbol
        return  new HttpStatusEntryPoint(HttpStatus.FORBIDDEN);
                                         ^
  symbol:   variable HttpStatus
  location: class WebSecurityConfig
65 errors
stdout
Standard output is empty