@Override public Map<String, List<String>> getHTTPHeaders(String url) { Map<String, List<String>> headers = super.getHTTPHeaders(url); if (headers == null) { headers = new HashMap<String, List<String>>(); } headers.put("Authorization", Collections.singletonList("Bearer " + getAccessToken())); return headers; }
private void refreshToken() throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Refreshing OAuth access token."); } makeRequest(true); if (LOG.isTraceEnabled()) { LOG.trace(token.toString()); } }
private void makeRequest(boolean isRefresh) throws IOException { Object tokenEndpoint = getSession().get(SessionParameter.OAUTH_TOKEN_ENDPOINT); if (!(tokenEndpoint instanceof String)) { throw new CmisConnectionException("Token endpoint not set!"); conn.setUseCaches(false); conn.setRequestProperty("User-Agent", (String) getSession().get(SessionParameter.USER_AGENT, ClientVersion.OPENCMIS_USER_AGENT)); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); Object code = getSession().get(SessionParameter.OAUTH_CODE); if (code != null) { writer.write("&code="); Object redirectUri = getSession().get(SessionParameter.OAUTH_REDIRECT_URI); if (redirectUri != null) { writer.write("&redirect_uri="); Object clientId = getSession().get(SessionParameter.OAUTH_CLIENT_ID); if (clientId != null) { writer.write("&client_id="); Object clientSecret = getSession().get(SessionParameter.OAUTH_CLIENT_SECRET); if (clientSecret != null) { writer.write("&client_secret="); JSONObject jsonResponse = parseResponse(conn); JSONObject jsonResponse = parseResponse(conn);
/** * Gets the access token. If no access token is present or the access token * is expired, a new token is requested. * * @return the access token */ protected String getAccessToken() { lock.writeLock().lock(); try { if (token.getAccessToken() == null) { if (token.getRefreshToken() == null) { requestToken(); } else { refreshToken(); } } else if (token.isExpired()) { refreshToken(); } return token.getAccessToken(); } catch (CmisConnectionException ce) { throw ce; } catch (Exception e) { throw new CmisConnectionException("Cannot get OAuth access token: " + e.getMessage(), e); } finally { lock.writeLock().unlock(); } }
reader = new InputStreamReader(stream, extractCharset(conn)); JSONParser parser = new JSONParser(); Object response = parser.parse(reader);
private void makeRequest(boolean isRefresh) throws IOException { Object tokenEndpoint = getSession().get(SessionParameter.OAUTH_TOKEN_ENDPOINT); if (!(tokenEndpoint instanceof String)) { throw new CmisConnectionException("Token endpoint not set!"); conn.setUseCaches(false); conn.setRequestProperty("User-Agent", (String) getSession().get(SessionParameter.USER_AGENT, ClientVersion.OPENCMIS_USER_AGENT)); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); Object code = getSession().get(SessionParameter.OAUTH_CODE); if (code != null) { writer.write("&code="); Object redirectUri = getSession().get(SessionParameter.OAUTH_REDIRECT_URI); if (redirectUri != null) { writer.write("&redirect_uri="); Object clientId = getSession().get(SessionParameter.OAUTH_CLIENT_ID); if (clientId != null) { writer.write("&client_id="); Object clientSecret = getSession().get(SessionParameter.OAUTH_CLIENT_SECRET); if (clientSecret != null) { writer.write("&client_secret="); JSONObject jsonResponse = parseResponse(conn); JSONObject jsonResponse = parseResponse(conn);
/** * Gets the access token. If no access token is present or the access token * is expired, a new token is requested. * * @return the access token */ protected String getAccessToken() { lock.writeLock().lock(); try { if (token.getAccessToken() == null) { if (token.getRefreshToken() == null) { requestToken(); } else { refreshToken(); } } else if (token.isExpired()) { refreshToken(); } return token.getAccessToken(); } catch (CmisConnectionException ce) { throw ce; } catch (Exception e) { throw new CmisConnectionException("Cannot get OAuth access token: " + e.getMessage(), e); } finally { lock.writeLock().unlock(); } }
reader = new InputStreamReader(stream, extractCharset(conn)); JSONParser parser = new JSONParser(); Object response = parser.parse(reader);
private void refreshToken() throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Refreshing OAuth access token."); } makeRequest(true); if (LOG.isTraceEnabled()) { LOG.trace(token.toString()); } }
@Override public Map<String, List<String>> getHTTPHeaders(String url) { Map<String, List<String>> headers = super.getHTTPHeaders(url); if (headers == null) { headers = new HashMap<String, List<String>>(); } headers.put("Authorization", Collections.singletonList("Bearer " + getAccessToken())); return headers; }
private void requestToken() throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Requesting new OAuth access token."); } makeRequest(false); if (LOG.isTraceEnabled()) { LOG.trace(token.toString()); } }
private void requestToken() throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Requesting new OAuth access token."); } makeRequest(false); if (LOG.isTraceEnabled()) { LOG.trace(token.toString()); } }