-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jans-fido2):handling exception fido2 get endpoints by invalid par…
…ams (#4139)
- Loading branch information
1 parent
0aa51eb
commit a50d2af
Showing
4 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
jans-fido2/model/src/main/java/io/jans/fido2/model/u2f/error/Fido2ErrorResponseFactory.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,26 @@ | ||
package io.jans.fido2.model.u2f.error; | ||
|
||
import io.jans.as.model.error.DefaultErrorResponse; | ||
import io.jans.as.model.error.IErrorType; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
public class Fido2ErrorResponseFactory { | ||
|
||
public static WebApplicationException createBadRequestException(IErrorType type, String reason, String description, String correlationId) { | ||
final DefaultErrorResponse response = new DefaultErrorResponse(); | ||
response.setType(type); | ||
response.setState(""); | ||
response.setReason(reason); | ||
if (correlationId != null) | ||
response.setErrorDescription(String.format(description + " CorrelationId: %s", correlationId)); | ||
else | ||
response.setErrorDescription(description); | ||
throw new WebApplicationException(Response | ||
.status(Response.Status.BAD_REQUEST) | ||
.entity(response.toJSonString()) | ||
.type(MediaType.APPLICATION_JSON_TYPE) | ||
.build()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
jans-fido2/model/src/main/java/io/jans/fido2/model/u2f/error/Fido2ErrorResponseType.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,53 @@ | ||
/* | ||
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text. | ||
* | ||
* Copyright (c) 2020, Janssen Project | ||
*/ | ||
|
||
package io.jans.fido2.model.u2f.error; | ||
|
||
import io.jans.as.model.error.IErrorType; | ||
|
||
/** | ||
* Error codes for fido2 error responses. | ||
* | ||
*/ | ||
public enum Fido2ErrorResponseType implements IErrorType { | ||
|
||
/** | ||
* The request is missing a required parameter, includes an | ||
* invalid parameter value or is otherwise malformed id_session. | ||
*/ | ||
INVALID_ID_SESSION("invalid_id_session"), | ||
|
||
/** | ||
* The request is missing a required parameter, username or keyhandle | ||
*/ | ||
INVALID_USERNAME_OR_KEYHANDLE("invalid_username_or_keyhandle"); | ||
|
||
|
||
private final String paramName; | ||
|
||
Fido2ErrorResponseType(String paramName) { | ||
this.paramName = paramName; | ||
} | ||
|
||
/** | ||
* Returns a string representation of the object. In this case, the lower | ||
* case code of the error. | ||
*/ | ||
@Override | ||
public String toString() { | ||
return paramName; | ||
} | ||
|
||
/** | ||
* Gets error parameter. | ||
* | ||
* @return error parameter | ||
*/ | ||
@Override | ||
public String getParameter() { | ||
return paramName; | ||
} | ||
} |
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