當前位置: 首頁>>代碼示例>>Java>>正文


Java SharedConsumerSecret類代碼示例

本文整理匯總了Java中org.springframework.security.oauth.common.signature.SharedConsumerSecret的典型用法代碼示例。如果您正苦於以下問題:Java SharedConsumerSecret類的具體用法?Java SharedConsumerSecret怎麽用?Java SharedConsumerSecret使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SharedConsumerSecret類屬於org.springframework.security.oauth.common.signature包,在下文中一共展示了SharedConsumerSecret類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testLoadOAuthParameters

import org.springframework.security.oauth.common.signature.SharedConsumerSecret; //導入依賴的package包/類
/**
 * loadOAuthParameters
 */
@Test
public void testLoadOAuthParameters() throws Exception {
	URL url = new URL("https://myhost.com/somepath?with=some&query=params&too");
	CoreOAuthConsumerSupport support = new CoreOAuthConsumerSupport() {
		@Override
		protected String getSignatureBaseString(Map<String, Set<CharSequence>> oauthParams, URL requestURL,
				String httpMethod) {
			return "MYSIGBASESTRING";
		}
	};
	OAuthSignatureMethodFactory sigFactory = mock(OAuthSignatureMethodFactory.class);
	support.setSignatureFactory(sigFactory);
	OAuthConsumerToken token = new OAuthConsumerToken();
	OAuthSignatureMethod sigMethod = mock(OAuthSignatureMethod.class);

	when(details.getConsumerKey()).thenReturn("my-consumer-key");
	when(details.getSignatureMethod()).thenReturn(HMAC_SHA1SignatureMethod.SIGNATURE_NAME);
	when(details.getSignatureMethod()).thenReturn(HMAC_SHA1SignatureMethod.SIGNATURE_NAME);
	SharedConsumerSecret secret = new SharedConsumerSecretImpl("shh!!!");
	when(details.getSharedSecret()).thenReturn(secret);
	when(sigFactory.getSignatureMethod(HMAC_SHA1SignatureMethod.SIGNATURE_NAME, secret, null))
			.thenReturn(sigMethod);
	when(sigMethod.sign("MYSIGBASESTRING")).thenReturn("MYSIGNATURE");

	Map<String, Set<CharSequence>> params = support.loadOAuthParameters(details, url, token, "POST", null);
	assertEquals("some", params.remove("with").iterator().next().toString());
	assertEquals("params", params.remove("query").iterator().next().toString());
	assertTrue(params.containsKey("too"));
	assertTrue(params.remove("too").isEmpty());
	assertNull(params.remove(OAuthConsumerParameter.oauth_token.toString()));
	assertNotNull(params.remove(OAuthConsumerParameter.oauth_nonce.toString()).iterator().next());
	assertEquals("my-consumer-key", params.remove(OAuthConsumerParameter.oauth_consumer_key.toString()).iterator()
			.next());
	assertEquals("MYSIGNATURE", params.remove(OAuthConsumerParameter.oauth_signature.toString()).iterator().next());
	assertEquals("1.0", params.remove(OAuthConsumerParameter.oauth_version.toString()).iterator().next());
	assertEquals(HMAC_SHA1SignatureMethod.SIGNATURE_NAME,
			params.remove(OAuthConsumerParameter.oauth_signature_method.toString()).iterator().next());
	assertTrue(Long.parseLong(params.remove(OAuthConsumerParameter.oauth_timestamp.toString()).iterator().next()
			.toString()) <= (System.currentTimeMillis() / 1000));
	assertTrue(params.isEmpty());
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:45,代碼來源:CoreOAuthConsumerSupportTests.java

示例2: testClientDetailsFromPropertyFile

import org.springframework.security.oauth.common.signature.SharedConsumerSecret; //導入依賴的package包/類
@Test
public void testClientDetailsFromPropertyFile() {
	ConsumerDetails consumer = clientDetailsService.loadConsumerByConsumerKey("my-client-key");
	assertNotNull(consumer);
	assertEquals("my-client-secret", ((SharedConsumerSecret)consumer.getSignatureSecret()).getConsumerSecret());
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:7,代碼來源:FilterChainInitializationTests.java


注:本文中的org.springframework.security.oauth.common.signature.SharedConsumerSecret類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。