@Test public void testSetClientSecret_2() throws Exception { final OAuth2Client fixture = new OAuth2Client(MockUtils.getDummyEncrypter()); fixture.setAuthorizationUrl(""); fixture.setClientAuthenticationType(""); fixture.setServiceName(""); fixture.setRedirectUri(""); fixture.setGrantType(""); fixture.setEncryptedSecret(new byte[] {}); fixture.setAllowModuleOverride(true); fixture.setAuthorizationHeader(true); fixture.setTokenUrl(""); fixture.setGadgetUri(""); fixture.setType(org.apache.shindig.gadgets.oauth2.OAuth2Accessor.Type.CONFIDENTIAL); fixture.setUrlParameter(true); fixture.setClientSecret(new byte[] {}); fixture.setClientId(""); final byte[] secret = new byte[] {}; fixture.setClientSecret(secret); }
@Override public OAuth2Client clone() { final OAuth2Client ret = new OAuth2Client(this.encrypter); ret.setAllowModuleOverride(this.allowModuleOverride); ret.setAuthorizationHeader(this.authorizationHeader); ret.setAuthorizationUrl(this.authorizationUrl); ret.setClientAuthenticationType(this.clientAuthenticationType); ret.setClientId(this.clientId); try { ret.setClientSecret(this.clientSecret); } catch (final OAuth2EncryptionException e) { // no op } ret.setGadgetUri(this.gadgetUri); ret.setGrantType(this.grantType); ret.setRedirectUri(this.redirectUri); ret.setServiceName(this.serviceName); ret.setSharedToken(this.sharedToken); ret.setTokenUrl(this.tokenUrl); ret.setType(this.type); ret.setUrlParameter(this.urlParameter); ret.setAllowedDomains(this.getAllowedDomains()); return ret; } }
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; }
protected String getClientKey(final OAuth2Client client) { return this.getClientKey(client.getGadgetUri(), client.getServiceName()); }
user, scope, client.isAllowModuleOverride(), this, this.globalRedirectUri, this.authority, this.contextRoot); newAccessor.setAccessToken(accessToken); newAccessor.setAuthorizationUrl(client.getAuthorizationUrl()); newAccessor.setClientAuthenticationType(client.getClientAuthenticationType()); newAccessor.setAuthorizationHeader(client.isAuthorizationHeader()); newAccessor.setUrlParameter(client.isUrlParameter()); newAccessor.setClientId(client.getClientId()); newAccessor.setClientSecret(client.getClientSecret()); newAccessor.setGrantType(client.getGrantType()); newAccessor.setRedirectUri(client.getRedirectUri()); newAccessor.setRefreshToken(refreshToken); newAccessor.setTokenUrl(client.getTokenUrl()); newAccessor.setType(client.getType()); newAccessor.setAllowedDomains(client.getAllowedDomains()); ret = newAccessor;
@Test public void testOAuth2Client_1() throws Exception { final OAuth2Client result = new OAuth2Client(MockUtils.getDummyEncrypter()); Assert.assertNotNull(result); Assert.assertEquals(null, result.getAuthorizationUrl()); Assert.assertEquals(null, result.getClientAuthenticationType()); Assert.assertEquals(null, result.getClientId()); Assert.assertEquals(null, result.getClientSecret()); Assert.assertEquals(null, result.getEncryptedSecret()); Assert.assertEquals(null, result.getGadgetUri()); Assert.assertEquals("NONE", result.getGrantType()); Assert.assertEquals(null, result.getRedirectUri()); Assert.assertEquals(null, result.getServiceName()); Assert.assertEquals(null, result.getTokenUrl()); Assert.assertEquals(false, result.isAllowModuleOverride()); Assert.assertEquals(false, result.isAuthorizationHeader()); Assert.assertEquals(false, result.isUrlParameter()); Assert .assertEquals( "org.apache.shindig.gadgets.oauth2.persistence.sample.OAuth2ClientImpl: serviceName = null , redirectUri = null , gadgetUri = null , clientId = null , grantType = NONE , type = UNKNOWN , grantType = NONE , tokenUrl = null , authorizationUrl = null , this.clientAuthenticationType = null , this.sharedToken = false, this.allowedDomains = []", result.toString()); }
final OAuth2Client client = new OAuth2Client(this.encrypter); client.setAuthorizationUrl(provider.getAuthorizationUrl()); client.setClientAuthenticationType(provider.getClientAuthenticationType()); client.setAuthorizationHeader(provider.isAuthorizationHeader()); client.setUrlParameter(provider.isUrlParameter()); client.setTokenUrl(provider.getTokenUrl()); final String sharedToken = settings.optString(OAuth2Message.SHARED_TOKEN, "false"); if ("true".equalsIgnoreCase(sharedToken)) { client.setSharedToken(true); client.setEncryptedSecret(secret.getBytes("UTF-8")); } catch (final OAuth2EncryptionException e) { throw new OAuth2PersistenceException(e); client.setClientId(clientId); client.setRedirectUri(redirectUri); client.setGrantType(grantType); client.setType(type); client.setAllowedDomains(domains.toArray(new String[0])); final String clientName = binding.getClientName(); final OAuth2Client cachedClient = internalMap.get(clientName); final OAuth2Client client = cachedClient.clone();
protected static OAuth2Client getClient_Code_Public() throws Exception { final OAuth2Client client = new OAuth2Client(MockUtils.getDummyEncrypter()); MockUtils.setClientCommons(client); client.setClientAuthenticationType(OAuth2Message.STANDARD_AUTH_TYPE); client.setClientId(MockUtils.CLIENT_ID2); client.setClientSecret(MockUtils.CLIENT_SECRET2.getBytes("UTF-8")); client.setGadgetUri(MockUtils.GADGET_URI2); client.setType(OAuth2Accessor.Type.PUBLIC); client.setAllowModuleOverride(false); client.setAuthorizationHeader(false); client.setUrlParameter(true); return client; }
@Test public void testStoreClient_1() throws Exception { OAuth2Client client = new OAuth2Client(MockUtils.getDummyEncrypter()); client.setGadgetUri("xxx"); client.setServiceName("yyy"); this.cache.storeClient(client); client = this.cache.getClient(client.getGadgetUri(), client.getServiceName()); Assert.assertNotNull(client); Assert.assertEquals("xxx", client.getGadgetUri()); Assert.assertEquals("yyy", client.getServiceName()); }
@Test public void testGetClientId_1() throws Exception { final String result = OAuth2ClientTest.client1.getClientId(); Assert.assertNotNull(result); Assert.assertEquals(MockUtils.CLIENT_ID1, result); }
@Test public void testGetClientSecret_1() throws Exception { final byte[] result = OAuth2ClientTest.client1.getClientSecret(); Assert.assertNotNull(result); Assert.assertEquals(MockUtils.CLIENT_SECRET1, new String(result, "UTF-8")); }
@Test public void testGetAuthorizationUrl_1() throws Exception { final String result = OAuth2ClientTest.client1.getAuthorizationUrl(); Assert.assertNotNull(result); Assert.assertEquals(MockUtils.AUTHORIZE_URL, result); }
@Test public void testGetClientAuthenticationType_1() throws Exception { final String result = OAuth2ClientTest.client1.getClientAuthenticationType(); Assert.assertNotNull(result); Assert.assertEquals(OAuth2Message.BASIC_AUTH_TYPE, result); }
@Test public void testGetRedirectUri_1() throws Exception { final String result = OAuth2ClientTest.client1.getRedirectUri(); Assert.assertNotNull(result); Assert.assertEquals(MockUtils.REDIRECT_URI, result); }
@Test public void testGetServiceName_1() throws Exception { final String result = OAuth2ClientTest.client1.getServiceName(); Assert.assertNotNull(result); Assert.assertEquals(MockUtils.SERVICE_NAME, result); }
@Test public void testGetGrantType_1() throws Exception { final String result = OAuth2ClientTest.client1.getGrantType(); Assert.assertNotNull(result); Assert.assertEquals(OAuth2Message.AUTHORIZATION_CODE, result); }
@Test public void testGetGadgetUri_1() throws Exception { final String result = OAuth2ClientTest.client1.getGadgetUri(); Assert.assertNotNull(result); Assert.assertEquals(MockUtils.GADGET_URI1, result); }
final String gadgetUri = client.getGadgetUri(); Assert.assertNotNull(gadgetUri); final boolean goodClient = gadgetUri.equals(MockUtils.GADGET_URI1) Assert.assertTrue(goodClient); if (gadgetUri.equals(MockUtils.GADGET_URI1)) { Assert.assertEquals(MockUtils.AUTHORIZE_URL, client.getAuthorizationUrl()); Assert.assertEquals(OAuth2Message.BASIC_AUTH_TYPE, client.getClientAuthenticationType()); Assert.assertEquals(MockUtils.CLIENT_ID1, client.getClientId()); Assert.assertEquals(MockUtils.CLIENT_SECRET1, new String(client.getClientSecret(), "UTF-8")); Assert.assertEquals(MockUtils.getDummyEncrypter(), client.getEncrypter()); Assert.assertEquals(OAuth2Message.AUTHORIZATION, client.getGrantType()); Assert.assertEquals(MockUtils.REDIRECT_URI, client.getRedirectUri()); Assert.assertEquals(MockUtils.SERVICE_NAME, client.getServiceName()); Assert.assertEquals(MockUtils.TOKEN_URL, client.getTokenUrl()); Assert.assertEquals(OAuth2Accessor.Type.CONFIDENTIAL, client.getType()); Assert.assertEquals(true, client.isAllowModuleOverride()); Assert.assertEquals(true, client.isAuthorizationHeader()); Assert.assertEquals(false, client.isUrlParameter()); Assert.assertArrayEquals(new String[] { "example.com", "ibm.com" }, client.getAllowedDomains()); } else if (gadgetUri.equals(MockUtils.GADGET_URI2)) { Assert.assertEquals(MockUtils.AUTHORIZE_URL, client.getAuthorizationUrl()); Assert.assertEquals(OAuth2Message.STANDARD_AUTH_TYPE, client.getClientAuthenticationType()); Assert.assertEquals(MockUtils.CLIENT_ID2, client.getClientId()); Assert.assertEquals(MockUtils.CLIENT_SECRET2, new String(client.getClientSecret(), "UTF-8")); Assert.assertEquals(MockUtils.getDummyEncrypter(), client.getEncrypter()); Assert.assertEquals(OAuth2Message.CLIENT_CREDENTIALS, client.getGrantType()); Assert.assertEquals(MockUtils.REDIRECT_URI, client.getRedirectUri());
@Test public void testOAuth2Client_1() throws Exception { final OAuth2Client result = new OAuth2Client(MockUtils.getDummyEncrypter()); Assert.assertNotNull(result); Assert.assertEquals(null, result.getAuthorizationUrl()); Assert.assertEquals(null, result.getClientAuthenticationType()); Assert.assertEquals(null, result.getClientId()); Assert.assertEquals(null, result.getClientSecret()); Assert.assertEquals(null, result.getEncryptedSecret()); Assert.assertEquals(null, result.getGadgetUri()); Assert.assertEquals("NONE", result.getGrantType()); Assert.assertEquals(null, result.getRedirectUri()); Assert.assertEquals(null, result.getServiceName()); Assert.assertEquals(null, result.getTokenUrl()); Assert.assertEquals(false, result.isAllowModuleOverride()); Assert.assertEquals(false, result.isAuthorizationHeader()); Assert.assertEquals(false, result.isUrlParameter()); Assert .assertEquals( "org.apache.shindig.gadgets.oauth2.persistence.sample.OAuth2ClientImpl: serviceName = null , redirectUri = null , gadgetUri = null , clientId = null , grantType = NONE , type = UNKNOWN , grantType = NONE , tokenUrl = null , authorizationUrl = null , this.clientAuthenticationType = null , this.sharedToken = false, this.allowedDomains = []", result.toString()); }
protected static OAuth2Client getClient_Code_Confidential() throws Exception { final OAuth2Client client = new OAuth2Client(MockUtils.getDummyEncrypter()); MockUtils.setClientCommons(client); client.setClientAuthenticationType(OAuth2Message.BASIC_AUTH_TYPE); client.setClientId(MockUtils.CLIENT_ID1); client.setClientSecret(MockUtils.CLIENT_SECRET1.getBytes("UTF-8")); client.setGadgetUri(MockUtils.GADGET_URI1); client.setType(OAuth2Accessor.Type.CONFIDENTIAL); client.setAllowModuleOverride(true); client.setAuthorizationHeader(true); client.setUrlParameter(false); return client; }