forked from dCache/dcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gplazma: oidc more descriptive offline verification failures
Motivation: OIDC uses caches to record the OIDC discover document and the issuer's public keys (for offline varification). Currently, if there is a problem with the discovery document or with the JWKS document then those problems are logged when the document is loaded, but subsequent attempts for offline verification of a token fail with an opaque and cryptic message. Modification: Update Result to support additional (Option-like) methods: `map` and `flatMap`. Introduce a new MissingNode class (ReasonBearingMissingNode) that can carry the reason why a JSON node is missing. Update discovery document fetching to take advantage of this new class. Update MemoriseMapWithExpiry to work on Results rather than Maps. The class is renamed to reflect this change. Issuer is updated to work with Result objects rather than Optional objects. These Result objects, if representing a failure, describe why the operation failed. This is used to generate a more descriptive AuthenticationException message. Suppress hamcrest-core from junit as this brings in an ancient version. Result: During offline verification, the details regarding any failure to fetch documents from the issuer or to parse the issuer-supplied documents are now used to build the error message when the plugin rejects a token. Target: master Requires-notes: yes Requires-book: no Closes: dCache#7553
- Loading branch information
1 parent
6a8dc21
commit edd80b2
Showing
10 changed files
with
924 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...gplazma2-oidc/src/main/java/org/dcache/gplazma/oidc/helpers/ReasonBearingMissingNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* dCache - http://www.dcache.org/ | ||
* | ||
* Copyright (C) 2024 Deutsches Elektronen-Synchrotron | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.dcache.gplazma.oidc.helpers; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.node.JsonNodeType; | ||
import com.fasterxml.jackson.databind.node.MissingNode; | ||
import com.fasterxml.jackson.databind.node.ValueNode; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* This is like Jackson's <tt>MissingNode</tt> but it carries a reason why the | ||
* node is missing. Unfortunately, <tt>MissingNode</tt> is declared final, so | ||
* we cannot simply extend it. | ||
*/ | ||
public class ReasonBearingMissingNode extends ValueNode { | ||
|
||
private final String reason; | ||
|
||
public ReasonBearingMissingNode(String reason) { | ||
this.reason = Objects.requireNonNull(reason); | ||
} | ||
|
||
public String getReason() { | ||
return reason; | ||
} | ||
|
||
@Override | ||
public final void serialize(JsonGenerator g, SerializerProvider provider) | ||
throws IOException | ||
{ | ||
g.writeNull(); | ||
} | ||
|
||
@Override | ||
public JsonToken asToken() { | ||
return JsonToken.NOT_AVAILABLE; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return reason.hashCode(); | ||
} | ||
|
||
@Override | ||
public JsonNodeType getNodeType() { | ||
return JsonNodeType.MISSING; | ||
} | ||
|
||
@Override | ||
public boolean isMissingNode() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String asText() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String toPrettyString() { | ||
return ""; | ||
} | ||
|
||
|
||
@Override | ||
public String asText(String defaultValue) { | ||
return defaultValue; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (!(other instanceof ReasonBearingMissingNode)) { | ||
return false; | ||
} | ||
|
||
ReasonBearingMissingNode o = (ReasonBearingMissingNode)other; | ||
return reason.equals(o.reason); | ||
} | ||
} |
Oops, something went wrong.