Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 481bb81

Browse files
authored
Feat/fido workaround (#1065)
* Updated okta libraries, ignore fido The auth library doesn't know about FIDO, so it fails to deal with it. We'll skip that until we can use the different library. * Fixed tests * Added tests for factor skipping methods * Fix check order for shouldSkip * Reverted node changes Co-authored-by: Shawn Sherwood <shawn-sher@users.noreply.github.com>
1 parent 6ade2c6 commit 481bb81

4 files changed

Lines changed: 80 additions & 1 deletion

File tree

cerberus-auth-connector-okta/src/main/java/com/nike/cerberus/auth/connector/okta/statehandlers/AbstractOktaStateHandler.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ public boolean isTriggerRequired(Factor factor) {
135135
return false;
136136
}
137137

138+
/**
139+
* Determines whether the factor is a FIDO type, which the okta.auth.sdk cannot handle
140+
*
141+
* @param factor Okta MFA factor
142+
* @return boolean trigger required
143+
*/
144+
public boolean isFido(Factor factor) {
145+
return factor.getVendorName().equals("FIDO");
146+
}
147+
138148
/**
139149
* Determines whether a trigger is required for a provided MFA factor
140150
*
@@ -149,6 +159,16 @@ public boolean isPush(Factor factor) {
149159
return (provider.equals(FactorProvider.OKTA) && type == FactorType.PUSH);
150160
}
151161

162+
/**
163+
* Determines whether a trigger is required for a provided MFA factor
164+
*
165+
* @param factor Okta MFA factor
166+
* @return boolean trigger required
167+
*/
168+
public boolean shouldSkip(Factor factor) {
169+
return isFido(factor) || isPush(factor);
170+
}
171+
152172
/**
153173
* Ensure the user has at least one active MFA device set up
154174
*

cerberus-auth-connector-okta/src/main/java/com/nike/cerberus/auth/connector/okta/statehandlers/InitialLoginStateHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void handleMfaResponse(AuthenticationResponse mfaResponse) {
7272

7373
final List<Factor> factors = new ArrayList<>(mfaResponse.getFactors());
7474

75-
factors.removeIf(this::isPush);
75+
factors.removeIf(this::shouldSkip);
7676

7777
validateUserFactors(factors);
7878

cerberus-auth-connector-okta/src/test/java/com/nike/cerberus/auth/connector/okta/AbstractOktaStateHandlerTest.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static groovy.test.GroovyTestCase.assertEquals;
2020
import static org.mockito.Mockito.mock;
21+
import static org.mockito.Mockito.times;
22+
import static org.mockito.Mockito.verify;
2123
import static org.mockito.Mockito.when;
2224
import static org.mockito.MockitoAnnotations.initMocks;
2325

@@ -241,4 +243,59 @@ public void handleUnknownPasswordExpired() {
241243

242244
abstractOktaStateHandler.handleUnknown(unknownResponse);
243245
}
246+
247+
@Test
248+
public void testIsFido() {
249+
DefaultFactor nonFidoFactor = mock(DefaultFactor.class);
250+
when(nonFidoFactor.getVendorName()).thenReturn("Okta");
251+
Assert.assertFalse(abstractOktaStateHandler.isFido(nonFidoFactor));
252+
253+
DefaultFactor fidoFactor = mock(DefaultFactor.class);
254+
when(fidoFactor.getVendorName()).thenReturn("FIDO");
255+
Assert.assertTrue(abstractOktaStateHandler.isFido(fidoFactor));
256+
}
257+
258+
@Test
259+
public void testIsPush() {
260+
DefaultFactor nonPushFactor = mock(DefaultFactor.class);
261+
when(nonPushFactor.getVendorName()).thenReturn("Okta");
262+
when(nonPushFactor.getProvider()).thenReturn(FactorProvider.OKTA);
263+
when(nonPushFactor.getType()).thenReturn(FactorType.TOKEN_SOFTWARE_TOTP);
264+
265+
Assert.assertFalse(abstractOktaStateHandler.isPush(nonPushFactor));
266+
267+
DefaultFactor pushFactor = mock(DefaultFactor.class);
268+
when(pushFactor.getVendorName()).thenReturn("Okta");
269+
when(pushFactor.getProvider()).thenReturn(FactorProvider.OKTA);
270+
when(pushFactor.getType()).thenReturn(FactorType.PUSH);
271+
272+
Assert.assertTrue(abstractOktaStateHandler.isPush(pushFactor));
273+
}
274+
275+
@Test
276+
public void testShouldSkip() {
277+
DefaultFactor nonSkipFactor = mock(DefaultFactor.class);
278+
when(nonSkipFactor.getVendorName()).thenReturn("Okta");
279+
when(nonSkipFactor.getProvider()).thenReturn(FactorProvider.OKTA);
280+
when(nonSkipFactor.getType()).thenReturn(FactorType.TOKEN_SOFTWARE_TOTP);
281+
282+
Assert.assertFalse(abstractOktaStateHandler.shouldSkip(nonSkipFactor));
283+
284+
DefaultFactor pushFactor = mock(DefaultFactor.class);
285+
when(pushFactor.getVendorName()).thenReturn("Okta");
286+
when(pushFactor.getProvider()).thenReturn(FactorProvider.OKTA);
287+
when(pushFactor.getType()).thenReturn(FactorType.PUSH);
288+
289+
Assert.assertTrue(abstractOktaStateHandler.isPush(pushFactor));
290+
Assert.assertTrue(abstractOktaStateHandler.shouldSkip(pushFactor));
291+
292+
DefaultFactor fidoFactor = mock(DefaultFactor.class);
293+
when(fidoFactor.getVendorName()).thenReturn("FIDO");
294+
when(fidoFactor.getProvider()).thenReturn(FactorProvider.OKTA);
295+
when(fidoFactor.getType()).thenReturn(FactorType.TOKEN_SOFTWARE_TOTP);
296+
297+
Assert.assertTrue(abstractOktaStateHandler.isFido(fidoFactor));
298+
Assert.assertTrue(abstractOktaStateHandler.shouldSkip(fidoFactor));
299+
verify(fidoFactor, times(0)).getProvider();
300+
}
244301
}

cerberus-auth-connector-okta/src/test/java/com/nike/cerberus/auth/connector/okta/InitialLoginStateHandlerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public void handleMfaRequired() throws Exception {
8787
when(factor.getProvider()).thenReturn(provider);
8888
when(factor.getStatus()).thenReturn(status);
8989
when(factor.getId()).thenReturn(deviceId);
90+
when(factor.getVendorName()).thenReturn("OKTA");
9091
when(expectedResponse.getFactors()).thenReturn(Lists.newArrayList(factor));
9192

9293
// do the call
@@ -125,6 +126,7 @@ public void handleMfaEnroll() throws Exception {
125126
when(factor.getProvider()).thenReturn(provider);
126127
when(factor.getStatus()).thenReturn(status);
127128
when(factor.getId()).thenReturn(deviceId);
129+
when(factor.getVendorName()).thenReturn("OKTA");
128130
when(expectedResponse.getFactors()).thenReturn(Lists.newArrayList(factor));
129131

130132
// do the call

0 commit comments

Comments
 (0)