简体   繁体   中英

how to authenticate REST in play framework 1.2.5

i have an application of play that need to be secure. i have try to import module secure, it working the application need login now, and now i have another problem. I want to authenticate from REST. I mean how client request to my application for authenticate?, i have try like this

public static Response logIn(){
    DataInputStream dis = new DataInputStream(request.body);
    String request;
    response.status = 400;
    try {
        while(null != ((request = dis.readLine()))){
            JSONObject jsonObject = new JSONObject(request);
            String username = jsonObject.getString("username");
            String password = jsonObject.getString("password");
            boolean authenticated = Security.authenticate(username, password);
            if(authenticated){
                response.status = 200;
                return response;
            }else{
                response.status = 400;
                return response;
            }
        }
    } catch (IOException | JSONException e) {
        e.printStackTrace();
    }
    return response;
}

but when i test it with rest client, it error, it say that server redirected too many. Sorry for my bad English, i want an example if that posible

您可以尝试一项现成的决定,例如播放认证插件或使用本文。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM