@Override public void updateRefreshToken(RefreshToken refreshToken) { try { deleteRefreshToken(refreshToken.getTokenId()); tokenStore.create(refreshToken); } catch (CoreTokenException e) { logger.error( "DefaultOAuthTokenStoreImpl::Unable to create refresh token " + refreshToken.getTokenId(), e); throw new OAuthProblemException( Status.SERVER_ERROR_INTERNAL.getCode(), "Internal error", "Could not create token in CTS", null); } catch (InvalidRequestException e) { logger.error( "DefaultOAuthTokenStoreImpl::Unable to delete refresh token " + refreshToken.getTokenId(), e); throw new OAuthProblemException( Status.SERVER_ERROR_INTERNAL.getCode(), "Internal error", "Could not delete token in CTS", null); } }
/** {@inheritDoc} */ public void deleteAuthorizationCode(String authorizationCode) { if (logger.messageEnabled()) { logger.message( "DefaultOAuthTokenStoreImpl::Deleting Authorization code: " + authorizationCode); } JsonValue oAuthToken; // Read from CTS try { oAuthToken = tokenStore.read(authorizationCode); } catch (CoreTokenException e) { logger.error( "DefaultOAuthTokenStoreImpl::Unable to read authorization code corresponding to id: " + authorizationCode, e); throw new OAuthProblemException( Status.SERVER_ERROR_INTERNAL.getCode(), "Internal error", "Could not read token from CTS: " + e.getMessage(), null); } if (oAuthToken == null) { logger.error( "DefaultOAuthTokenStoreImpl::Unable to read authorization code corresponding to id: " + authorizationCode); throw new OAuthProblemException( Status.CLIENT_ERROR_NOT_FOUND.getCode(), "Not found", "Could not find token using CTS", null); } // Delete the code try { tokenStore.delete(authorizationCode); } catch (CoreTokenException e) { logger.error( "DefaultOAuthTokenStoreImpl::Unable to delete authorization code corresponding to id: " + authorizationCode, e); throw new OAuthProblemException( Status.SERVER_ERROR_INTERNAL.getCode(), "Internal error", "Could not delete token from CTS: " + e.getMessage(), null); } }
/** {@inheritDoc} */ public void updateAuthorizationCode(AuthorizationCode authorizationCode) { deleteAuthorizationCode(authorizationCode.getTokenId()); // Store in CTS try { tokenStore.create(authorizationCode); if (auditLogger.isAuditLogEnabled()) { String[] obs = {"UPDATED_AUTHORIZATION_CODE", authorizationCode.toString()}; auditLogger.logAccessMessage("CREATED_AUTHORIZATION_CODE", obs, null); } } catch (CoreTokenException e) { if (auditLogger.isAuditLogEnabled()) { String[] obs = {"FAILED_UPDATE_AUTHORIZATION_CODE", authorizationCode.toString()}; auditLogger.logErrorMessage("FAILED_UPDATE_AUTHORIZATION_CODE", obs, null); } logger.error( "DefaultOAuthTokenStoreImpl::Unable to create authorization code " + authorizationCode.getTokenInfo(), e); throw new OAuthProblemException( Status.SERVER_ERROR_INTERNAL.getCode(), "Internal error", "Could not create token in CTS", null); } }
@Override protected void afterHandle(Request request, Response response) { String callback = request.getResourceRef().getQueryAsForm().getFirstValue("callback"); if (callback != null) { StringBuilder stringBuilder = new StringBuilder(callback); stringBuilder.append("("); Representation representation = response.getEntity(); if (representation != null) { try { InputStream inputStream = representation.getStream(); if (inputStream != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] bytes = new byte[0x10000]; int length; while ((length = inputStream.read(bytes)) > 0) { out.write(bytes, 0, length); } stringBuilder.append(out.toString("UTF-8")); } } catch (IOException e) { List<String> details = new ArrayList<String>(); details.add(e.getMessage()); ServiceException serviceException = new ServiceException( new ServiceError( (Status.SERVER_ERROR_INTERNAL.getCode()), "Internal Server Error", details)); response.setEntity(serviceException); } } stringBuilder.append(")"); response.setEntity(new StringRepresentation(stringBuilder.toString(), MediaType.TEXT_PLAIN)); } }
public void updateAccessToken(AccessToken accessToken) { try { deleteAccessToken(accessToken.getTokenId()); tokenStore.create(accessToken); } catch (ServerException e) { logger.error( "DefaultOAuthTokenStoreImpl::Unable to delete access token " + accessToken.getTokenId(), e); throw new OAuthProblemException( Status.SERVER_ERROR_INTERNAL.getCode(), "Internal error", "Could not delete token in CTS", null); } catch (CoreTokenException e) { logger.error( "DefaultOAuthTokenStoreImpl::Unable to create access token " + accessToken.getTokenId(), e); throw new OAuthProblemException( Status.SERVER_ERROR_INTERNAL.getCode(), "Internal error", "Could not create token in CTS", null); } }