- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为 Web 应用程序的某些页面启用 HTTPS。我将 Spring MVC 和 Spring Security 用于部署在 Tomcat 上的 Web 应用程序,并使用 Nginx 作为 tomcat 的代理。
首先,无需任何 HTTPS 配置,一切正常。我生成了一个自签名 SSL 证书并将其安装在 Nginx 上。我没有对 Tomcat 进行任何更改以启用 HTTPS,因为我只希望 Nginx 处理 SSL 终止。这是我的 SSL 相关 Nginx 配置。
listen 443;
server_name 127.0.0.1;
root /usr/local/server/web/webapps/ROOT;
ssl on;
ssl_certificate /usr/local/etc/nginx/ssl/server.crt;
ssl_certificate_key /usr/local/etc/nginx/ssl/server.key;
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
我的 SSL Spring 安全配置如下所示:
<http pattern="/static/**" security="none" />
<http pattern="/favicon*" security="none" />
<http use-expressions="true">
<intercept-url pattern="/login" access="permitAll" requires-channel="https" />
<intercept-url pattern="/loginprocess" method="POST" requires-channel="https" />
<intercept-url pattern="/logout" access="isAuthenticated()"/>
<intercept-url pattern="/**" access="isAuthenticated()" requires-channel="https" />
<form-login username-parameter="username"
password-parameter="password" login-page="/login"
login-processing-url="/loginprocess" default-target-url="/hiring"
authentication-failure-url="/login?error" always-use-default-target="true" />
<logout logout-url="/logout" logout-success-url="/login?logout" />
</http>
现在,当我尝试在浏览器上访问登录页面时 - https://localhost/internal/login
,出现错误 -
This webpage has a redirect loop
Spring Security 中的日志如下所示:
12:34:55.240 [http-bio-8080-exec-33] DEBUG o.s.security.web.FilterChainProxy - /login at position 1 of 10 in additional filter chain; firing Filter: 'ChannelProcessingFilter'
12:34:55.240 [http-bio-8080-exec-33] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/login'; against '/login'
12:34:55.240 [http-bio-8080-exec-33] DEBUG o.s.s.w.a.c.ChannelProcessingFilter - Request: FilterInvocation: URL: /login; ConfigAttributes: [REQUIRES_SECURE_CHANNEL]
12:34:55.240 [http-bio-8080-exec-33] DEBUG o.s.s.w.a.c.RetryWithHttpsEntryPoint - Redirecting to: https://localhost/internal/login
12:34:55.241 [http-bio-8080-exec-33] DEBUG o.s.s.web.DefaultRedirectStrategy - Redirecting to 'https://localhost/internal/login'
我尝试使用 requires-channel 一段时间,但没有真正解决问题。任何帮助/指点都会很棒。
我尝试使用以下配置,重定向循环错误不再存在。但是,这些日志的身份验证失败 -
03:29:28.603 [http-bio-8080-exec-19] DEBUG o.s.s.w.a.c.ChannelProcessingFilter - Request: FilterInvocation: URL: /loginprocess; ConfigAttributes: [REQUIRES_SECURE_CHANNEL]
03:29:28.603 [http-bio-8080-exec-19] DEBUG o.s.s.w.a.c.RetryWithHttpsEntryPoint - Redirecting to: https://localhost/internal/loginprocess
03:29:28.603 [http-bio-8080-exec-19] DEBUG o.s.s.web.DefaultRedirectStrategy - Redirecting to 'https://localhost/internal/loginprocess'
03:29:28.609 [http-bio-8080-exec-11] DEBUG o.s.s.web.util.AntPathRequestMatcher - Request 'GET /loginprocess' doesn't match 'POST /loginprocess
03:29:28.609 [http-bio-8080-exec-11] DEBUG o.s.s.web.util.AntPathRequestMatcher - Request '/loginprocess' matched by universal pattern '/**'
03:29:28.614 [http-bio-8080-exec-20] DEBUG o.s.security.web.FilterChainProxy - /loginprocess at position 4 of 10 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
03:29:28.614 [http-bio-8080-exec-20] DEBUG o.s.s.w.a.UsernamePasswordAuthenticationFilter - Request is to process authentication
03:29:28.615 [http-bio-8080-exec-20] DEBUG o.s.s.w.a.UsernamePasswordAuthenticationFilter - Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: Authentication method not supported: GET
我想知道这是否又是同一个问题,因为 Spring Security 向浏览器发送了一个重定向,它返回一个 GET 请求。但是,如果登录登录页面是 HTTPS,并且 Spring 认为它是安全的,因为 RemoteIPValve,为什么又出现上述问题?
我没有在 RemoteIpValve 中添加 internalProxies 参数,这是导致问题的原因。
默认情况下,在 internalProxies 中启用了一些 IP 地址(在我的例子中,它是)。问题是身份验证间歇性地工作。我为 RemoteIpValve 启用了日志,并观察到代理 IP 是 IpV6 格式,这与 internalProxies 不匹配,因此没有为该请求启用 RemoteIpValve,因此出现了问题。我在 Mac OS X 上注释掉了 #fe80::1%lo0 localhost
行,问题就解决了。
对了,@M里面的配置。 Deinum 的回答似乎很有效。
最佳答案
您的 HTTPS 连接由 NGINX 处理。与您的应用程序的连接是 HTTP 连接。所以基本上是外在安全,内在不安全。
Spring Security 使用 isSecure()
来自 ServletRequest 的方法要确定它是否安全,默认情况下会检查协议(protocol)是否为 https。
当您使用 tomcat 时,您可以配置一个额外的阀,RemoteIpValue 3影响 isSecure()
的行为, getRemoteAddr()
方法(和其他一些方法)。
<Valve
className="org.apache.catalina.valves.RemoteIpValve"
internalProxies="192\.168\.0\.10|192\.168\.0\.11"
remoteIpHeader="x-forwarded-for"
proxiesHeader="x-forwarded-by"
protocolHeader="x-forwarded-proto"
/>
将以上内容添加到 <Host >
元素(当然您可能需要删除/修改内部代理参数)。
在您的 Nginx 配置中添加 X-Forwarded-proto header 。
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Front-End-Https on;
proxy_set_header Host $http_host;
}
或者简单地删除对安全通道的检查并假设一切正常...
链接
关于tomcat - 使用 Spring Security : This webpage has a redirect loop 启用 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18998711/
我认为这样的表达式会导致 Haskell 永远评估。但是 GHCi 和编译程序中的行为让我感到惊讶。 例如,在 GHCi 中,这些表达式一直阻塞到 I Control+C ,但不消耗 CPU。看起来像
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
如果可以的话,我想减少这段代码: class Alarm { internal static void isGreaterThanOrBelowValue(int min, int max,
我有以下问题: 我想创建一个批处理文件,循环访问一定数量的 IP 地址,以停止远程 PC 上的某个服务。 因为停止过程需要一些时间,所以我需要第二个循环来查询服务的状态并等待,直到服务达到“已停止”状
我已经完整地编写了“The Rust Programming Language”在线书籍中的程序,chapter 2 .我还进一步开发了它:通过添加一个简单的问题/响应,用户可以通过输入“y”再次玩游
这个人已经困扰了我一阵子了, 我们应该如何在集合中存储值或在for循环中映射? (let [s #{}] (for [ i (range 10) j (range 1
mov ecx, 16 looptop: . . . loop looptop 这个循环会执行多少次? 如果 ecx
我似乎无法找到一种在 Xtend 中表达以下内容而不诉诸 while 循环的好方法: for(int i = 0; i range(int stop) { range(0, stop) }
好吧,长话短说,我正在学习汇编,我正在尝试循环打印出 ascii 字符“0”-“9”。因此,我完成了我在示例中看到的所有基础知识,例如使用 pushad 和 popad 保存寄存器状态,分配堆栈空间,
我正在尝试为自己编写一个扑克计算器,我有一个 5 级深的 for 循环。 为此,我将 for 循环一个接一个地嵌套。我正在寻找一种方法来简单地使用一个循环(或函数),它可以告诉我想去多少层。对于这个例
我有一本包含约 150,000 个键的字典。没有重复的键。每个 key 的长度为 127 个字符,每个 key 在 1-11 个位置上有所不同(大多数差异发生在 key 的末尾)。每个键的值是一个唯一
我正在尝试编写一个 Lisp 程序来实现与点和方 block 非常相似的棋盘游戏,这意味着我有两个玩家相互竞争但可以连续移动。我正在尝试实现最简单的 minimax 算法来实现这一点,没有 alpha
下面是我实现的代码的简要说明。 for 循环的复杂度应该是 O(n)。我只是无法弄清楚内部 while 循环的时间复杂度。 int x,n; // Inputted by the user.
我目前正在尝试使用 html 分词器 https://godoc.org/golang.org/x/net/html . 所以我想做的是:从 url 获取所有链接,如果 url 包含特定字符串 ->
我有 32 个文件(以相同的模式命名,唯一的区别是下面写的 $sample 编号)我想分成 4 个文件夹。我正在尝试使用以下脚本来完成这项工作,但该脚本无法正常工作,有人可以帮我使用以下 shell
我必须根据 where 条件在我的内部表上做一个循环,但根据我的程序模式,必须在运行时修改 where 条件的字段。 我知道在 SELECT 语句中这是可能的,但是当我在循环中执行此操作时出现错误。
我正在学习关于kdb数据库的q。我担心q中没有循环。 我需要写一个算法,用像C这样的冗长程序在几个嵌套的for循环中编写。但是在q中,我被无法循环的事实所困扰。 仅举一个具体的例子(很多),我有一个简
我不明白为什么这段代码只循环一次然后退出? 在 Ghci 中,我只能回答第一个循环,然后似乎变量 cont 设置为 false 并且我没有提示回答。 结果是: *Main> testLoop1 td1
我正在 Racket 中运行 for 循环,对于列表中的每个对象,我想执行两件事:如果该项目满足条件,(1) 将其附加到我的新列表中,(2) 然后打印列表。但我不知道如何在 Racket 中执行此操作
我正在尝试使用 matlab 并行包中的 parfor 循环。我和这个人有类似的问题:MATLAB parfor slicing issue? 。输出矩阵似乎没有被识别为切片变量。在我的具体情况下,我
我是一名优秀的程序员,十分优秀!