/** * Get the Stormpath Error Code * Check http://docs.stormpath.com/errors/ for the list of Stormpath Error Codes * @return the code of the error */ @Override public int getCode() { return error.getCode(); }
/** * More information about the error is described in the Stormpath Error Codes documentation * Check http://docs.stormpath.com/errors/ for the list of Stormpath Error Codes * @return the URI to the error documentation */ @Override public String getMoreInfo() { return error.getMoreInfo(); }
@Override public int getStatus() { return error.getStatus(); }
private ErrorModel translateResourceException(HttpServletRequest request, ResourceException e) { return new ErrorModel.Builder() .setStatus(e.getStormpathError().getStatus()) .setMessage(getErrorMessage(request, "stormpath.web.errors." + e.getStormpathError().getCode(), e.getStormpathError().getMessage())) .build(); }
/** * Ensures the message used for the exception (i.e. exception.getMessage()) reports the {@code developerMessage} * returned by the Stormpath API Server. The regular Stormpath response body {@code message} field is targeted * at applicadtion end-users that could very likely be non-technical. Since an exception should be helpful to * developers, it is better to show a more technical message. * <p/> * Added as a fix for <a href="https://github.com/stormpath/stormpath-sdk-java/issues/28">Issue #28</a>. * * @param error the response Error. Cannot be null. * @return {@code error.getDeveloperMessage()} * @since 0.9.2 */ private static String buildExceptionMessage(Error error) { Assert.notNull(error, "Error argument cannot be null."); StringBuilder sb = new StringBuilder(); sb.append("HTTP ").append(error.getStatus()) .append(", Stormpath ").append(error.getCode()) .append(" (").append(error.getMoreInfo()).append(")"); String requestId = error.getRequestId(); if (Strings.hasText(requestId)) { sb.append(", RequestId ").append(error.getRequestId()); } return sb.append(": ").append(error.getDeveloperMessage()).toString(); }
@Override public Map<String, Object> toErrorMap(Error error) { Map<String, Object> errorMap = new LinkedHashMap<String, Object>(); errorMap.put("status", error.getStatus()); errorMap.put("message", error.getMessage()); return errorMap; } }
private void revokeToken(String token, TokenTypeHint tokenTypeHint, HttpServletRequest request) { Application application = applicationResolver.getApplication(request); if (application != null && token != null) { try { OAuthRevocationRequest revocationRequest = OAuthRequests.OAUTH_TOKEN_REVOCATION_REQUEST.builder() .setToken(token) .setTokenTypeHint(tokenTypeHint) .build(); OAuthTokenRevocators.OAUTH_TOKEN_REVOCATOR.forApplication(application).revoke(revocationRequest); } catch (ResourceException e) { com.stormpath.sdk.error.Error error = e.getStormpathError(); String message = "There was an error trying to revoke a token: {}"; if (log.isDebugEnabled()) { log.warn(message, error.getMessage(), e); } else { log.warn(message, error.getMessage()); } } } }
@Override public String getDeveloperMessage() { return error.getDeveloperMessage(); }
@Override public String getRequestId() { return error.getRequestId(); }
private ErrorModel translateResourceException(HttpServletRequest request, ResourceException e) { return new ErrorModel.Builder() .setStatus(e.getStormpathError().getStatus()) .setMessage(getErrorMessage(request, "stormpath.web.errors." + e.getStormpathError().getCode(), e.getStormpathError().getMessage())) .build(); }
@Override public Map<String, Object> toErrorMap(Error error) { Map<String, Object> errorMap = new LinkedHashMap<String, Object>(); errorMap.put("status", error.getStatus()); errorMap.put("message", error.getMessage()); return errorMap; } }
private void revokeToken(String token, TokenTypeHint tokenTypeHint, HttpServletRequest request) { Application application = applicationResolver.getApplication(request); if (application != null && token != null) { try { OAuthRevocationRequest revocationRequest = OAuthRequests.OAUTH_TOKEN_REVOCATION_REQUEST.builder() .setToken(token) .setTokenTypeHint(tokenTypeHint) .build(); OAuthTokenRevocators.OAUTH_TOKEN_REVOCATOR.forApplication(application).revoke(revocationRequest); } catch (ResourceException e) { com.stormpath.sdk.error.Error error = e.getStormpathError(); String message = "There was an error trying to revoke a token: {}"; if (log.isDebugEnabled()) { log.warn(message, error.getMessage(), e); } else { log.warn(message, error.getMessage()); } } } }
protected boolean supports(Error error) { return supportedErrors.contains(error.getCode()); }
/** * Retrieves the {@link ApiKey} instance pointed by this {@code apiKeyId} and accessible from the {@code * application} <p/> The ApiKey is retrieved from the {@link Application} passed as argument. <p/> This method * asserts that the ApiKey retrieved status is {@link ApiKeyStatus#ENABLED} and also that the status of the account * owner is {@link AccountStatus#ENABLED} * * @param apiKeyId - The id of the {@link ApiKey} embedded in the access token. */ protected ApiKey getTokenApiKey(HttpServletRequest request, String apiKeyId) throws OAuthException { try { return getEnabledApiKey(request, apiKeyId); } catch (ResourceException e) { OAuthErrorCode err = OAuthErrorCode.INVALID_CLIENT; String msg = e.getStormpathError().getDeveloperMessage(); throw new OAuthException(err, msg, e); } } }
private void revoke(Application application, OAuthRevocationRequest request) throws OAuthException { try { OAuthTokenRevocators.OAUTH_TOKEN_REVOCATOR.forApplication(application).revoke(request); } catch (ResourceException e) { com.stormpath.sdk.error.Error error = e.getStormpathError(); String message = error.getMessage(); OAuthErrorCode oauthError = OAuthErrorCode.INVALID_REQUEST; if (error instanceof DefaultError) { Object errorObject = ((DefaultError) error).getProperty("error"); oauthError = errorObject == null ? oauthError : new OAuthErrorCode(errorObject.toString()); } throw new OAuthException(oauthError, message); } }
public void rethrow() throws InvalidSamlTokenException, SamlSessionTimeoutException { Error error = this.getStormpathError(); if (error.getCode() == 10100 || error.getCode() == 10101 || error.getCode() == 10102) { throw new InvalidSamlTokenException(error); } if (this.getStormpathError().getCode() == 12001) { throw new SamlSessionTimeoutException(error); } throw new IllegalStateException("error type is unrecognized: " + error.getCode()); }
/** * Retrieves the {@link ApiKey} instance pointed by this {@code apiKeyId} and accessible from the {@code * application} <p/> The ApiKey is retrieved from the {@link Application} passed as argument. <p/> This method * asserts that the ApiKey retrieved status is {@link ApiKeyStatus#ENABLED} and also that the status of the account * owner is {@link AccountStatus#ENABLED} * * @param apiKeyId - The id of the {@link ApiKey} embedded in the access token. */ protected ApiKey getTokenApiKey(HttpServletRequest request, String apiKeyId) throws OAuthException { try { return getEnabledApiKey(request, apiKeyId); } catch (ResourceException e) { OAuthErrorCode err = OAuthErrorCode.INVALID_CLIENT; String msg = e.getStormpathError().getDeveloperMessage(); throw new OAuthException(err, msg, e); } } }
private void revoke(Application application, OAuthRevocationRequest request) throws OAuthException { try { OAuthTokenRevocators.OAUTH_TOKEN_REVOCATOR.forApplication(application).revoke(request); } catch (ResourceException e) { com.stormpath.sdk.error.Error error = e.getStormpathError(); String message = error.getMessage(); OAuthErrorCode oauthError = OAuthErrorCode.INVALID_REQUEST; if (error instanceof DefaultError) { Object errorObject = ((DefaultError) error).getProperty("error"); oauthError = errorObject == null ? oauthError : new OAuthErrorCode(errorObject.toString()); } throw new OAuthException(oauthError, message); } }
/** * Converts this generic IDSite exception into one of the following corresponding checked exceptions: InvalidIDSiteTokenException, IDSiteSessionTimeoutException. * * @throws InvalidIDSiteTokenException * @throws IDSiteSessionTimeoutException */ public void rethrow() throws InvalidIDSiteTokenException, IDSiteSessionTimeoutException { Error error = this.getStormpathError(); if (error.getCode() == 10011 || error.getCode() == 10012 || error.getCode() == 11001 || error.getCode() == 11002 || error.getCode() == 11003 || error.getCode() == 11005 ) { throw new InvalidIDSiteTokenException(error); } if (this.getStormpathError().getCode() == 12001) { throw new IDSiteSessionTimeoutException(error); } if (this.getStormpathError().getCode() == 11005) { throw new IDSiteSessionTimeoutException(error); } throw new IllegalStateException("error type is unrecognized: " + error.getCode()); }
String message = error.getMessage();