Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrcidInvalidScopeException should display the provided scopes and log… #7228

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ public class OrcidExceptionMapper implements ExceptionMapper<Throwable> {
public Response toResponse(Throwable t) {
// Whatever exception has been caught, make sure we log it.
String clientId = securityManager.getClientIdFromAPIRequest();
if(t instanceof OrcidDeprecatedException
if(t instanceof OrcidInvalidScopeException) {
// This exception happens on client_credentials grant, so, the security manager doesn't have the client id info
OrcidInvalidScopeException ex = (OrcidInvalidScopeException) t;
if(clientId == null) {
clientId = ex.getClientId();
}
logShortError(t, clientId);
} else if(t instanceof OrcidDeprecatedException
|| t instanceof LockedException
|| t instanceof DeactivatedException
|| t instanceof OrcidNoBioException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Response obtainOauth2Token(String authorization, MultivaluedMap<String, S
if(scopeType.isInternalScope()) {
// You should not allow any internal scope here! go away!
String message = localeManager.resolveMessage("apiError.9015.developerMessage", new Object[]{});
throw new OrcidInvalidScopeException(message);
throw new OrcidInvalidScopeException(message, clientId, scope);
} else if(OrcidOauth2Constants.GRANT_TYPE_CLIENT_CREDENTIALS.equals(grantType)) {
if(!scopeType.isClientCreditalScope())
toRemove.add(scope);
Expand All @@ -147,7 +147,10 @@ public Response obtainOauth2Token(String authorization, MultivaluedMap<String, S
}
} catch (IllegalArgumentException iae) {
String message = localeManager.resolveMessage("apiError.9015.developerMessage", new Object[]{});
throw new OrcidInvalidScopeException(message);
if(scopes != null) {
message += " Provided scopes: " + String.join(",", scopes);
}
throw new OrcidInvalidScopeException(message, clientId, iae.getMessage());
}

try{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,28 @@ public class OrcidInvalidScopeException extends ApplicationException {

private static final long serialVersionUID = 1L;

private String clientId;
private String scope;

public OrcidInvalidScopeException() {
super();
}

public OrcidInvalidScopeException(String message) {
super(message);
}

public OrcidInvalidScopeException(String message, String clientId, String scope) {
super(message);
this.clientId = clientId;
this.scope = scope;
}

public String getClientId() {
return clientId;
}

public String getScope() {
return scope;
}
}