简体   繁体   English

@PreAuthorize(“ isAuthenticated()”)重定向服务器太多次

[英]@PreAuthorize(“isAuthenticated()”) redirected server too many times

I'm trying to learn the @EnableGlobalMethodSecurity annotation in Spring. 我正在尝试在Spring中学习@EnableGlobalMethodSecurity批注。 Here is an example that doesnt seem to work for me. 这是一个对我似乎不起作用的示例。

THIS WORKS: Let's say I have a global controller that shows the logged-in username on every page, like so: 这项工作假设我有一个全局控制器,该控制器在每个页面上显示登录的用户名,如下所示:

@ControllerAdvice
public class GlobalController {

    @ModelAttribute("username")
    public String getCurrUser(Principal principal) {
        if (principal != null) {
            return principal.getName();
        }
        return null;
    }
}

THIS DOESNT WORK: The same controller now, but this time with preAuthorize annotation. 这项工作:现在是相同的控制器,但是这次带有preAuthorize注释。 This returns me the following error message: localhost redirected you too many times. 这将向我返回以下错误消息: localhost将您重定向了太多次。

@ControllerAdvice
public class GlobalController {

    @PreAuthorize("isAuthenticated()")
    @ModelAttribute("username")
    public String getCurrUser(Principal principal) {

        return principal.getName();
    }
}

My SecurityConfig class is annotated like this: 我的SecurityConfig类的注释如下:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

...

So how can I solve this error message with PreAuthorize annotation? 那么,如何使用PreAuthorize注释解决此错误消息?

I recently have been learning Spring and Spring security too. 我最近也一直在学习Spring和Spring安全性。 Doe your base url pattern has restriction or not ? 您的基本网址格式有限制吗? I tried to redirect all the logins to the same a point which according to my configuration required authentication. 我尝试将所有登录名重定向到同一点,根据我的配置需要进行身份验证。

See if the configuration is correct and access security is properly set on the code. 查看配置是否正确,并且在代码上正确设置了访问安全性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 服务器重定向太多次 - Server redirected too many times SOAP客户端 - ProtocolException:服务器重定向次数过多 - SOAP client - ProtocolException: Server redirected too many times Java HttpURLConnection问题:服务器重定向次数过多 - Java HttpURLConnection issue: Server redirected too many times java.net.ProtocolException: 服务器重定向次数过多 (20) - java.net.ProtocolException: Server redirected too many times (20) java.net.ProtocolException: 服务器重定向次数过多 - java.net.ProtocolException: Server redirected too many times 尝试检索 Sharepoint WSDL 失败,并显示“服务器重定向太多次” - Attempt to retrieve Sharepoint WSDL fails with “Server redirected too many times” 尝试使用 HTTPS 进行连接:服务器重定向次数过多 - Tring to connect using HTTPS: Server redirected too many times java.net.Authenticator:java.net.ProtocolException:服务器重定向太多次(20) - java.net.Authenticator : java.net.ProtocolException: Server redirected too many times (20) 获取“java.net.ProtocolException:服务器重定向次数太多”错误 - Getting “java.net.ProtocolException: Server redirected too many times” Error PreAuthorize(“ isAuthenticated()”)在RestController上不起作用 - PreAuthorize(“isAuthenticated()”) not working on RestController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM