mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	make saml work with new library
This commit is contained in:
		
							parent
							
								
									e261b1df2f
								
							
						
					
					
						commit
						804b31da39
					
				| @ -27,7 +27,9 @@ import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| import com.owncloud.android.lib.common.http.HttpClient; | ||||
| import com.owncloud.android.lib.common.http.interceptors.BarearAuthInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.BasicAuthInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor.RequestInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.SamlAuthInterceptor; | ||||
| 
 | ||||
| import org.apache.commons.httpclient.UsernamePasswordCredentials; | ||||
| import org.apache.commons.httpclient.auth.AuthPolicy; | ||||
| @ -68,11 +70,10 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials { | ||||
|         ArrayList<RequestInterceptor> requestInterceptors = HttpClient.getOkHttpInterceptor().getRequestInterceptors(); | ||||
| 
 | ||||
|         // Clear previous basic credentials | ||||
|         for (RequestInterceptor requestInterceptor : requestInterceptors) { | ||||
|             if (requestInterceptor instanceof BasicAuthInterceptor) { | ||||
|                 requestInterceptors.remove(requestInterceptor); | ||||
|             } | ||||
|             if(requestInterceptor instanceof BarearAuthInterceptor) { | ||||
|         for (HttpInterceptor.RequestInterceptor requestInterceptor : requestInterceptors) { | ||||
|             if (requestInterceptor instanceof BasicAuthInterceptor | ||||
|                     || requestInterceptor instanceof BarearAuthInterceptor | ||||
|                     || requestInterceptor instanceof SamlAuthInterceptor) { | ||||
|                 requestInterceptors.remove(requestInterceptor); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -39,6 +39,7 @@ import com.owncloud.android.lib.common.http.HttpClient; | ||||
| import com.owncloud.android.lib.common.http.interceptors.BarearAuthInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.BasicAuthInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.SamlAuthInterceptor; | ||||
| 
 | ||||
| public class OwnCloudBearerCredentials implements OwnCloudCredentials { | ||||
| 
 | ||||
| @ -60,11 +61,10 @@ public class OwnCloudBearerCredentials implements OwnCloudCredentials { | ||||
| 
 | ||||
|         // Clear previous basic credentials | ||||
|         for (HttpInterceptor.RequestInterceptor requestInterceptor : requestInterceptors) { | ||||
|             if (requestInterceptor instanceof BasicAuthInterceptor) { | ||||
|                 requestInterceptors.remove(requestInterceptor); | ||||
|             } | ||||
|             if(requestInterceptor instanceof BarearAuthInterceptor) { | ||||
|                 requestInterceptors.remove(requestInterceptor); | ||||
|             if (requestInterceptor instanceof BasicAuthInterceptor | ||||
|                 || requestInterceptor instanceof BarearAuthInterceptor | ||||
|                 || requestInterceptor instanceof SamlAuthInterceptor) { | ||||
|                     requestInterceptors.remove(requestInterceptor); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  | ||||
| @ -23,12 +23,20 @@ | ||||
|  */ | ||||
| package com.owncloud.android.lib.common.authentication; | ||||
| 
 | ||||
| import org.apache.commons.httpclient.Cookie; | ||||
| import org.apache.commons.httpclient.cookie.CookiePolicy; | ||||
| 
 | ||||
| import android.net.Uri; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| import com.owncloud.android.lib.common.http.HttpClient; | ||||
| import com.owncloud.android.lib.common.http.interceptors.BarearAuthInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.BasicAuthInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor; | ||||
| import com.owncloud.android.lib.common.http.interceptors.SamlAuthInterceptor; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import okhttp3.Cookie; | ||||
| 
 | ||||
| public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials { | ||||
| 
 | ||||
| @ -46,26 +54,20 @@ public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials { | ||||
|         client.getParams().setCredentialCharset(OwnCloudCredentialsFactory.CREDENTIAL_CHARSET); | ||||
|         client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); | ||||
| 
 | ||||
|         // TODO | ||||
| //        client.setFollowRedirects(false); | ||||
|         final ArrayList<HttpInterceptor.RequestInterceptor> requestInterceptors = | ||||
|                 HttpClient.getOkHttpInterceptor().getRequestInterceptors(); | ||||
| 
 | ||||
|         Uri serverUri = client.getBaseUri(); | ||||
| 
 | ||||
|         String[] cookies = mSessionCookie.split(";"); | ||||
|         if (cookies.length > 0) { | ||||
|             Cookie cookie = null; | ||||
|             for (int i = 0; i < cookies.length; i++) { | ||||
|                 int equalPos = cookies[i].indexOf('='); | ||||
|                 if (equalPos >= 0) { | ||||
|                     cookie = new Cookie(); | ||||
|                     cookie.setName(cookies[i].substring(0, equalPos)); | ||||
|                     cookie.setValue(cookies[i].substring(equalPos + 1)); | ||||
|                     cookie.setDomain(serverUri.getHost());    // VERY IMPORTANT | ||||
|                     cookie.setPath(serverUri.getPath());    // VERY IMPORTANT | ||||
|                     client.getState().addCookie(cookie); | ||||
|                 } | ||||
|         // Clear previous basic credentials | ||||
|         for (HttpInterceptor.RequestInterceptor requestInterceptor : requestInterceptors) { | ||||
|             if (requestInterceptor instanceof BasicAuthInterceptor | ||||
|                     || requestInterceptor instanceof BarearAuthInterceptor | ||||
|                     || requestInterceptor instanceof SamlAuthInterceptor) { | ||||
|                 requestInterceptors.remove(requestInterceptor); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         HttpClient.getOkHttpInterceptor() | ||||
|                 .addRequestInterceptor(new SamlAuthInterceptor(mSessionCookie)); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  | ||||
| @ -0,0 +1,21 @@ | ||||
| package com.owncloud.android.lib.common.http.interceptors; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| 
 | ||||
| import okhttp3.Request; | ||||
| 
 | ||||
| public class SamlAuthInterceptor implements HttpInterceptor.RequestInterceptor { | ||||
| 
 | ||||
|     private final String mSessionCookie; | ||||
| 
 | ||||
|     public SamlAuthInterceptor(String sessionCookie) { | ||||
|         this.mSessionCookie = sessionCookie; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Request intercept(Request request) throws IOException { | ||||
|         return request.newBuilder() | ||||
|                 .addHeader("Cookie", mSessionCookie) | ||||
|                 .build(); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user