
be.looorent.micronaut.security.FailedSecurityContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of keycloak-micronaut-adapter Show documentation
Show all versions of keycloak-micronaut-adapter Show documentation
Create API middleware to check Authorization headers against Keycloak
The newest version!
package be.looorent.micronaut.security;
/**
* A security context that as either failed a token validation
* or that caught an unexpected error during this validation.
* Wraps an exception.
* @author Lorent Lempereur - [email protected]
*/
class FailedSecurityContext implements SecurityContext {
private final Throwable exception;
private final String message;
private final String reason;
private final boolean unexpected;
public FailedSecurityContext(Throwable exception,
String message,
String reason,
boolean unexpected) {
this.exception = exception;
this.message = message;
this.reason = reason;
this.unexpected = unexpected;
}
static final FailedSecurityContext unexpectedErrorDuringVerification(Throwable exception) {
return new FailedSecurityContext(exception,
"An unexpected error occurred during the authentication",
"internal_error",
true);
}
static final FailedSecurityContext securityErrorFound(SecurityException exception) {
return new FailedSecurityContext(exception,
exception.getMessage(),
"unauthorized",
false);
}
public Throwable getException() {
return exception;
}
public String getMessage() {
return message;
}
public String getReason() {
return reason;
}
public boolean isUnexpected() {
return unexpected;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy