@Inject public OAuth2StoreProvider( @Named(OAuth2Module.OAUTH2_REDIRECT_URI) final String globalRedirectUri, @Named(OAuth2Module.OAUTH2_IMPORT) final boolean importFromConfig, @Named(OAuth2Module.OAUTH2_IMPORT_CLEAN) final boolean importClean, final Authority authority, final OAuth2Cache cache, final OAuth2Persister persister, final OAuth2Encrypter encrypter, @Nullable @Named("shindig.contextroot") final String contextRoot, @Named(OAuth2FetcherConfig.OAUTH2_STATE_CRYPTER) final BlobCrypter stateCrypter) { this.store = new BasicOAuth2Store(cache, persister, encrypter, globalRedirectUri, authority, contextRoot, stateCrypter); if (importFromConfig) { try { final OAuth2Persister source = new JSONOAuth2Persister(encrypter, authority, globalRedirectUri, contextRoot); BasicOAuth2Store.runImport(source, persister, importClean); } catch (final OAuth2PersistenceException e) { if (OAuth2Module.LOG.isLoggable()) { OAuth2Module.LOG.log("store init exception", e); } } } try { this.store.init(); } catch (final GadgetException e) { if (OAuth2Module.LOG.isLoggable()) { OAuth2Module.LOG.log("store init exception", e); } } }
protected String getGadgetUri(final String gadgetUri, final String serviceName) throws GadgetException { String ret = gadgetUri; final OAuth2Client client = this.getClient(ret, serviceName); if (client != null) { if (client.isSharedToken()) { ret = client.getClientId() + ':' + client.getServiceName(); } } return ret; }
public OAuth2Token createToken() { final boolean isLogging = BasicOAuth2Store.LOG.isLoggable(); if (isLogging) { BasicOAuth2Store.LOG.entering(BasicOAuth2Store.LOG_CLASS, "createToken"); } final OAuth2Token ret = this.internalCreateToken(); if (isLogging) { BasicOAuth2Store.LOG.exiting(BasicOAuth2Store.LOG_CLASS, "clearCache", ret); } return ret; }
@Test public void testSetTokenForSharedClient() throws Exception { final OAuth2Cache cache = new InMemoryCache(); final OAuth2Persister persister = MockUtils.getDummyPersister(); final OAuth2Encrypter encrypter = MockUtils.getDummyEncrypter(); final BlobCrypter stateCrypter = MockUtils.getDummyStateCrypter(); OAuth2Token token = MockUtils.getAccessToken(); OAuth2Client client = MockUtils.getClient_Code_Confidential(); client.setSharedToken( true ); BasicOAuth2Store mockStore = createMockBuilder( BasicOAuth2Store.class ) .withConstructor( OAuth2Cache.class, OAuth2Persister.class, OAuth2Encrypter.class, String.class, Authority.class, String.class, BlobCrypter.class ) .withArgs( cache, persister, encrypter, MockUtils.REDIRECT_URI, (Authority)null, (String)null, stateCrypter ) .addMockedMethod( "getClient" ) .addMockedMethod( "getToken" ) .createMock(); expect( mockStore.getClient( eq(MockUtils.GADGET_URI1), eq(MockUtils.SERVICE_NAME) ) ).andReturn( client ); expect( mockStore.getToken( eq(token.getGadgetUri()), eq(token.getServiceName()), eq(token.getUser()), eq(token.getScope()), eq(token.getType() ) )).andReturn( token ); replay( mockStore ); mockStore.setToken( token ); verify( mockStore ); } }
final OAuth2Client client = this.getClient(gadgetUri, serviceName); final OAuth2Token accessToken = this.getToken(gadgetUri, serviceName, user, scope, OAuth2Token.Type.ACCESS); final OAuth2Token refreshToken = this.getToken(gadgetUri, serviceName, user, scope, OAuth2Token.Type.REFRESH); ret = newAccessor; this.storeOAuth2Accessor(ret);
final String serviceName = token.getServiceName(); final String processedGadgetUri = this.getGadgetUri(gadgetUri, serviceName); synchronized (token) { token.setGadgetUri(processedGadgetUri); try { final OAuth2Token existingToken = this.getToken(gadgetUri, token.getServiceName(), token.getUser(), token.getScope(), token.getType()); try {
protected static OAuth2Store getDummyStore(final OAuth2Cache cache, final OAuth2Persister persister, final OAuth2Encrypter encrypter, final String globalRedirectUri, final Authority authority, final String contextRoot, final BlobCrypter stateCrypter) { final OAuth2Store store = new BasicOAuth2Store(cache, persister, encrypter, globalRedirectUri, authority, contextRoot, stateCrypter); return store; }
final String processedGadgetUri = this.getGadgetUri(gadgetUri, serviceName); OAuth2Token token = this.cache.getToken(processedGadgetUri, serviceName, user, scope, type); if (token == null) {
@Test public void testSetTokenForSharedClient() throws Exception { final OAuth2Cache cache = new InMemoryCache(); final OAuth2Persister persister = MockUtils.getDummyPersister(); final OAuth2Encrypter encrypter = MockUtils.getDummyEncrypter(); final BlobCrypter stateCrypter = MockUtils.getDummyStateCrypter(); OAuth2Token token = MockUtils.getAccessToken(); OAuth2Client client = MockUtils.getClient_Code_Confidential(); client.setSharedToken( true ); BasicOAuth2Store mockStore = createMockBuilder( BasicOAuth2Store.class ) .withConstructor( OAuth2Cache.class, OAuth2Persister.class, OAuth2Encrypter.class, String.class, Authority.class, String.class, BlobCrypter.class ) .withArgs( cache, persister, encrypter, MockUtils.REDIRECT_URI, (Authority)null, (String)null, stateCrypter ) .addMockedMethod( "getClient" ) .addMockedMethod( "getToken" ) .createMock(); expect( mockStore.getClient( eq(MockUtils.GADGET_URI1), eq(MockUtils.SERVICE_NAME) ) ).andReturn( client ); expect( mockStore.getToken( eq(token.getGadgetUri()), eq(token.getServiceName()), eq(token.getUser()), eq(token.getScope()), eq(token.getType() ) )).andReturn( token ); replay( mockStore ); mockStore.setToken( token ); verify( mockStore ); } }
protected static OAuth2Store getDummyStore(final OAuth2Cache cache, final OAuth2Persister persister, final OAuth2Encrypter encrypter, final String globalRedirectUri, final Authority authority, final String contextRoot, final BlobCrypter stateCrypter) { final OAuth2Store store = new BasicOAuth2Store(cache, persister, encrypter, globalRedirectUri, authority, contextRoot, stateCrypter); return store; }
synchronized (token) { final String origGadgetApi = token.getGadgetUri(); final String processedGadgetUri = this.getGadgetUri(token.getGadgetUri(), token.getServiceName()); token.setGadgetUri(processedGadgetUri); try {