Search in sources :

Example 1 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 testToClientTime.

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

        @Override
        public long getSkewMillis() {
            return 42L;
        }
    };
    assertEquals(67932L, clockSkewManager.toClientTime(67890).getTime());
}
Also used : ClockSkewManager(com.microsoft.identity.common.internal.util.ClockSkewManager) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) Test(org.junit.Test)

Example 2 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 testGetReferenceTime.

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

        @Override
        public Date getCurrentClientTime() {
            return new Date(67890);
        }

        @Override
        public long getSkewMillis() {
            return 42L;
        }
    };
    assertEquals(67848L, clockSkewManager.getAdjustedReferenceTime().getTime());
}
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 3 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 testToReferenceTime.

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

        @Override
        public long getSkewMillis() {
            return 42L;
        }
    };
    assertEquals(67848L, clockSkewManager.toReferenceTime(67890).getTime());
}
Also used : ClockSkewManager(com.microsoft.identity.common.internal.util.ClockSkewManager) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) Test(org.junit.Test)

Example 4 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 testOnTimestampReceived.

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

        @Override
        public Date getCurrentClientTime() {
            return new Date(12345);
        }
    };
    final Date serverTime = new Date(67890);
    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 5 with ClockSkewManager

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

the class MsalBrokerRequestAdapter method getAuthenticationScheme.

@NonNull
private static AbstractAuthenticationScheme getAuthenticationScheme(@NonNull final Context context, @NonNull final BrokerRequest request) {
    final AbstractAuthenticationScheme requestScheme = request.getAuthenticationScheme();
    if (null == requestScheme) {
        // Default assumes the scheme is Bearer
        return new BearerAuthenticationSchemeInternal();
    } else {
        if (requestScheme instanceof PopAuthenticationSchemeInternal) {
            final IClockSkewManager clockSkewManager = new ClockSkewManager(context);
            ((PopAuthenticationSchemeInternal) requestScheme).setClockSkewManager(clockSkewManager);
        }
        return requestScheme;
    }
}
Also used : AbstractAuthenticationScheme(com.microsoft.identity.common.internal.authscheme.AbstractAuthenticationScheme) BearerAuthenticationSchemeInternal(com.microsoft.identity.common.internal.authscheme.BearerAuthenticationSchemeInternal) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) ClockSkewManager(com.microsoft.identity.common.internal.util.ClockSkewManager) PopAuthenticationSchemeInternal(com.microsoft.identity.common.internal.authscheme.PopAuthenticationSchemeInternal) NonNull(androidx.annotation.NonNull)

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