Skip to content

Commit 739b125

Browse files
authored
Merge pull request #76 from cslzchen/feature/customized-errors
[Institution Rework] [ENG-4205] Customize Exception Handling
2 parents ea1a469 + 2c7be1b commit 739b125

21 files changed

Lines changed: 540 additions & 122 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.cos.cas.osf.authentication.exception;
2+
3+
import lombok.NoArgsConstructor;
4+
5+
import javax.security.auth.login.AccountException;
6+
7+
/**
8+
* Describes an authentication error condition where institution SSO has failed
9+
* due to the OSF account is not active or not eligible for activation.
10+
*
11+
* @author Longze Chen
12+
* @since 23.1.0
13+
*/
14+
@NoArgsConstructor
15+
public class InstitutionSsoAccountInactiveException extends AccountException {
16+
17+
/**
18+
* Serialization metadata.
19+
*/
20+
private static final long serialVersionUID = -430454081442388569L;
21+
22+
/**
23+
* Instantiates a new {@link InstitutionSsoAccountInactiveException}.
24+
*
25+
* @param msg the msg
26+
*/
27+
public InstitutionSsoAccountInactiveException(final String msg) {
28+
super(msg);
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.cos.cas.osf.authentication.exception;
2+
3+
import lombok.NoArgsConstructor;
4+
5+
import javax.security.auth.login.AccountException;
6+
7+
/**
8+
* Describes an authentication error condition where institution SSO has failed
9+
* due to missing required attributes from IdP.
10+
*
11+
* @author Longze Chen
12+
* @since 23.1.0
13+
*/
14+
@NoArgsConstructor
15+
public class InstitutionSsoAttributeMissingException extends AccountException {
16+
17+
/**
18+
* Serialization metadata.
19+
*/
20+
private static final long serialVersionUID = 1412743002614665584L;
21+
22+
/**
23+
* Instantiates a new {@link InstitutionSsoAttributeMissingException}.
24+
*
25+
* @param msg the msg
26+
*/
27+
public InstitutionSsoAttributeMissingException(final String msg) {
28+
super(msg);
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.cos.cas.osf.authentication.exception;
2+
3+
import lombok.NoArgsConstructor;
4+
5+
import javax.security.auth.login.AccountException;
6+
7+
/**
8+
* Describes an authentication error condition where institution SSO has failed
9+
* due to attribute normalization or parsing failure.
10+
*
11+
* @author Longze Chen
12+
* @since 23.1.0
13+
*/
14+
@NoArgsConstructor
15+
public class InstitutionSsoAttributeParsingException extends AccountException {
16+
17+
/**
18+
* Serialization metadata.
19+
*/
20+
private static final long serialVersionUID = 4319114898092268727L;
21+
22+
/**
23+
* Instantiates a new {@link InstitutionSsoAttributeParsingException}.
24+
*
25+
* @param msg the msg
26+
*/
27+
public InstitutionSsoAttributeParsingException(final String msg) {
28+
super(msg);
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.cos.cas.osf.authentication.exception;
2+
3+
import lombok.NoArgsConstructor;
4+
5+
import javax.security.auth.login.AccountException;
6+
7+
/**
8+
* Describes an authentication error condition where institution SSO has failed
9+
* due to duplicate SSO identity.
10+
*
11+
* @author Longze Chen
12+
* @since 23.1.0
13+
*/
14+
@NoArgsConstructor
15+
public class InstitutionSsoDuplicateIdentityException extends AccountException {
16+
17+
/**
18+
* Serialization metadata.
19+
*/
20+
private static final long serialVersionUID = 1412743002614665584L;
21+
22+
/**
23+
* Instantiates a new {@link InstitutionSsoDuplicateIdentityException}.
24+
*
25+
* @param msg the msg
26+
*/
27+
public InstitutionSsoDuplicateIdentityException(final String msg) {
28+
super(msg);
29+
}
30+
}

src/main/java/io/cos/cas/osf/authentication/exception/InstitutionSsoFailedException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import javax.security.auth.login.AccountException;
66

77
/**
8-
* Describes an authentication error condition where institution SSO has failed.
8+
* Describes an authentication error condition where institution SSO has failed
9+
* in a way that doesn't fit into any specific exception.
910
*
1011
* @author Longze Chen
1112
* @since 21.0.0

src/main/java/io/cos/cas/osf/authentication/exception/InstitutionSsoOsfApiFailureException.java renamed to src/main/java/io/cos/cas/osf/authentication/exception/InstitutionSsoOsfApiFailedException.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
import javax.security.auth.login.AccountException;
66

77
/**
8-
* Describes an authentication error condition when connection failures and/or server errors happen between
9-
* CAS and OSF API during institution SSO.
8+
* Describes an authentication error condition when connection failures and/or server errors happen
9+
* between CAS and OSF API during institution SSO.
1010
*
1111
* @author Longze Chen
1212
* @since 22.1.3
1313
*/
1414
@NoArgsConstructor
15-
public class InstitutionSsoOsfApiFailureException extends AccountException {
15+
public class InstitutionSsoOsfApiFailedException extends AccountException {
1616

1717
/**
1818
* Serialization metadata.
1919
*/
2020
private static final long serialVersionUID = -620313210360224932L;
2121

2222
/**
23-
* Instantiates a new {@link InstitutionSsoOsfApiFailureException}.
23+
* Instantiates a new {@link InstitutionSsoOsfApiFailedException}.
2424
*
2525
* @param msg the msg
2626
*/
27-
public InstitutionSsoOsfApiFailureException(final String msg) {
27+
public InstitutionSsoOsfApiFailedException(final String msg) {
2828
super(msg);
2929
}
3030
}

src/main/java/io/cos/cas/osf/authentication/exception/InstitutionSelectiveSsoFailedException.java renamed to src/main/java/io/cos/cas/osf/authentication/exception/InstitutionSsoSelectiveLoginDeniedException.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@
55
import javax.security.auth.login.AccountException;
66

77
/**
8-
* Describes an authentication error condition where user is not allowed to access OSF via institution SSO.
8+
* Describes an authentication error condition where user is not allowed to access OSF
9+
* via institution SSO due to Selective SSO rules.
910
*
1011
* @author Longze Chen
1112
* @since 22.0.1
1213
*/
1314
@NoArgsConstructor
14-
public class InstitutionSelectiveSsoFailedException extends AccountException {
15+
public class InstitutionSsoSelectiveLoginDeniedException extends AccountException {
1516

1617
/**
1718
* Serialization metadata.
1819
*/
1920
private static final long serialVersionUID = -7613915260905373074L;
2021

2122
/**
22-
* Instantiates a new {@link InstitutionSelectiveSsoFailedException}.
23+
* Instantiates a new {@link InstitutionSsoSelectiveLoginDeniedException}.
2324
*
2425
* @param msg the msg
2526
*/
26-
public InstitutionSelectiveSsoFailedException(final String msg) {
27+
public InstitutionSsoSelectiveLoginDeniedException(final String msg) {
2728
super(msg);
2829
}
2930
}

src/main/java/io/cos/cas/osf/authentication/support/OsfApiPermissionDenied.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ public enum OsfApiPermissionDenied {
1010

1111
DEFAULT("PermissionDenied"),
1212

13-
INSTITUTION_SELECTIVE_SSO_FAILURE("InstitutionSsoSelectiveNotAllowed");
13+
INSTITUTION_SSO_DUPLICATE_IDENTITY("InstitutionSsoDuplicateIdentity"),
14+
15+
INSTITUTION_SSO_ACCOUNT_INACTIVE("InstitutionSsoAccountInactive"),
16+
17+
INSTITUTION_SSO_SELECTIVE_LOGIN_DENIED("InstitutionSsoSelectiveLoginDenied");
1418

1519
private final String id;
1620

src/main/java/io/cos/cas/osf/web/flow/config/OsfCasCoreWebflowConfiguration.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import io.cos.cas.osf.authentication.exception.AccountNotConfirmedIdpException;
44
import io.cos.cas.osf.authentication.exception.AccountNotConfirmedOsfException;
5-
import io.cos.cas.osf.authentication.exception.InstitutionSelectiveSsoFailedException;
6-
import io.cos.cas.osf.authentication.exception.InstitutionSsoOsfApiFailureException;
5+
import io.cos.cas.osf.authentication.exception.InstitutionSsoAccountInactiveException;
6+
import io.cos.cas.osf.authentication.exception.InstitutionSsoAttributeMissingException;
7+
import io.cos.cas.osf.authentication.exception.InstitutionSsoAttributeParsingException;
8+
import io.cos.cas.osf.authentication.exception.InstitutionSsoDuplicateIdentityException;
79
import io.cos.cas.osf.authentication.exception.InstitutionSsoFailedException;
10+
import io.cos.cas.osf.authentication.exception.InstitutionSsoOsfApiFailedException;
11+
import io.cos.cas.osf.authentication.exception.InstitutionSsoSelectiveLoginDeniedException;
812
import io.cos.cas.osf.authentication.exception.InvalidOneTimePasswordException;
913
import io.cos.cas.osf.authentication.exception.InvalidPasswordException;
1014
import io.cos.cas.osf.authentication.exception.InvalidUserStatusException;
@@ -44,14 +48,18 @@ public Set<Class<? extends Throwable>> handledAuthenticationExceptions() {
4448
Set<Class<? extends Throwable>> errors = new LinkedHashSet<>();
4549
errors.add(AccountNotConfirmedIdpException.class);
4650
errors.add(AccountNotConfirmedOsfException.class);
47-
errors.add(InvalidOneTimePasswordException.class);
51+
errors.add(InstitutionSsoAccountInactiveException.class);
52+
errors.add(InstitutionSsoAttributeMissingException.class);
53+
errors.add(InstitutionSsoAttributeParsingException.class);
54+
errors.add(InstitutionSsoDuplicateIdentityException.class);
4855
errors.add(InstitutionSsoFailedException.class);
56+
errors.add(InstitutionSsoOsfApiFailedException.class);
57+
errors.add(InstitutionSsoSelectiveLoginDeniedException.class);
58+
errors.add(InvalidOneTimePasswordException.class);
4959
errors.add(InvalidPasswordException.class);
5060
errors.add(InvalidUserStatusException.class);
5161
errors.add(InvalidVerificationKeyException.class);
5262
errors.add(OneTimePasswordRequiredException.class);
53-
errors.add(InstitutionSelectiveSsoFailedException.class);
54-
errors.add(InstitutionSsoOsfApiFailureException.class);
5563
errors.add(TermsOfServiceConsentRequiredException.class);
5664

5765
// Add built-in exceptions after OSF-specific exceptions since order matters

src/main/java/io/cos/cas/osf/web/flow/configurer/OsfCasLoginWebflowConfigurer.java

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import io.cos.cas.osf.authentication.credential.OsfPostgresCredential;
44
import io.cos.cas.osf.authentication.exception.AccountNotConfirmedIdpException;
55
import io.cos.cas.osf.authentication.exception.AccountNotConfirmedOsfException;
6-
import io.cos.cas.osf.authentication.exception.InstitutionSelectiveSsoFailedException;
7-
import io.cos.cas.osf.authentication.exception.InstitutionSsoOsfApiFailureException;
6+
import io.cos.cas.osf.authentication.exception.InstitutionSsoAccountInactiveException;
7+
import io.cos.cas.osf.authentication.exception.InstitutionSsoAttributeMissingException;
8+
import io.cos.cas.osf.authentication.exception.InstitutionSsoAttributeParsingException;
9+
import io.cos.cas.osf.authentication.exception.InstitutionSsoDuplicateIdentityException;
810
import io.cos.cas.osf.authentication.exception.InstitutionSsoFailedException;
11+
import io.cos.cas.osf.authentication.exception.InstitutionSsoOsfApiFailedException;
12+
import io.cos.cas.osf.authentication.exception.InstitutionSsoSelectiveLoginDeniedException;
913
import io.cos.cas.osf.authentication.exception.InvalidOneTimePasswordException;
1014
import io.cos.cas.osf.authentication.exception.InvalidUserStatusException;
1115
import io.cos.cas.osf.authentication.exception.InvalidVerificationKeyException;
@@ -231,6 +235,41 @@ protected void createHandleAuthenticationFailureAction(final Flow flow) {
231235
AccountNotConfirmedOsfException.class.getSimpleName(),
232236
OsfCasWebflowConstants.VIEW_ID_ACCOUNT_NOT_CONFIRMED_OSF
233237
);
238+
createTransitionForState(
239+
handler,
240+
InstitutionSsoAccountInactiveException.class.getSimpleName(),
241+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_ACCOUNT_INACTIVE
242+
);
243+
createTransitionForState(
244+
handler,
245+
InstitutionSsoAttributeMissingException.class.getSimpleName(),
246+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_ATTRIBUTE_MISSING
247+
);
248+
createTransitionForState(
249+
handler,
250+
InstitutionSsoAttributeParsingException.class.getSimpleName(),
251+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_ATTRIBUTE_PARSING_FAILED
252+
);
253+
createTransitionForState(
254+
handler,
255+
InstitutionSsoDuplicateIdentityException.class.getSimpleName(),
256+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_DUPLICATE_IDENTITY
257+
);
258+
createTransitionForState(
259+
handler,
260+
InstitutionSsoFailedException.class.getSimpleName(),
261+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_FAILED
262+
);
263+
createTransitionForState(
264+
handler,
265+
InstitutionSsoOsfApiFailedException.class.getSimpleName(),
266+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_OSF_API_FAILED
267+
);
268+
createTransitionForState(
269+
handler,
270+
InstitutionSsoSelectiveLoginDeniedException.class.getSimpleName(),
271+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_SELECTIVE_LOGIN_DENIED
272+
);
234273
createTransitionForState(
235274
handler,
236275
InvalidUserStatusException.class.getSimpleName(),
@@ -256,21 +295,6 @@ protected void createHandleAuthenticationFailureAction(final Flow flow) {
256295
TermsOfServiceConsentRequiredException.class.getSimpleName(),
257296
OsfCasWebflowConstants.VIEW_ID_TERMS_OF_SERVICE_CONSENT_REQUIRED
258297
);
259-
createTransitionForState(
260-
handler,
261-
InstitutionSsoFailedException.class.getSimpleName(),
262-
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_FAILED
263-
);
264-
createTransitionForState(
265-
handler,
266-
InstitutionSelectiveSsoFailedException.class.getSimpleName(),
267-
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SELECTIVE_SSO_FAILED
268-
);
269-
createTransitionForState(
270-
handler,
271-
InstitutionSsoOsfApiFailureException.class.getSimpleName(),
272-
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_OSF_API_FAILURE
273-
);
274298

275299
// The default transition
276300
createStateDefaultTransition(handler, CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM);
@@ -411,20 +435,40 @@ private void createOsfCasAuthenticationExceptionViewStates(final Flow flow) {
411435
OsfCasWebflowConstants.VIEW_ID_INVALID_VERIFICATION_KEY,
412436
OsfCasWebflowConstants.VIEW_ID_INVALID_VERIFICATION_KEY
413437
);
438+
createViewState(
439+
flow,
440+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_ACCOUNT_INACTIVE,
441+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_ACCOUNT_INACTIVE
442+
);
443+
createViewState(
444+
flow,
445+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_ATTRIBUTE_MISSING,
446+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_ATTRIBUTE_MISSING
447+
);
448+
createViewState(
449+
flow,
450+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_ATTRIBUTE_PARSING_FAILED,
451+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_ATTRIBUTE_PARSING_FAILED
452+
);
453+
createViewState(
454+
flow,
455+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_DUPLICATE_IDENTITY,
456+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_DUPLICATE_IDENTITY
457+
);
414458
createViewState(
415459
flow,
416460
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_FAILED,
417461
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_FAILED
418462
);
419463
createViewState(
420464
flow,
421-
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SELECTIVE_SSO_FAILED,
422-
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SELECTIVE_SSO_FAILED
465+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_OSF_API_FAILED,
466+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_OSF_API_FAILED
423467
);
424468
createViewState(
425469
flow,
426-
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_OSF_API_FAILURE,
427-
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_OSF_API_FAILURE
470+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_SELECTIVE_LOGIN_DENIED,
471+
OsfCasWebflowConstants.VIEW_ID_INSTITUTION_SSO_SELECTIVE_LOGIN_DENIED
428472
);
429473
}
430474

0 commit comments

Comments
 (0)