Skip to content

Commit

Permalink
improved exception for the missing client_public_id
Browse files Browse the repository at this point in the history
  • Loading branch information
SrdjanStevanetic committed Feb 5, 2025
1 parent 34dd68c commit 91e628d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package eu.europeana.annotation.web.service.controller.jsonld;

import static org.springframework.http.HttpStatus.UNAUTHORIZED;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.stanbol.commons.exception.JsonParseException;
import org.apache.stanbol.commons.jsonld.JsonLd;
Expand Down Expand Up @@ -60,14 +60,12 @@
import eu.europeana.annotation.web.service.authorization.AnnotationAuthorizationUtils;
import eu.europeana.annotation.web.service.controller.BaseRest;
import eu.europeana.api.common.config.I18nConstantsAnnotation;
import eu.europeana.api.commons.definitions.config.i18n.I18nConstants;
import eu.europeana.api.commons.oauth2.model.impl.EuropeanaApiCredentials;
import eu.europeana.api.commons.web.definitions.WebFields;
import eu.europeana.api.commons.web.exception.ApplicationAuthenticationException;
import eu.europeana.api.commons.web.exception.HttpException;
import eu.europeana.api.commons.web.exception.InternalServerException;
import eu.europeana.api.commons.web.http.HttpHeaders;
import eu.europeana.api.commons.web.model.vocabulary.Operations;

public class BaseJsonldRest extends BaseRest {

Expand Down Expand Up @@ -179,10 +177,8 @@ private String verifyClient(Authentication authentication)
throws ApplicationAuthenticationException {
String clientId = ((EuropeanaApiCredentials) authentication.getCredentials()).getClientId();
if (StringUtils.isBlank(clientId)) {
final String message = "ClientID is mandatory, please contact the support Team";
throw new ApplicationAuthenticationException(message,
I18nConstants.OPERATION_NOT_AUTHORIZED, new String[] {message},
UNAUTHORIZED);
throw new ApplicationAuthenticationException(I18nConstantsAnnotation.CLIENT_NOT_PUBLIC,
I18nConstantsAnnotation.CLIENT_NOT_PUBLIC, null, HttpStatus.FORBIDDEN);
}
return clientId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public interface I18nConstantsAnnotation extends eu.europeana.api.commons.definitions.config.i18n.I18nConstants{
String ANNOTATION_NOT_FOUND = "error.annotation_not_found";
String CLIENT_NOT_AUTHORIZED = "error.annotation_client_not_authorized";
String CLIENT_NOT_PUBLIC = "error.annotation_client_not_public";
String USER_NOT_AUTHORIZED = "error.annotation_user_not_authorized";
String ANNOTATION_NOT_ACCESSIBLE = "error.annotation_not_accessible";
String ANNOTATION_INVALID_BODY = "error.annotation_invalid_body";
Expand Down
1 change: 1 addition & 0 deletions annotation-web/src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ error.annotation_not_found=No annotation found with the given identifier! {0}
error.annotation_apikey_file_not_found=No apiKey file found in {0} folder!
#error.annotation_operation_not_authorized=The user is not allowed to perform the given operation!
error.annotation_client_not_authorized=The client application is not allowed to perform the given operation!
error.annotation_client_not_public=The client is not authorized to perform the given operation because the public id for the client is missing. Please get in contact with the Europeana APIs customer support via [email protected]

error.annotation_invalid_token=The provided authentication token is invalid! {0}
error.annotation_user_not_authorized=The user is not authorized to perform the given action! {0}
Expand Down

0 comments on commit 91e628d

Please sign in to comment.