Browse Source

Code cleanup / add check if auth token is correct

David Luhmer 7 years ago
parent
commit
b7712e7580

+ 11 - 33
src/main/java/com/owncloud/android/services/AccountManagerService.java

@@ -1,48 +1,26 @@
 package com.owncloud.android.services;
 
-import android.accounts.Account;
 import android.app.Service;
 import android.content.Intent;
-import android.os.Bundle;
-import android.os.Handler;
 import android.os.IBinder;
-import android.os.Message;
-import android.os.RemoteException;
-import android.util.Log;
-import android.widget.Toast;
-
-import com.owncloud.android.authentication.AccountUtils;
-import com.owncloud.android.lib.common.OwnCloudAccount;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.ui.activity.FileDisplayActivity;
-import com.owncloud.android.ui.asynctasks.AsyncTaskHelper;
-
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.methods.DeleteMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
-import org.apache.commons.io.IOUtils;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.util.Map;
 
 import de.luhmer.owncloud.accountimporter.helper.InputStreamBinder;
-import de.luhmer.owncloud.accountimporter.helper.NextcloudRequest;
 
 public class AccountManagerService extends Service {
 
+    private InputStreamBinder mBinder;
+
     @Override
     public IBinder onBind(Intent intent) {
-        return (new InputStreamBinder(this));
+        if(mBinder == null) {
+            mBinder = new InputStreamBinder(this);
+        }
+        return mBinder;
+    }
+
+    @Override
+    public boolean onUnbind(Intent intent) {
+        return super.onUnbind(intent);
     }
 
 }

+ 10 - 1
src/main/java/de/luhmer/owncloud/accountimporter/helper/InputStreamBinder.java

@@ -111,15 +111,24 @@ public class InputStreamBinder extends IInputStreamService.Stub {
         OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
         OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context);
 
+
+        if(!client.getCredentials().getAuthToken().equals(request.token)) {
+            throw new IllegalStateException("Provided authentication token does not match!");
+        }
+
         //OwnCloudVersion version = AccountUtils.getServerVersion(account);
         //client.setOwnCloudVersion(version);
 
+        if(!request.url.startsWith("/")) {
+            throw new IllegalStateException("URL need to start with a /");
+        }
+
         // TODO do some checks if url is correct!! (prevent ../ in url etc..
         request.url = client.getBaseUri() + request.url;
 
         //AccountManagerService.INetworkInterface network = (stream) ? new AccountManagerService.StreamingRequest(port) : new AccountManagerService.PlainRequest();
 
-        HttpMethodBase method = null;
+        HttpMethodBase method;
 
         switch (request.method) {
             case "GET":