[英]Play Framework 2.3.x: Wrap Request object using Scala Oauth in Play Framework
[英]Play-Framework 2.3.x: How to secure play-framework application URL
我的基本要求是,我想保护我的游戏应用程序URL。 当用户点击url时,将显示一个弹出窗口或基本身份验证,用于访问应用程序登录页面,例如tomcat。 在tomcat中,我们可以轻松地使用基本身份验证。 但是玩用netty
服务器,我们如何在netty
做呢?
在播放框架中,如果我们想通过基本的浏览器身份验证来保护URL,则需要通过以下方式以编程方式进行处理:
object Application extends Controller {
private final val logger: Logger = LoggerFactory.getLogger("Application")
val config: Configuration = Play.application().configuration();
def index = Action { implicit request =>
logger.info("Serving index page...")
val authorization = request.headers.get("Authorization");
if(!authorization.isEmpty) {
val cridentials = new String(Base64.getDecoder.decode(request.headers.get("Authorization").get.substring(5).trim()));
val arr = cridentials.split("\\:");
if(!arr.isEmpty && arr.apply(0).equalsIgnoreCase(config.getString("username")) && arr.apply(1).equalsIgnoreCase(config.getString("password"))){
Ok(views.html.index());
}else {
Unauthorized("Protected Security").withHeaders(
"WWW-Authenticate" -> "Basic realm=Protected Security"
)
}
}else{
Unauthorized("Protected Security").withHeaders(
"WWW-Authenticate" -> "Basic realm=Protected Security"
)
}}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.