1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
.authenticator
;
23 import org
.apache
.commons
.httpclient
.HttpStatus
;
25 import eu
.alefzero
.webdav
.WebdavClient
;
27 import android
.net
.Uri
;
28 import android
.os
.Handler
;
30 public class AuthenticationRunnable
implements Runnable
{
32 private OnAuthenticationResultListener mListener
;
33 private Handler mHandler
;
35 private String mUsername
;
36 private String mPassword
;
38 public AuthenticationRunnable(URL url
, String username
, String password
) {
45 public void setOnAuthenticationResultListener(
46 OnAuthenticationResultListener listener
, Handler handler
) {
54 uri
= Uri
.parse(mUrl
.toString());
55 int login_result
= WebdavClient
.tryToLogin(uri
, mUsername
, mPassword
);
56 switch (login_result
) {
57 case HttpStatus
.SC_OK
:
58 postResult(true
, uri
.toString());
60 case HttpStatus
.SC_UNAUTHORIZED
:
61 postResult(false
, "Invalid login or/and password");
63 case HttpStatus
.SC_NOT_FOUND
:
64 postResult(false
, "Wrong path given");
67 postResult(false
, "Internal server error, code: " + login_result
);
71 private void postResult(final boolean success
, final String message
) {
72 if (mHandler
!= null
&& mListener
!= null
) {
73 mHandler
.post(new Runnable() {
76 mListener
.onAuthenticationResult(success
, message
);