【发布时间】:2014-11-24 22:01:16
【问题描述】:
我正在使用 scala 和 play 框架。我想在我的应用中使用播放安全授权。
之前我在项目中使用 java 实现它并播放如下:
public class Secured extends Security.Authenticator {
private static String EMAIL = "Email";
private static String U_COOKIE = "ucookie";
public String getUsername(Context ctx) {
String decodedText = null;
String CHARSET = "ISO-8859-1";
Cookies cookies = play.mvc.Controller.request().cookies();
try {
Cookie emailCookie = cookies.get(EMAIL);
Cookie uCookie = cookies.get(U_COOKIE);
if (uCookie !=null && uCookie.value() != null) {
String userId = uCookie.value();
}
if (emailCookie != null && emailCookie.value() != null) {
String email = emailCookie.value();
try {
decodedText = new String(Base64.decodeBase64(email.getBytes(CHARSET)));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
Logger.error(e.getMessage());
}
return decodedText;
}
public Result onUnauthorized(Context ctx) {
String done = play.mvc.Controller.request().path();
return redirect(routes.RegController.signIn(done));
}
}
我在所有使用方法中都使用了上述授权
@Security.Authenticated(Secured.class)
在我的应用程序中的任何方法之前。
当我调用任何方法时,@before 该方法调用安全类并验证用户。
现在我想用 scala 来实现同样的事情。以下是我的问题....
1) 是否可以使用@来继承和调用安全类的方法??
2) 调用play的安全认证的正确方法是什么??
附:我想使用 cookie 来实现安全认证/授权。
任何帮助或解决方法都将是很大的帮助..
【问题讨论】:
标签: scala security authentication