Search in sources :

Example 6 with ClockSkewManager

use of com.microsoft.identity.common.internal.util.ClockSkewManager in project microsoft-authentication-library-common-for-android by AzureAD.

the class ClockSkewManagerTest method testOnTimestampReceived2.

@Test
public void testOnTimestampReceived2() {
    clockSkewManager = new ClockSkewManager(context) {

        @Override
        public Date getCurrentClientTime() {
            return new Date(67890);
        }
    };
    final Date serverTime = new Date(12345);
    clockSkewManager.onTimestampReceived(serverTime.getTime());
    assertEquals(55545, clockSkewManager.getSkewMillis());
}
Also used : ClockSkewManager(com.microsoft.identity.common.internal.util.ClockSkewManager) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) Date(java.util.Date) Test(org.junit.Test)

Example 7 with ClockSkewManager

use of com.microsoft.identity.common.internal.util.ClockSkewManager in project microsoft-authentication-library-common-for-android by AzureAD.

the class LocalMSALController method generateSignedHttpRequest.

@Override
public GenerateShrResult generateSignedHttpRequest(@NonNull final GenerateShrCommandParameters parameters) throws Exception {
    final Context context = parameters.getAndroidApplicationContext();
    final IClockSkewManager clockSkewManager = new ClockSkewManager(context);
    final OAuth2TokenCache cache = parameters.getOAuth2TokenCache();
    final String clientId = parameters.getClientId();
    final String homeAccountId = parameters.getHomeAccountId();
    final IPoPAuthenticationSchemeParams popSchemeParams = parameters.getPopParameters();
    final GenerateShrResult result;
    if (userHasLocalAccountRecord(cache, clientId, homeAccountId)) {
        // Perform the signing locally...
        result = DevicePoPUtils.generateSignedHttpRequest(context, clockSkewManager, popSchemeParams);
    } else {
        // Populate the error on the result and return...
        result = new GenerateShrResult();
        result.setErrorCode(GenerateShrResult.Errors.NO_ACCOUNT_FOUND);
        result.setErrorMessage("Account does not exist.");
    }
    return result;
}
Also used : Context(android.content.Context) OAuth2TokenCache(com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache) GenerateShrResult(com.microsoft.identity.common.internal.result.GenerateShrResult) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) ClockSkewManager(com.microsoft.identity.common.internal.util.ClockSkewManager) IPoPAuthenticationSchemeParams(com.microsoft.identity.common.internal.authscheme.IPoPAuthenticationSchemeParams)

Example 8 with ClockSkewManager

use of com.microsoft.identity.common.internal.util.ClockSkewManager in project microsoft-authentication-library-common-for-android by AzureAD.

the class AuthenticationSchemeFactory method createScheme.

/**
 * Gets the internal scheme equivalent for the provided public api scheme.
 *
 * @param nameable The nameable public scheme representation.
 * @return The internal scheme representation.
 */
public static AbstractAuthenticationScheme createScheme(@NonNull final Context context, @Nullable final INameable nameable) {
    if (null == nameable) {
        // If null, choose Bearer for backcompat
        return new BearerAuthenticationSchemeInternal();
    }
    switch(nameable.getName()) {
        case BearerAuthenticationSchemeInternal.SCHEME_BEARER:
            Logger.verbose(TAG, "Constructing Bearer Authentication Scheme.");
            return new BearerAuthenticationSchemeInternal();
        case PopAuthenticationSchemeInternal.SCHEME_POP:
            if (nameable instanceof IPoPAuthenticationSchemeParams) {
                Logger.verbose(TAG, "Constructing PoP Authentication Scheme.");
                final IPoPAuthenticationSchemeParams params = (IPoPAuthenticationSchemeParams) nameable;
                final IClockSkewManager clockSkewManager = new ClockSkewManager(context);
                return new PopAuthenticationSchemeInternal(clockSkewManager, params.getHttpMethod(), params.getUrl(), params.getNonce(), params.getClientClaims());
            } else {
                throw new IllegalStateException("Unrecognized parameter type.");
            }
        default:
            throw new UnsupportedOperationException("Unknown or unsupported scheme: " + nameable.getName());
    }
}
Also used : IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) ClockSkewManager(com.microsoft.identity.common.internal.util.ClockSkewManager) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager)

Aggregations

ClockSkewManager (com.microsoft.identity.common.internal.util.ClockSkewManager)8 IClockSkewManager (com.microsoft.identity.common.internal.util.IClockSkewManager)8 Test (org.junit.Test)5 Date (java.util.Date)3 Context (android.content.Context)1 NonNull (androidx.annotation.NonNull)1 AbstractAuthenticationScheme (com.microsoft.identity.common.internal.authscheme.AbstractAuthenticationScheme)1 BearerAuthenticationSchemeInternal (com.microsoft.identity.common.internal.authscheme.BearerAuthenticationSchemeInternal)1 IPoPAuthenticationSchemeParams (com.microsoft.identity.common.internal.authscheme.IPoPAuthenticationSchemeParams)1 PopAuthenticationSchemeInternal (com.microsoft.identity.common.internal.authscheme.PopAuthenticationSchemeInternal)1 OAuth2TokenCache (com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache)1 GenerateShrResult (com.microsoft.identity.common.internal.result.GenerateShrResult)1