/** * Update a response with additional data to be returned to the application. */ public void addToResponse(HttpResponseBuilder response, OAuthRequestException e) { if (!newClientState.isEmpty()) { try { response.setMetadata(CLIENT_STATE, newClientState.getEncryptedState()); } catch (BlobCrypterException cryptException) { // Configuration error somewhere, this should never happen. throw new RuntimeException(cryptException); } } if (aznUrl != null) { response.setMetadata(APPROVAL_URL, aznUrl); } if (e != null || sendTraceToClient) { StringBuilder verboseError = new StringBuilder(); if (e != null) { response.setMetadata(ERROR_CODE, e.getError()); verboseError.append(e.getErrorText()); } if (sendTraceToClient) { verboseError.append('\n'); verboseError.append(getRequestTrace()); } response.setMetadata(ERROR_TEXT, verboseError.toString()); } }
/** * Update a response with additional data to be returned to the application. */ public void addToResponse(HttpResponseBuilder response, OAuthRequestException e) { if (!newClientState.isEmpty()) { try { response.setMetadata(CLIENT_STATE, newClientState.getEncryptedState()); } catch (BlobCrypterException cryptException) { // Configuration error somewhere, this should never happen. throw new RuntimeException(cryptException); } } if (aznUrl != null) { response.setMetadata(APPROVAL_URL, aznUrl); } if (e != null || sendTraceToClient) { StringBuilder verboseError = new StringBuilder(); if (e != null) { response.setMetadata(ERROR_CODE, e.getError()); verboseError.append(e.getErrorText()); } if (sendTraceToClient) { verboseError.append('\n'); verboseError.append(getRequestTrace()); } response.setMetadata(ERROR_TEXT, verboseError.toString()); } }
/** * Update a response with additional data to be returned to the application. */ public void addToResponse(HttpResponseBuilder response, OAuthRequestException e) { if (!newClientState.isEmpty()) { try { response.setMetadata(CLIENT_STATE, newClientState.getEncryptedState()); } catch (BlobCrypterException cryptException) { // Configuration error somewhere, this should never happen. throw new RuntimeException(cryptException); } } if (aznUrl != null) { response.setMetadata(APPROVAL_URL, aznUrl); } if (e != null || sendTraceToClient) { StringBuilder verboseError = new StringBuilder(); if (e != null) { response.setMetadata(ERROR_CODE, e.getError()); verboseError.append(e.getErrorText()); } if (sendTraceToClient) { verboseError.append('\n'); verboseError.append(getRequestTrace()); } response.setMetadata(ERROR_TEXT, verboseError.toString()); } }
@Test public void testEncryptEmpty() throws Exception { OAuthClientState state = new OAuthClientState(crypter); assertEmpty(state); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEmpty(state); }
@Test public void testEncryptEmpty() throws Exception { OAuthClientState state = new OAuthClientState(crypter); assertEmpty(state); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEmpty(state); }
@Test public void testEncryptEmpty() throws Exception { OAuthClientState state = new OAuthClientState(crypter); assertEmpty(state); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEmpty(state); }
@Test public void testExpired() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setRequestToken("reqtoken"); String encrypted = state.getEncryptedState(); // expiry time + skew. timeSource.incrementSeconds(3600 + 180 + 1); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); }
@Test public void testExpired() throws Exception { OAuthClientState state = new OAuthClientState(crypter); timeSource.incrementSeconds(-1 * (3600 + 180 + 1)); // expiry time + skew. state.setTimeSource(timeSource); state.setRequestToken("reqtoken"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); }
@Test public void testExpired() throws Exception { OAuthClientState state = new OAuthClientState(crypter); timeSource.incrementSeconds(-1 * (3600 + 180 + 1)); // expiry time + skew. state.setTimeSource(timeSource); state.setRequestToken("reqtoken"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); }
@Test public void testNullValue() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setRequestToken("reqtoken"); state.setRequestToken(null); state.setOwner("owner"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); assertEquals("owner", state.getOwner()); } }
@Test public void testNullValue() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setRequestToken("reqtoken"); state.setRequestToken(null); state.setOwner("owner"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); assertEquals("owner", state.getOwner()); } }
@Test public void testNullValue() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setRequestToken("reqtoken"); state.setRequestToken(null); state.setOwner("owner"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); assertEquals("owner", state.getOwner()); } }
@Test public void testValuesSet() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setAccessToken("atoken"); state.setAccessTokenSecret("atokensecret"); state.setOwner("owner"); state.setRequestToken("reqtoken"); state.setRequestTokenSecret("reqtokensecret"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEquals("atoken", state.getAccessToken()); assertEquals("atokensecret", state.getAccessTokenSecret()); assertEquals("owner", state.getOwner()); assertEquals("reqtoken", state.getRequestToken()); assertEquals("reqtokensecret", state.getRequestTokenSecret()); }
@Test public void testValuesSet() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setAccessToken("atoken"); state.setAccessTokenSecret("atokensecret"); state.setOwner("owner"); state.setRequestToken("reqtoken"); state.setRequestTokenSecret("reqtokensecret"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEquals("atoken", state.getAccessToken()); assertEquals("atokensecret", state.getAccessTokenSecret()); assertEquals("owner", state.getOwner()); assertEquals("reqtoken", state.getRequestToken()); assertEquals("reqtokensecret", state.getRequestTokenSecret()); }
@Test public void testValuesSet() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setAccessToken("atoken"); state.setAccessTokenSecret("atokensecret"); state.setOwner("owner"); state.setRequestToken("reqtoken"); state.setRequestTokenSecret("reqtokensecret"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEquals("atoken", state.getAccessToken()); assertEquals("atokensecret", state.getAccessTokenSecret()); assertEquals("owner", state.getOwner()); assertEquals("reqtoken", state.getRequestToken()); assertEquals("reqtokensecret", state.getRequestTokenSecret()); }