Java 在play1.2.4应用程序中使用ssl
我需要在web应用程序中使用https连接器发出某些请求。假设我的Java 在play1.2.4应用程序中使用ssl,java,ssl,https,playframework,Java,Ssl,Https,Playframework,我需要在web应用程序中使用https连接器发出某些请求。假设我的CustomerController中有两种方法需要发送敏感信息。此外,我使用controllers.Secure.Security的子类进行身份验证(通过实现身份验证(…),因此登录信息必须通过ssl 我浏览了.From-SO帖子,发现我需要一个控制器来确保ssl class EnsureSSL extends Controller { @Before static void verifySSL() { if(!re
CustomerController
中有两种方法需要发送敏感信息。此外,我使用controllers.Secure.Security
的子类进行身份验证(通过实现身份验证(…)
,因此登录信息必须通过ssl
我浏览了.From-SO帖子,发现我需要一个控制器来确保ssl
class EnsureSSL extends Controller {
@Before
static void verifySSL() {
if(!request.secure) {
redirect("https://" + request.host + request.url);
}
}
}
现在,我需要在任何发送敏感信息的请求上使用它。我想在登录/身份验证请求
以及CustomerController
的两种敏感方法上使用它
正确的方法是什么?@With(..)只能用于整个类。因此我不能在CustomerController类中仅使用某些方法来使用SSL。如果我限制整个类,这不会增加负载吗
需要CustomerController.java的方法级装饰
安全性的类级装饰。java
我想知道我是否走错了方向。有人能提供建议吗?您可以为此创建自己的注释:
package utils;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface RequiresSSL {
}
现在创建如下控制器方法:
@With(EnsureSSL.class)
class CustomerController extends Controller{
@RequiresSSL
public static void sensitiveMethod1(...){
...
}
@RequiresSSL
public static void sensitiveMethod2(...){
...
}
public static void freeForAllToSee(...){
...
}
}
并在检查前将您的EnsureSSL修改为:
class EnsureSSL extends Controller {
@Before
static void verifySSL() {
if((!request.secure)
&& (request.invokedMethod.getAnnotation(RequiresSSL.class) != null)) {
redirect("https://" + request.host + request.url);
}
}
}
我想,我将不得不修改重定向url以添加,因为ssl和正常应用程序运行的端口是不同的
@With(EnsureSSL.class)
class CustomerController extends Controller{
@RequiresSSL
public static void sensitiveMethod1(...){
...
}
@RequiresSSL
public static void sensitiveMethod2(...){
...
}
public static void freeForAllToSee(...){
...
}
}
class EnsureSSL extends Controller {
@Before
static void verifySSL() {
if((!request.secure)
&& (request.invokedMethod.getAnnotation(RequiresSSL.class) != null)) {
redirect("https://" + request.host + request.url);
}
}
}