2012-07-18 2 views
0

PlayFramework 1.2.x로 작성된 작은 응용 프로그램을 유지 관리해야합니다. 완료해야하는 항목 : 로그인 페이지에 보안 문자 추가. 이것은 로그인 페이지가 Secure 모듈에 의해 반자동으로 처리되기 때문에 분명히 생각보다 어렵습니다.PlayFramework 1.2.x 로그인 페이지에 보안 문자 추가하기

정상적인 HTTP 형식을 처리 할 때 PlayFramework는 형식 변수를 매개 변수로 컨트롤러 메서드에 전달합니다. 표준 보안 모듈을 사용하는 로그인 양식에는 사용자 이름과 암호 만 포함되며이 양식은 authenticate 메소드에 전달됩니다.

이제 captcha가 포함 된 사용자 정의 로그인 양식을 만들 수 있으며 Secure 모듈에서 authenticate 메소드를 덮어 쓸 수도 있습니다. 문제는 이것입니다 : captcha-code를 포함하도록 authenticate 메소드의 매개 변수를 변경할 수 없거나 다른 방법으로 수퍼 클래스의 메소드를 더 이상 오버라이드하지 않으며 메소드가 호출되지 않습니다. 여기서

#{extends 'main.html' /} #{set title:'Login' /} 

#{form @authenticate()} 

<p> 
    <label for="username">User name: </label> <input type="text" 
     name="username" id="username" maxlength="30" 
     value="${params.username}" /> 
</p> 
<p> 
    <label for="password">Password: </label> <input type="password" 
     name="password" id="password" maxlength="30" " /> 
</p> 
<p> 
    <label for="code">Please type the code below: </label> <img 
     src="@{Captcha.captcha(randomID)}" /> <br /> <input type="text" 
     name="code" id="code" size="18" value="" /> <input type="hidden" 
     name="randomID" value="${randomID}" /> 
</p> 
<p> 
    <input type="submit" id="signin" value="Log in" /> 
</p> 

#{/form} 

작동하지 않는 간단하여 인증 방법은 "코드"때문에 "randomID"여기

는 "으면"예에서 적응 보안 문자와 간단한 로그인 형태 정의되지 않았습니다. 다시 말하지만, 인증을 위해 매개 변수를 추가 할 수 없으며, 그렇지 않으면 더 이상 수퍼 클래스의 메소드를 대체하지 않고 호출되지 않습니다.

package controllers; 

import play.cache.Cache; 
import play.data.validation.Required; 
import models.*; 

public class Security extends Secure.Security { 


    static boolean authenticate(String username, String password) { 
     boolean auth = false; 
     if (code.equals(Cache.get(randomID))) { 
      auth = (User.connect(username, password) != null); 
     } 
     return auth; 
    } 
} 

질문 : 양식에서 "authenticate"값으로 "code"및 "randomID"값을 얻으려면 어떻게해야합니까? 양식에서 값에 액세스하는 다른 방법이 있습니까?

답변

0

재생 중입니다! 컨트롤러이므로 객체 request.params에 액세스 할 수 있으며 그 중 request.params.get("code")처럼 매개 변수를 가져올 수 있습니다.