@Test public void testFindTokenByServiceNameAndGadgetUrl() { OAuthConsumer consumer = new OAuthConsumer("provider1", "http: "secret1", "HMAC-SHA1"); OAuthToken token = sut.execute(new OAuthTokenRequest(consumer, "123", "456")); assertTrue("No Token found for consumer 101 and viewer 123 and owner 456", token != null); assertEquals("Incorrect access token returned", "accesstoken1", token.getAccessToken()); assertEquals("Incorrect token secret returned", "accesssecret1", token.getTokenSecret()); }
@Override @SuppressWarnings("unchecked") public OAuthToken execute(final OAuthTokenRequest inRequest) { Query q = getEntityManager().createQuery( "from OAuthToken t where t.consumer.serviceProviderName = :serviceName" + " and t.consumer.gadgetUrl = :gadgetUrl and t.viewerId = :viewerId and t.ownerId = :ownerId") .setParameter("serviceName", inRequest.getConsumer().getServiceProviderName()).setParameter( "gadgetUrl", inRequest.getConsumer().getGadgetUrl()).setParameter("viewerId", inRequest.getViewerId()).setParameter("ownerId", inRequest.getOwnerId()); List results = q.getResultList(); if (results.size() == 0) { return null; } OAuthToken token = (OAuthToken) results.get(0); Long ms = token.getTokenExpireMillis(); if (ms == null || ms == 0 || ms > Calendar.getInstance().getTimeInMillis()) { return token; } else { getEntityManager().remove(token); return null; } }
GetOAuthToken extends ReadMapper<OAuthTokenRequest, OAuthToken> { @Override @SuppressWarnings("unchecked") public OAuthToken execute(final OAuthTokenRequest inRequest) { Query q = getEntityManager().createQuery( "from OAuthToken t where t.consumer.serviceProviderName = :serviceName" + " and t.consumer.gadgetUrl = :gadgetUrl and t.viewerId = :viewerId and t.ownerId = :ownerId") .setParameter("serviceName", inRequest.getConsumer().getServiceProviderName()).setParameter( "gadgetUrl", inRequest.getConsumer().getGadgetUrl()).setParameter("viewerId", inRequest.getViewerId()).setParameter("ownerId", inRequest.getOwnerId()); List results = q.getResultList(); if (results.size() == 0) { return null; } OAuthToken token = (OAuthToken) results.get(0); Long ms = token.getTokenExpireMillis(); if (ms == null || ms == 0 || ms > Calendar.getInstance().getTimeInMillis()) { return token; } else { getEntityManager().remove(token); return null; } } }
GetOAuthToken extends ReadMapper<OAuthTokenRequest, OAuthToken> { @Override @SuppressWarnings("unchecked") public OAuthToken execute(final OAuthTokenRequest inRequest) { Query q = getEntityManager().createQuery( "from OAuthToken t where t.consumer.serviceProviderName = :serviceName" + " and t.consumer.gadgetUrl = :gadgetUrl and t.viewerId = :viewerId and t.ownerId = :ownerId") .setParameter("serviceName", inRequest.getConsumer().getServiceProviderName()).setParameter( "gadgetUrl", inRequest.getConsumer().getGadgetUrl()).setParameter("viewerId", inRequest.getViewerId()).setParameter("ownerId", inRequest.getOwnerId()); List results = q.getResultList(); if (results.size() == 0) { return null; } OAuthToken token = (OAuthToken) results.get(0); Long ms = token.getTokenExpireMillis(); if (ms == null || ms == 0 || ms > Calendar.getInstance().getTimeInMillis()) { return token; } else { getEntityManager().remove(token); return null; } }  }
GetOAuthToken extends ReadMapper<OAuthTokenRequest, OAuthToken> { @Override @SuppressWarnings("unchecked") public OAuthToken execute(final OAuthTokenRequest inRequest) { Query q = getEntityManager().createQuery( "from OAuthToken t where t.consumer.serviceProviderName = :serviceName" + " and t.consumer.gadgetUrl = :gadgetUrl and t.viewerId = :viewerId and t.ownerId = :ownerId") .setParameter("serviceName", inRequest.getConsumer().getServiceProviderName()).setParameter( "gadgetUrl", inRequest.getConsumer().getGadgetUrl()).setParameter("viewerId", inRequest.getViewerId()).setParameter("ownerId", inRequest.getOwnerId()); List results = q.getResultList(); if (results.size() == 0) { return null; } OAuthToken token = (OAuthToken) results.get(0); Long ms = token.getTokenExpireMillis(); if (ms == null || ms == 0 || ms > Calendar.getInstance().getTimeInMillis()) { return token; } else { getEntityManager().remove(token); return null; } }  @Override @SuppressWarnings("unchecked") OAuthToken execute(final OAuthTokenRequest inRequest); }
GetOAuthToken extends ReadMapper<OAuthTokenRequest, OAuthToken> { @Override @SuppressWarnings("unchecked") public OAuthToken execute(final OAuthTokenRequest inRequest) { Query q = getEntityManager().createQuery( "from OAuthToken t where t.consumer.serviceProviderName = :serviceName" + " and t.consumer.gadgetUrl = :gadgetUrl and t.viewerId = :viewerId and t.ownerId = :ownerId") .setParameter("serviceName", inRequest.getConsumer().getServiceProviderName()).setParameter( "gadgetUrl", inRequest.getConsumer().getGadgetUrl()).setParameter("viewerId", inRequest.getViewerId()).setParameter("ownerId", inRequest.getOwnerId()); List results = q.getResultList(); if (results.size() == 0) { return null; } OAuthToken token = (OAuthToken) results.get(0); Long ms = token.getTokenExpireMillis(); if (ms == null || ms == 0 || ms > Calendar.getInstance().getTimeInMillis()) { return token; } else { getEntityManager().remove(token); return null; } }  @Override @SuppressWarnings("unchecked") OAuthToken execute(final OAuthTokenRequest inRequest);  }