如何在Spring Security中允许单个URL

时间:2019-03-19 15:32:52

标签: spring http spring-security jwt

我有两个获取网址

  
      
  1. / api / appconsole / app / {appid}
  2.   
  3. / api / appconsole / app / search
  4.   

我想保护第二个API,但想允许第一个API。

下面的

是websecurityconfig.java文件。 我应该写什么,以便只允许第一个api,即/ api / appconsole / app / {appid}

httpSecurity.csrf().disable()

                .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()

                // don't create session
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()

                .authorizeRequests()
                //.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()

                // allow anonymous resource requests
                .antMatchers(
                        HttpMethod.GET,
                        "/",
                        "/file/**/*.*",
                        "/*.html",
                        "/favicon.ico",
                        "/**/*.html",
                        "/**/*.css",
                        "/**/*.js"
                ).permitAll()
                .antMatchers(HttpMethod.GET, "/api/appconsole/app/{appid}").permitAll()
                .antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll()
                .antMatchers("/ws/**").permitAll()
                .antMatchers("/upload").permitAll()
                .antMatchers("/login/**").permitAll()
                .antMatchers("/registration/**").permitAll()
                .antMatchers("/api/orbeon/**").permitAll()
                .anyRequest().authenticated();

谢谢。

1 个答案:

答案 0 :(得分:0)

订单很重要:

http ...
   .antMatchers(HttpMethod.GET, "/api/appconsole/app/search").authenticated()
   .antMatchers(HttpMethod.GET, "/api/appconsole/app/*").permitAll()