本文整理汇总了Java中org.springframework.security.oauth.consumer.ProtectedResourceDetails类的典型用法代码示例。如果您正苦于以下问题:Java ProtectedResourceDetails类的具体用法?Java ProtectedResourceDetails怎么用?Java ProtectedResourceDetails使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProtectedResourceDetails类属于org.springframework.security.oauth.consumer包,在下文中一共展示了ProtectedResourceDetails类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetRestTemplate_ReturnsOauthTemplate
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
@Test
public void testGetRestTemplate_ReturnsOauthTemplate() throws Exception {
//When
RestTemplate restTemplate = userSyncRestTemplateFactory.getOAuthRestTemplate("some-key", "some-secret");
//Then
assertThat(restTemplate).isInstanceOf(OAuthRestTemplate.class);
OAuthRestTemplate oauthRestTemplate = (OAuthRestTemplate) restTemplate;
//Then
ProtectedResourceDetails resource = oauthRestTemplate.getResource();
assertThat(resource.getConsumerKey()).isEqualTo("some-key");
assertThat(resource.getSharedSecret())
.isInstanceOf(SharedConsumerSecretImpl.class)
.hasFieldOrPropertyWithValue("consumerSecret", "some-secret");
}
示例2: getUnauthorizedRequestToken
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public OAuthConsumerToken getUnauthorizedRequestToken(ProtectedResourceDetails details, String callback) throws OAuthRequestFailedException {
URL requestTokenURL;
try {
requestTokenURL = new URL(details.getRequestTokenURL());
}
catch (MalformedURLException e) {
throw new IllegalStateException("Malformed URL for obtaining a request token.", e);
}
String httpMethod = details.getRequestTokenHttpMethod();
Map<String, String> additionalParameters = new TreeMap<String, String>();
if (details.isUse10a()) {
additionalParameters.put(OAuthConsumerParameter.oauth_callback.toString(), callback);
}
Map<String, String> specifiedParams = details.getAdditionalParameters();
if (specifiedParams != null) {
additionalParameters.putAll(specifiedParams);
}
return getTokenFromProvider(details, requestTokenURL, httpMethod, null, additionalParameters);
}
示例3: getAccessToken
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public OAuthConsumerToken getAccessToken(ProtectedResourceDetails details, OAuthConsumerToken requestToken, String verifier) {
URL accessTokenURL;
try {
accessTokenURL = new URL(details.getAccessTokenURL());
}
catch (MalformedURLException e) {
throw new IllegalStateException("Malformed URL for obtaining an access token.", e);
}
String httpMethod = details.getAccessTokenHttpMethod();
Map<String, String> additionalParameters = new TreeMap<String, String>();
if (details.isUse10a()) {
if (verifier == null) {
throw new UnverifiedRequestTokenException("Unverified request token: " + requestToken);
}
additionalParameters.put(OAuthConsumerParameter.oauth_verifier.toString(), verifier);
}
Map<String, String> specifiedParams = details.getAdditionalParameters();
if (specifiedParams != null) {
additionalParameters.putAll(specifiedParams);
}
return getTokenFromProvider(details, accessTokenURL, httpMethod, requestToken, additionalParameters);
}
示例4: getUserAuthorizationRedirectURL
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
/**
* Get the URL to which to redirect the user for authorization of protected resources.
*
* @param details The resource for which to get the authorization url.
* @param requestToken The request token.
* @param callbackURL The callback URL.
* @return The URL.
*/
protected String getUserAuthorizationRedirectURL(ProtectedResourceDetails details, OAuthConsumerToken requestToken, String callbackURL) {
try {
String baseURL = details.getUserAuthorizationURL();
StringBuilder builder = new StringBuilder(baseURL);
char appendChar = baseURL.indexOf('?') < 0 ? '?' : '&';
builder.append(appendChar).append("oauth_token=");
builder.append(URLEncoder.encode(requestToken.getValue(), "UTF-8"));
if (!details.isUse10a()) {
builder.append('&').append("oauth_callback=");
builder.append(URLEncoder.encode(callbackURL, "UTF-8"));
}
return builder.toString();
}
catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
示例5: readProtectedResource
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public InputStream readProtectedResource(URL url, OAuthConsumerToken accessToken, String httpMethod) throws OAuthRequestFailedException {
if (accessToken == null) {
throw new OAuthRequestFailedException("A valid access token must be supplied.");
}
ProtectedResourceDetails resourceDetails = getProtectedResourceDetailsService().loadProtectedResourceDetailsById(accessToken.getResourceId());
if ((!resourceDetails.isAcceptsAuthorizationHeader()) && !"POST".equalsIgnoreCase(httpMethod) && !"PUT".equalsIgnoreCase(httpMethod)) {
throw new IllegalArgumentException("Protected resource " + resourceDetails.getId() + " cannot be accessed with HTTP method " +
httpMethod + " because the OAuth provider doesn't accept the OAuth Authorization header.");
}
return readResource(resourceDetails, url, httpMethod, accessToken, resourceDetails.getAdditionalParameters(), null);
}
示例6: getAuthorizationHeader
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public String getAuthorizationHeader(ProtectedResourceDetails details, OAuthConsumerToken accessToken, URL url, String httpMethod, Map<String, String> additionalParameters) {
if (!details.isAcceptsAuthorizationHeader()) {
return null;
}
else {
Map<String, Set<CharSequence>> oauthParams = loadOAuthParameters(details, url, accessToken, httpMethod, additionalParameters);
String realm = details.getAuthorizationHeaderRealm();
StringBuilder builder = new StringBuilder("OAuth ");
boolean writeComma = false;
if (realm != null) { //realm is optional.
builder.append("realm=\"").append(realm).append('"');
writeComma = true;
}
for (Map.Entry<String, Set<CharSequence>> paramValuesEntry : oauthParams.entrySet()) {
Set<CharSequence> paramValues = paramValuesEntry.getValue();
CharSequence paramValue = findValidHeaderValue(paramValues);
if (paramValue != null) {
if (writeComma) {
builder.append(", ");
}
builder.append(paramValuesEntry.getKey()).append("=\"").append(oauthEncode(paramValue.toString())).append('"');
writeComma = true;
}
}
return builder.toString();
}
}
示例7: OAuthRestTemplate
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public OAuthRestTemplate(ClientHttpRequestFactory requestFactory, ProtectedResourceDetails resource) {
super();
if (resource == null) {
throw new IllegalArgumentException("An OAuth resource must be supplied.");
}
if (support == null) {
throw new IllegalArgumentException("OAuth support must be supplied.");
}
this.resource = resource;
setRequestFactory(requestFactory);
}
示例8: OAuthClientHttpRequestFactory
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public OAuthClientHttpRequestFactory(ClientHttpRequestFactory delegate, ProtectedResourceDetails resource, OAuthConsumerSupport support) {
this.delegate = delegate;
this.resource = resource;
this.support = support;
if (delegate == null) {
throw new IllegalArgumentException("A delegate must be supplied for an OAuth2ClientHttpRequestFactory.");
}
if (resource == null) {
throw new IllegalArgumentException("A resource must be supplied for an OAuth2ClientHttpRequestFactory.");
}
}
示例9: OAuthOverHttpsURLStreamHandler
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public OAuthOverHttpsURLStreamHandler(ProtectedResourceDetails resourceDetails, OAuthConsumerToken accessToken, OAuthConsumerSupport support, String httpMethod, Map<String, String> additionalParameters) {
this.resourceDetails = resourceDetails;
this.accessToken = accessToken;
this.support = support;
this.httpMethod = httpMethod;
this.additionalParameters = additionalParameters;
}
示例10: OAuthOverHttpURLStreamHandler
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public OAuthOverHttpURLStreamHandler(ProtectedResourceDetails resourceDetails, OAuthConsumerToken accessToken, OAuthConsumerSupport support, String httpMethod, Map<String, String> additionalParameters) {
this.resourceDetails = resourceDetails;
this.accessToken = accessToken;
this.support = support;
this.httpMethod = httpMethod;
this.additionalParameters = additionalParameters;
}
示例11: checkForResourceThatNeedsAuthorization
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
/**
* Check the given exception for the resource that needs authorization. If the exception was not thrown because a resource needed authorization, then rethrow
* the exception.
*
* @param ex The exception.
* @return The resource that needed authorization (never null).
*/
protected ProtectedResourceDetails checkForResourceThatNeedsAuthorization(Exception ex) throws ServletException, IOException {
Throwable[] causeChain = getThrowableAnalyzer().determineCauseChain(ex);
AccessTokenRequiredException ase = (AccessTokenRequiredException) getThrowableAnalyzer().getFirstThrowableOfType(AccessTokenRequiredException.class, causeChain);
ProtectedResourceDetails resourceThatNeedsAuthorization;
if (ase != null) {
resourceThatNeedsAuthorization = ase.getResource();
if (resourceThatNeedsAuthorization == null) {
throw new OAuthRequestFailedException(ase.getMessage());
}
}
else {
// Rethrow ServletExceptions and RuntimeExceptions as-is
if (ex instanceof ServletException) {
throw (ServletException) ex;
}
if (ex instanceof IOException) {
throw (IOException) ex;
}
else if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
}
// Wrap other Exceptions. These are not expected to happen
throw new RuntimeException(ex);
}
return resourceThatNeedsAuthorization;
}
示例12: createInstance
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
@Override
protected ProtectedResourceDetailsService createInstance() throws Exception {
Map<String, ProtectedResourceDetails> detailsMap = BeanFactoryUtils.beansOfTypeIncludingAncestors((ListableBeanFactory) getBeanFactory(),
ProtectedResourceDetails.class);
InMemoryProtectedResourceDetailsService service = new InMemoryProtectedResourceDetailsService();
service.setResourceDetailsStore(detailsMap);
return service;
}
示例13: testGetAuthorizationHeader
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
/**
* test getAuthorizationHeader
*/
@Test
public void testGetAuthorizationHeader() throws Exception {
final TreeMap<String, Set<CharSequence>> params = new TreeMap<String, Set<CharSequence>>();
CoreOAuthConsumerSupport support = new CoreOAuthConsumerSupport() {
@Override
protected Map<String, Set<CharSequence>> loadOAuthParameters(ProtectedResourceDetails details,
URL requestURL, OAuthConsumerToken requestToken, String httpMethod,
Map<String, String> additionalParameters) {
return params;
}
};
URL url = new URL("https://myhost.com/somepath?with=some&query=params&too");
OAuthConsumerToken token = new OAuthConsumerToken();
when(details.isAcceptsAuthorizationHeader()).thenReturn(false);
assertNull(support.getAuthorizationHeader(details, token, url, "POST", null));
params.put("with", Collections.singleton((CharSequence) "some"));
params.put("query", Collections.singleton((CharSequence) "params"));
params.put("too", null);
when(details.isAcceptsAuthorizationHeader()).thenReturn(true);
when(details.getAuthorizationHeaderRealm()).thenReturn("myrealm");
assertEquals("OAuth realm=\"myrealm\", query=\"params\", with=\"some\"",
support.getAuthorizationHeader(details, token, url, "POST", null));
params.put(OAuthConsumerParameter.oauth_consumer_key.toString(), Collections.singleton((CharSequence) "mykey"));
params.put(OAuthConsumerParameter.oauth_nonce.toString(), Collections.singleton((CharSequence) "mynonce"));
params.put(OAuthConsumerParameter.oauth_timestamp.toString(), Collections.singleton((CharSequence) "myts"));
when(details.isAcceptsAuthorizationHeader()).thenReturn(true);
when(details.getAuthorizationHeaderRealm()).thenReturn("myrealm");
assertEquals(
"OAuth realm=\"myrealm\", oauth_consumer_key=\"mykey\", oauth_nonce=\"mynonce\", oauth_timestamp=\"myts\", query=\"params\", with=\"some\"",
support.getAuthorizationHeader(details, token, url, "POST", null));
}
示例14: getResource
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public ProtectedResourceDetails getResource() {
return resource;
}
示例15: getHttpStreamHandler
import org.springframework.security.oauth.consumer.ProtectedResourceDetails; //导入依赖的package包/类
public URLStreamHandler getHttpStreamHandler(ProtectedResourceDetails resourceDetails, OAuthConsumerToken accessToken, OAuthConsumerSupport support, String httpMethod, Map<String, String> additionalParameters) {
return new OAuthOverHttpURLStreamHandler(resourceDetails, accessToken, support, httpMethod, additionalParameters);
}