小编lex*_*exx的帖子

如何使Spring Security应用程序在代理后面运行?

我们有一个基于Spring 1.6.3的Java 1.6上的应用程序,它使用Spring Security 3.0.5并使用Spring Web和RestEasy 2.1.0实现REST API.我需要将此应用程序(服务器)置于代理之后,该代理将HTTPS请求流量从REST API客户端应用程序转换为HTTP流量.此更改为登录请求创建"跨域"方案:客户端发送HTTPS登录请求,服务器使用HTTP的重定向URL进行应答.目前它回复:

”http://192.168.0.10:8090/index.html;jsessionid=64FD79...86D”,

我需要的是:

”/index.html;jsessionid=64FD79...86D”

我们提供了解决方案,使服务器响应"相对"URL而不是"绝对"URL.所以我尝试在这里实现与描述情况类似的东西:

在forum.spring.io上的线程

我已经使用contextRelative ="true"设置RedirectStrategy bean并从LoginSuccessHandler扩展类中的AbstractAuthenticationTargetUrlRequestHandler覆盖redirectStrategy setter,我看到HttpServletResponse对象的redirectStrategy属性按预期设置为true.仍然没有解决问题.

此外,当使用encodeRedirectURL("otherLogin")更改HttpServletResponse对象的redirectURLCC属性时,设置类似于

”http://192.168.0.10:8090/otherLogin”

而这不是我需要的.我需要删除URL的整个协议+ ipaddress部分.响应对象的URL属性无法进行更改,因为它由Filter和FilterChain接口实现包装.

请提出任何想法.我想这种事情应该在web.xml或auth-AplicationContext.xml文件中解决,而不是在代码中.

最好的祝福.

java spring spring-security resteasy

8
推荐指数
1
解决办法
5704
查看次数

将自定义异常序列化为JSON,并非所有字段都已序列化

我正在尝试使用Jackson库中的writeValueAsString()方法序列化Java中的自定义Exception。我打算通过HTTP将其发送到另一台计算机。这是局部工作的,因为序列化后并非所有字段都包含在JSON中。顶级异常Throwable实现了Serializable接口,并且还具有一些构造函数,这些构造函数添加有关要序列化的内容的信息。我想真相就在这里。请提供一些建议。这是我的自定义异常代码:

import java.io.Serializable;

public class MyException extends RuntimeException{

private static String type = null;
private static String severity = null;

// somewhere on google I red that should use setters to make serialize work

public static void setType(String type) {
    MyException.type = type;
}

public static void setSeverity(String severity) {
    MyException.severity = severity;
}

public MyException(String message) {
    super(message);
}
}
Run Code Online (Sandbox Code Playgroud)

我在代码中使用的某处:

MyException exc = new MyException("Here goes my exception.");
MyException.setType(exc.getClass().getSimpleName());    
MyException.setSeverity("Major");
throw exc;
Run Code Online (Sandbox Code Playgroud)

在其他地方,我有:

ObjectMapper mapper = new ObjectMapper(); …
Run Code Online (Sandbox Code Playgroud)

java serialization json custom-exceptions jackson

3
推荐指数
1
解决办法
6989
查看次数