Skip to content

feat: introduce new exception handling model for Kerberos failures wi…#108

Open
bedrin wants to merge 1 commit into
masterfrom
feature/exceptions
Open

feat: introduce new exception handling model for Kerberos failures wi…#108
bedrin wants to merge 1 commit into
masterfrom
feature/exceptions

Conversation

@bedrin

@bedrin bedrin commented Jun 8, 2026

Copy link
Copy Markdown
Owner

…th diagnostics

…th diagnostics

Signed-off-by: Dmitry Bedrin <dmitry.bedrin@gmail.com>
Copilot AI review requested due to automatic review settings June 8, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new Kerberos failure diagnostic model across Kerb4J, translating provider-specific exceptions (JAAS/JGSS/Kerby) into stable, support-friendly runtime exceptions with machine-readable codes/categories, and propagates those diagnostics through client and Spring server integrations.

Changes:

  • Added KerberosFailureAnalyzer, KerberosDiagnostic, and a taxonomy of failure codes/categories plus typed Kerb4JKerberosException subclasses for consistent classification and troubleshooting output.
  • Introduced “*OrThrow” convenience APIs in SpnegoClient/SpnegoContext and updated server-side Spring components to wrap failures with Kerb4J diagnostics.
  • Added tests for diagnostic classification and documentation describing the new exception/diagnostic contract.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
kerb4j-server/kerb4j-server-spring-security-core/.../SpnegoAuthenticationProvider.java Wraps Kerberos/SPNEGO failures into diagnostic exceptions before rethrowing Spring auth exceptions.
kerb4j-server/kerb4j-server-spring-security-core/.../SunJaasKerberosTicketValidator.java Uses new diagnostic model and new *OrThrow APIs to surface richer BadCredentials diagnostics.
kerb4j-server/kerb4j-server-common/.../Kerb4JException.java Fixes checked exception cause handling by delegating to super(message, cause).
kerb4j-common/src/main/java/com/kerb4j/common/exception/* Adds diagnostic types (codes/categories/diagnostic object/analyzer) and typed runtime exceptions.
kerb4j-common/src/main/java/com/kerb4j/common/jaas/sun/Krb5LoginContext.java Replaces generic RuntimeException wrapping with diagnostic exceptions on login failures.
kerb4j-common/src/main/java/com/kerb4j/client/SpnegoClient.java Adds *OrThrow + correctly-spelled createAuthorizationHeader* convenience APIs.
kerb4j-common/src/main/java/com/kerb4j/client/SpnegoContext.java Adds *OrThrow convenience APIs for token creation/acceptance and correct header method spelling.
kerb4j-common/src/main/java/com/kerb4j/client/spi/* Wraps login/refresh failures into diagnostic exceptions.
kerb4j-client-kerby/.../KerbySpnegoClientProvider.java Replaces IllegalStateException cases with explicit Kerberos diagnostics.
kerb4j-client-jdk/.../JdkSpnegoClientProvider.java Replaces UnsupportedOperationException with explicit provider diagnostics.
kerb4j-client-jdk/.../JdkSpnegoClientProviderTest.java Updates tests to assert new provider diagnostic exception behavior.
kerb4j-common/src/test/.../KerberosFailureAnalyzerTest.java Adds unit tests validating exception classification behavior.
docs/KERBEROS_FAILURE_DIAGNOSTICS.md Documents the new diagnostic exception model and troubleshooting contract.

Comment on lines +84 to 88
} finally {
if (!holdOnToGSSContext) {
acceptContext.close();
}
}
Comment on lines +68 to +72
throw diagnosticBadCredentials(KerberosFailureAnalyzer.explicit(
"spnego.resolve-service-credentials",
KerberosFailureCode.KEYTAB_MISSING_PRINCIPAL,
KerberosFailureCategory.CREDENTIALS,
"No Kerberos service credentials are configured for validating this token.",
Comment on lines +251 to +258
public String createAuthorizationHeader(URL url) throws Kerb4JKerberosException, IOException {
SpnegoContext context = createContextOrThrow(url);
try {
return context.createTokenAsAuthorizationHeader();
} finally {
context.close();
}
}
Comment on lines +269 to +276
public String createAuthorizationHeaderForSPN(String spn) throws Kerb4JKerberosException, IOException {
SpnegoContext contextForSPN = createContextForSPNOrThrow(spn);
try {
return contextForSPN.createTokenAsAuthorizationHeader();
} finally {
contextForSPN.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants