Skip to content

Commit

Permalink
respond with 403 (not 401) when password good but no perms #10340
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Dec 19, 2024
1 parent 77caada commit 7d7414d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/AbstractApiBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,18 @@ protected Response badRequest(String msg, Map<String, String> fieldErrors) {
.build();
}

/**
* In short, your password is fine but you don't have permission.
*
* "The 403 (Forbidden) status code indicates that the server understood the
* request but refuses to authorize it. A server that wishes to make public
* why the request has been forbidden can describe that reason in the
* response payload (if any).
*
* If authentication credentials were provided in the request, the server
* considers them insufficient to grant access." --
* https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.3
*/
protected Response forbidden( String msg ) {
return error( Status.FORBIDDEN, msg );
}
Expand All @@ -852,9 +864,17 @@ protected Response permissionError( PermissionException pe ) {
}

protected Response permissionError( String message ) {
return unauthorized( message );
return forbidden( message );
}

/**
* In short, bad password.
*
* "The 401 (Unauthorized) status code indicates that the request has not
* been applied because it lacks valid authentication credentials for the
* target resource." --
* https://datatracker.ietf.org/doc/html/rfc7235#section-3.1
*/
protected Response unauthorized( String message ) {
return error( Status.UNAUTHORIZED, message );
}
Expand Down

0 comments on commit 7d7414d

Please sign in to comment.