diff --git a/sdk/odata-engine-android-impl/build.gradle b/sdk/odata-engine-android-impl/build.gradle index 637b0909..f5a9eb9a 100644 --- a/sdk/odata-engine-android-impl/build.gradle +++ b/sdk/odata-engine-android-impl/build.gradle @@ -27,6 +27,9 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.google.code.gson:gson:2.3' compile project(':odata-engine-core') + compile('com.microsoft.aad:adal:(,2.0)') { + exclude group: 'com.android.support' + } } apply from : '../android-libraries.gradle' \ No newline at end of file diff --git a/sdk/odata-engine-android-impl/src/main/java/com/microsoft/services/odata/impl/DefaultDependencyResolver.java b/sdk/odata-engine-android-impl/src/main/java/com/microsoft/services/odata/impl/DefaultDependencyResolver.java index bb273a9b..342f5b06 100644 --- a/sdk/odata-engine-android-impl/src/main/java/com/microsoft/services/odata/impl/DefaultDependencyResolver.java +++ b/sdk/odata-engine-android-impl/src/main/java/com/microsoft/services/odata/impl/DefaultDependencyResolver.java @@ -5,20 +5,26 @@ import com.microsoft.services.odata.Constants; import com.microsoft.services.odata.impl.http.AndroidHttpTransport; import com.microsoft.services.odata.impl.http.RequestImpl; -import com.microsoft.services.odata.interfaces.*; +import com.microsoft.services.odata.interfaces.Credentials; +import com.microsoft.services.odata.interfaces.DependencyResolver; +import com.microsoft.services.odata.interfaces.HttpTransport; +import com.microsoft.services.odata.interfaces.JsonSerializer; +import com.microsoft.services.odata.interfaces.ODataURL; +import com.microsoft.services.odata.interfaces.Request; /** * The type Default dependency resolver. */ public class DefaultDependencyResolver implements DependencyResolver { - private CredentialsFactory credentialsFactory; private LoggerImpl logger; + private String token; /** * Instantiates a new Default dependency resolver. */ - public DefaultDependencyResolver() { + public DefaultDependencyResolver(String token) { + this.token = token; this.logger = new LoggerImpl(); } @@ -37,11 +43,6 @@ public JsonSerializer getJsonSerializer() { return new GsonSerializer(); } - @Override - public CredentialsFactory getCredentialsFactory() { - return credentialsFactory; - } - @Override public ODataURL createODataURL() { return new ODataURLImpl(); @@ -59,15 +60,15 @@ public String getPlatformUserAgent(String productName) { "%s/1.0 (lang=%s; os=%s; os_version=%s; arch=%s; version=%s)", productName, "Java", "Android", Build.VERSION.RELEASE, Build.CPU_ABI, Constants.SDK_VERSION); - } - /** - * Sets credentials factory. - * - * @param credentialsFactory the credentials factory - */ - public void setCredentialsFactory(CredentialsFactory credentialsFactory) { - this.credentialsFactory = credentialsFactory; + @Override + public Credentials getCredentials() { + return new Credentials() { + @Override + public void prepareRequest(Request request) { + request.addHeader("Authorization", "Bearer " + token); + } + }; } } diff --git a/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/BaseODataContainer.java b/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/BaseODataContainer.java index ded72619..d606f2ef 100755 --- a/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/BaseODataContainer.java +++ b/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/BaseODataContainer.java @@ -10,7 +10,6 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import com.microsoft.services.odata.interfaces.Credentials; -import com.microsoft.services.odata.interfaces.CredentialsFactory; import com.microsoft.services.odata.interfaces.DependencyResolver; import com.microsoft.services.odata.interfaces.HttpTransport; import com.microsoft.services.odata.interfaces.LogLevel; @@ -69,13 +68,10 @@ protected ListenableFuture oDataExecute(Request request) { } boolean credentialsSet = false; - CredentialsFactory credFactory = resolver.getCredentialsFactory(); - if (credFactory != null) { - Credentials cred = credFactory.getCredentials(); - if (cred != null) { - cred.prepareRequest(request); - credentialsSet = true; - } + Credentials cred = resolver.getCredentials(); + if (cred != null) { + cred.prepareRequest(request); + credentialsSet = true; } if (!credentialsSet) { diff --git a/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/impl/http/CredentialsFactoryImpl.java b/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/impl/http/CredentialsFactoryImpl.java deleted file mode 100644 index 273c7da5..00000000 --- a/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/impl/http/CredentialsFactoryImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.microsoft.services.odata.impl.http; - -import com.microsoft.services.odata.interfaces.Credentials; -import com.microsoft.services.odata.interfaces.CredentialsFactory; - -/** - * The type Credentials factory impl. - */ -public class CredentialsFactoryImpl implements CredentialsFactory { - - private Credentials mCredentials; - - @Override - public Credentials getCredentials() { - return mCredentials; - } - - /** - * Set credentials. - * - * @param credentials the credentials - */ - public void setCredentials(Credentials credentials){ - mCredentials = credentials; - } -} diff --git a/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/interfaces/CredentialsFactory.java b/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/interfaces/CredentialsFactory.java deleted file mode 100644 index 78270205..00000000 --- a/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/interfaces/CredentialsFactory.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.microsoft.services.odata.interfaces; - -public interface CredentialsFactory { - public Credentials getCredentials(); -} diff --git a/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/interfaces/DependencyResolver.java b/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/interfaces/DependencyResolver.java index 1eec5f17..90ca4c04 100644 --- a/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/interfaces/DependencyResolver.java +++ b/sdk/odata-engine-core/src/main/java/com/microsoft/services/odata/interfaces/DependencyResolver.java @@ -25,13 +25,6 @@ public interface DependencyResolver { */ JsonSerializer getJsonSerializer(); - /** - * Gets credentials factory. - * - * @return the credentials factory - */ - CredentialsFactory getCredentialsFactory(); - /** * Create o data uRL. * @@ -52,4 +45,11 @@ public interface DependencyResolver { * @return the user agent */ String getPlatformUserAgent(String productName); + + /** + * Gets credentials. + * + * @return the credentials + */ + Credentials getCredentials(); } diff --git a/sdk/odata-engine-jvm-impl/src/main/java/com/microsoft/services/odata/impl/desktop/DesktopDependencyResolver.java b/sdk/odata-engine-jvm-impl/src/main/java/com/microsoft/services/odata/impl/desktop/DesktopDependencyResolver.java deleted file mode 100644 index a928511b..00000000 --- a/sdk/odata-engine-jvm-impl/src/main/java/com/microsoft/services/odata/impl/desktop/DesktopDependencyResolver.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.microsoft.services.odata.impl.desktop; - -import com.microsoft.services.odata.Constants; -import com.microsoft.services.odata.impl.ODataURLImpl; -import com.microsoft.services.odata.impl.desktop.http.DesktopHttpTransport; -import com.microsoft.services.odata.impl.http.RequestImpl; -import com.microsoft.services.odata.interfaces.CredentialsFactory; -import com.microsoft.services.odata.interfaces.DependencyResolver; -import com.microsoft.services.odata.interfaces.HttpTransport; -import com.microsoft.services.odata.interfaces.JsonSerializer; -import com.microsoft.services.odata.interfaces.ODataURL; -import com.microsoft.services.odata.interfaces.Request; - -/** - * The type Default dependency resolver. - */ -public class DesktopDependencyResolver implements DependencyResolver { - - private CredentialsFactory credentialsFactory; - private LoggerImpl logger; - - /** - * Instantiates a new Default dependency resolver. - */ - public DesktopDependencyResolver() { - this.logger = new LoggerImpl(); - } - - @Override - public HttpTransport getHttpTransport() { - return new DesktopHttpTransport(); - } - - @Override - public LoggerImpl getLogger() { - return this.logger; - } - - @Override - public JsonSerializer getJsonSerializer() { - return new GsonSerializer(); - } - - @Override - public CredentialsFactory getCredentialsFactory() { - return credentialsFactory; - } - - @Override - public ODataURL createODataURL() { - return new ODataURLImpl(); - } - - @Override - public Request createRequest() { - return new RequestImpl(); - } - - @Override - public String getPlatformUserAgent(String productName) { - - String osName = System.getProperty("os.name"); - return String.format( - "%s/1.0 (lang=%s; os=%s; version=%s)", - productName, "Java", osName, Constants.SDK_VERSION); - } - - /** - * Sets credentials factory. - * - * @param credentialsFactory the credentials factory - */ - public void setCredentialsFactory(CredentialsFactory credentialsFactory) { - this.credentialsFactory = credentialsFactory; - } -} diff --git a/tests/e2e-test-app/app/src/main/java/com/microsoft/office365/test/integration/android/AndroidTestPlatformContext.java b/tests/e2e-test-app/app/src/main/java/com/microsoft/office365/test/integration/android/AndroidTestPlatformContext.java index 4e7b8beb..4833418f 100644 --- a/tests/e2e-test-app/app/src/main/java/com/microsoft/office365/test/integration/android/AndroidTestPlatformContext.java +++ b/tests/e2e-test-app/app/src/main/java/com/microsoft/office365/test/integration/android/AndroidTestPlatformContext.java @@ -17,13 +17,11 @@ import com.microsoft.discoveryservices.odata.DiscoveryClient; import com.microsoft.listservices.SharepointListsClient; import com.microsoft.office365.test.integration.TestPlatformContext; -import com.microsoft.office365.test.integration.framework.OAuthCredentials; import com.microsoft.office365.test.integration.framework.TestCase; import com.microsoft.office365.test.integration.framework.TestExecutionCallback; import com.microsoft.office365.test.integration.framework.TestResult; import com.microsoft.outlookservices.odata.OutlookClient; import com.microsoft.services.odata.impl.DefaultDependencyResolver; -import com.microsoft.services.odata.impl.http.CredentialsFactoryImpl; import com.microsoft.services.odata.interfaces.DependencyResolver; import com.microsoft.services.odata.interfaces.LogLevel; import com.microsoft.sharepointservices.odata.SharePointClient; @@ -250,7 +248,8 @@ public void onError(Exception exc) { public void onSuccess(AuthenticationResult result) { TClient client = null; try { - client = clientClass.getDeclaredConstructor(String.class, DependencyResolver.class).newInstance(endpointUrl, getDependencyResolver(result.getAccessToken())); + client = clientClass.getDeclaredConstructor(String.class, DependencyResolver.class) + .newInstance(endpointUrl, getDependencyResolver(result.getAccessToken())); future.set(client); } catch (Throwable t) { onError(new Exception(t)); @@ -303,12 +302,8 @@ public void onSuccess(AuthenticationResult result) { } private DependencyResolver getDependencyResolver(final String token) { - OAuthCredentials credentials = new OAuthCredentials(token); - CredentialsFactoryImpl credFactory = new CredentialsFactoryImpl(); - credFactory.setCredentials(credentials); - DefaultDependencyResolver dependencyResolver = new DefaultDependencyResolver(); - dependencyResolver.setCredentialsFactory(credFactory); + DefaultDependencyResolver dependencyResolver = new DefaultDependencyResolver(token); dependencyResolver.getLogger().setEnabled(true); dependencyResolver.getLogger().setLogLevel(LogLevel.VERBOSE);