@Test public void testSuccessfulAuthorizationWithUnsignedCallback() { final OAuthDomainEntry dto = new OAuthDomainEntry(); dto.setCallbackUrlSigned(false); context.checking(new Expectations() { { oneOf(actionContext).getPrincipal(); will(returnValue(principal)); oneOf(principal).getAccountId(); will(returnValue("testacctid")); oneOf(actionContext).getParams(); will(returnValue("token")); oneOf(entryMapper).execute("token"); will(returnValue(dto)); oneOf(entryMapper).execute("token"); will(returnValue(dto)); } }); String callbackurl = sut.execute(actionContext); assertNotNull(callbackurl); assertEquals(dto.isAuthorized(), true); assertTrue(dto.getCallbackToken() == null); context.assertIsSatisfied(); }
@Override public String execute(final PrincipalActionContext inActionContext) throws ExecutionException { final String accountId = inActionContext.getPrincipal().getAccountId(); final String token = (String) inActionContext.getParams(); log.trace("Authorizing OAuth token for user: " + accountId); OAuthEntry tokenEntry = new OAuthEntry(); tokenEntry.setToken(token); try { OAuthDomainEntry dto = entryMapper.execute(token); dto.setAuthorized(true); if (dto.isCallbackUrlSigned()) { dto.setCallbackToken(Crypto.getRandomDigits(CALLBACK_TOKEN_LENGTH)); } } catch (Exception ex) { log.error("An error occurred authorizing the OAuth token.", ex); throw new ExecutionException(ex); } OAuthDomainEntry currentEntry = entryMapper.execute(tokenEntry.getToken()); log.trace("Authorization for user: " + accountId + " complete."); String callbackUrl = ""; if (currentEntry.getCallbackUrl() != null && currentEntry.getCallbackUrl().length() > 0) { try { callbackUrl = OAuth.addParameters(currentEntry.getCallbackUrl(), "oauth_verifier", currentEntry .getCallbackToken()); callbackUrl = OAuth.addParameters(callbackUrl, OAuth.OAUTH_TOKEN, currentEntry.getToken()); } catch (IOException ioe) { log.error("An IO exception has occured.", ioe); throw new ExecutionException(ioe); } } log.debug("return the callback url with the oauth_token added " + callbackUrl); return callbackUrl; }
OAuthAuthorizeExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public String execute(final PrincipalActionContext inActionContext) throws ExecutionException { final String accountId = inActionContext.getPrincipal().getAccountId(); final String token = (String) inActionContext.getParams(); log.trace("Authorizing OAuth token for user: " + accountId); OAuthEntry tokenEntry = new OAuthEntry(); tokenEntry.setToken(token); try { OAuthDomainEntry dto = entryMapper.execute(token); dto.setAuthorized(true); if (dto.isCallbackUrlSigned()) { dto.setCallbackToken(Crypto.getRandomDigits(CALLBACK_TOKEN_LENGTH)); } } catch (Exception ex) { log.error("An error occurred authorizing the OAuth token.", ex); throw new ExecutionException(ex); } OAuthDomainEntry currentEntry = entryMapper.execute(tokenEntry.getToken()); log.trace("Authorization for user: " + accountId + " complete."); String callbackUrl = ""; if (currentEntry.getCallbackUrl() != null && currentEntry.getCallbackUrl().length() > 0) { try { callbackUrl = OAuth.addParameters(currentEntry.getCallbackUrl(), "oauth_verifier", currentEntry .getCallbackToken()); callbackUrl = OAuth.addParameters(callbackUrl, OAuth.OAUTH_TOKEN, currentEntry.getToken()); } catch (IOException ioe) { log.error("An IO exception has occured.", ioe); throw new ExecutionException(ioe); } } log.debug("return the callback url with the oauth_token added " + callbackUrl); return callbackUrl; } }
OAuthAuthorizeExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public String execute(final PrincipalActionContext inActionContext) throws ExecutionException { final String accountId = inActionContext.getPrincipal().getAccountId(); final String token = (String) inActionContext.getParams(); log.trace("Authorizing OAuth token for user: " + accountId); OAuthEntry tokenEntry = new OAuthEntry(); tokenEntry.setToken(token); try { OAuthDomainEntry dto = entryMapper.execute(token); dto.setAuthorized(true); if (dto.isCallbackUrlSigned()) { dto.setCallbackToken(Crypto.getRandomDigits(CALLBACK_TOKEN_LENGTH)); } } catch (Exception ex) { log.error("An error occurred authorizing the OAuth token.", ex); throw new ExecutionException(ex); } OAuthDomainEntry currentEntry = entryMapper.execute(tokenEntry.getToken()); log.trace("Authorization for user: " + accountId + " complete."); String callbackUrl = ""; if (currentEntry.getCallbackUrl() != null && currentEntry.getCallbackUrl().length() > 0) { try { callbackUrl = OAuth.addParameters(currentEntry.getCallbackUrl(), "oauth_verifier", currentEntry .getCallbackToken()); callbackUrl = OAuth.addParameters(callbackUrl, OAuth.OAUTH_TOKEN, currentEntry.getToken()); } catch (IOException ioe) { log.error("An IO exception has occured.", ioe); throw new ExecutionException(ioe); } } log.debug("return the callback url with the oauth_token added " + callbackUrl); return callbackUrl; } OAuthAuthorizeExecution(final DomainMapper<String, OAuthDomainEntry> inEntryMapper); }
OAuthAuthorizeExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public String execute(final PrincipalActionContext inActionContext) throws ExecutionException { final String accountId = inActionContext.getPrincipal().getAccountId(); final String token = (String) inActionContext.getParams(); log.trace("Authorizing OAuth token for user: " + accountId); OAuthEntry tokenEntry = new OAuthEntry(); tokenEntry.setToken(token); try { OAuthDomainEntry dto = entryMapper.execute(token); dto.setAuthorized(true); if (dto.isCallbackUrlSigned()) { dto.setCallbackToken(Crypto.getRandomDigits(CALLBACK_TOKEN_LENGTH)); } } catch (Exception ex) { log.error("An error occurred authorizing the OAuth token.", ex); throw new ExecutionException(ex); } OAuthDomainEntry currentEntry = entryMapper.execute(tokenEntry.getToken()); log.trace("Authorization for user: " + accountId + " complete."); String callbackUrl = ""; if (currentEntry.getCallbackUrl() != null && currentEntry.getCallbackUrl().length() > 0) { try { callbackUrl = OAuth.addParameters(currentEntry.getCallbackUrl(), "oauth_verifier", currentEntry .getCallbackToken()); callbackUrl = OAuth.addParameters(callbackUrl, OAuth.OAUTH_TOKEN, currentEntry.getToken()); } catch (IOException ioe) { log.error("An IO exception has occured.", ioe); throw new ExecutionException(ioe); } } log.debug("return the callback url with the oauth_token added " + callbackUrl); return callbackUrl; } OAuthAuthorizeExecution(final DomainMapper<String, OAuthDomainEntry> inEntryMapper); @Override String execute(final PrincipalActionContext inActionContext); }
OAuthAuthorizeExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public String execute(final PrincipalActionContext inActionContext) throws ExecutionException { final String accountId = inActionContext.getPrincipal().getAccountId(); final String token = (String) inActionContext.getParams(); log.trace("Authorizing OAuth token for user: " + accountId); OAuthEntry tokenEntry = new OAuthEntry(); tokenEntry.setToken(token); try { OAuthDomainEntry dto = entryMapper.execute(token); dto.setAuthorized(true); if (dto.isCallbackUrlSigned()) { dto.setCallbackToken(Crypto.getRandomDigits(CALLBACK_TOKEN_LENGTH)); } } catch (Exception ex) { log.error("An error occurred authorizing the OAuth token.", ex); throw new ExecutionException(ex); } OAuthDomainEntry currentEntry = entryMapper.execute(tokenEntry.getToken()); log.trace("Authorization for user: " + accountId + " complete."); String callbackUrl = ""; if (currentEntry.getCallbackUrl() != null && currentEntry.getCallbackUrl().length() > 0) { try { callbackUrl = OAuth.addParameters(currentEntry.getCallbackUrl(), "oauth_verifier", currentEntry .getCallbackToken()); callbackUrl = OAuth.addParameters(callbackUrl, OAuth.OAUTH_TOKEN, currentEntry.getToken()); } catch (IOException ioe) { log.error("An IO exception has occured.", ioe); throw new ExecutionException(ioe); } } log.debug("return the callback url with the oauth_token added " + callbackUrl); return callbackUrl; } OAuthAuthorizeExecution(final DomainMapper<String, OAuthDomainEntry> inEntryMapper); @Override String execute(final PrincipalActionContext inActionContext);  }