且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

认证来自Android客户端一个Grails服务器

更新时间:2022-02-21 22:15:56

首先把旅游注意请求方法到您的网络appliaction。 据我所知,你应该发送POST方法请求。 第二个春天的安全检查你的cookies,尤其是参数JSESSIONID你只是把这个参数设置有效的春天已经提供凭据的安全性。 您可以通过一些网络分析仪的检查。

First of all put tour attention to request method to your web appliaction. As far as I know you should send POST method request. Second Spring security checks your cookies, especially parameter JSESSIONID you just make this parameter valid to Spring security having provided your credentials. You can check it via some network analyzer.

我计算出使用HttpCleint嵌入Android的类似的任务。这里是code这个问题上我用来实现自己的安全系统。

I worked out similar task using HttpCleint embedded in Android. Here is code listing I used to implement my own security system.

DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            HttpGet httpget = new HttpGet("https://yourwebbapp");

            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();

            System.out.println("Login form get: " + response.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Initial set of cookies:");
            List<Cookie> cookies = httpclient.getCookieStore().getCookies();
            if (cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }

            HttpPost httpost = new HttpPost("https://yourwebbapp");

            List <NameValuePair> nvps = new ArrayList <NameValuePair>();
            nvps.add(new BasicNameValuePair("IDToken1", "username"));
            nvps.add(new BasicNameValuePair("IDToken2", "password"));

            httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

            response = httpclient.execute(httpost);
            entity = response.getEntity();

            System.out.println("Login form get: " + response.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Post logon cookies:");
            cookies = httpclient.getCookieStore().getCookies();
            if (cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }

        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }