This repository has been archived by the owner on Apr 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial steps toward breaking Spring Social into more cohesive submod…
…ules
- Loading branch information
Showing
34 changed files
with
2,108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# | ||
#Wed Nov 17 09:24:37 CST 2010 | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.compliance=1.5 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.source=1.5 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
31 changes: 31 additions & 0 deletions
31
...social-oauth/src/main/java/org/springframework/social/oauth/OAuthClientRequestSigner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2010 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.oauth; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.http.client.ClientHttpRequest; | ||
|
||
/** | ||
* Strategy interface for signing a client request with the necessary | ||
* information for it to be OAuth-authenticated. Implementations of this | ||
* interface will vary for different versions of OAuth. | ||
* | ||
* @author Craig Walls | ||
*/ | ||
public interface OAuthClientRequestSigner { | ||
void sign(ClientHttpRequest request, Map<String, String> bodyParameters); | ||
} |
84 changes: 84 additions & 0 deletions
84
...l-oauth/src/main/java/org/springframework/social/oauth/OAuthSigningClientHttpRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2010 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.oauth; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.AbstractClientHttpRequest; | ||
import org.springframework.http.client.ClientHttpRequest; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
|
||
/** | ||
* Implementation of {@link ClientHttpRequest} that wraps another | ||
* {@link ClientHttpRequest} and signs it with an OAuth | ||
* <code>Authorization</code> header before it is sent. | ||
* | ||
* @author Craig Walls | ||
*/ | ||
public class OAuthSigningClientHttpRequest extends AbstractClientHttpRequest { | ||
private final ClientHttpRequest delegate; | ||
private final OAuthClientRequestSigner signer; | ||
|
||
/** | ||
* Creates an {@link OAuthSigningClientHttpRequest}. | ||
* | ||
* @param delegate | ||
* The wrapped {@link ClientHttpRequest} that is to be signed | ||
* @param signer | ||
* An OAuth signer | ||
*/ | ||
public OAuthSigningClientHttpRequest(ClientHttpRequest delegate, OAuthClientRequestSigner signer) { | ||
this.delegate = delegate; | ||
this.signer = signer; | ||
} | ||
|
||
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException { | ||
Map<String, String> bodyParameters = extractBodyParameters(headers.getContentType(), bufferedOutput); | ||
signer.sign(delegate, bodyParameters); | ||
delegate.getBody().write(bufferedOutput); | ||
delegate.getHeaders().putAll(headers); | ||
return delegate.execute(); | ||
} | ||
|
||
private Map<String, String> extractBodyParameters(MediaType bodyType, byte[] bodyBytes) { | ||
Map<String, String> params = new HashMap<String, String>(); | ||
|
||
if (bodyType != null && bodyType.equals(MediaType.APPLICATION_FORM_URLENCODED)) { | ||
String[] paramPairs = new String(bodyBytes).split("&"); | ||
for (String pair : paramPairs) { | ||
String[] keyValue = pair.split("="); | ||
if (keyValue.length == 2) { | ||
params.put(keyValue[0], keyValue[1]); | ||
} | ||
} | ||
} | ||
return params; | ||
} | ||
|
||
public URI getURI() { | ||
return delegate.getURI(); | ||
} | ||
|
||
public HttpMethod getMethod() { | ||
return delegate.getMethod(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../src/main/java/org/springframework/social/oauth/OAuthSigningClientHttpRequestFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2010 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.oauth; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
|
||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.client.ClientHttpRequest; | ||
import org.springframework.http.client.ClientHttpRequestFactory; | ||
|
||
/** | ||
* An implementation of {@link ClientHttpRequestFactory} that creates an | ||
* {@link OAuthSigningClientHttpRequest} so that the request can be signed with | ||
* an OAuth <code>Authorization</code> header. | ||
* | ||
* @author Craig Walls | ||
*/ | ||
public class OAuthSigningClientHttpRequestFactory implements ClientHttpRequestFactory { | ||
private final OAuthClientRequestSigner signer; | ||
private final ClientHttpRequestFactory delegate; | ||
|
||
public OAuthSigningClientHttpRequestFactory(ClientHttpRequestFactory delegate, OAuthClientRequestSigner signer) { | ||
this.delegate = delegate; | ||
this.signer = signer; | ||
} | ||
|
||
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { | ||
return new OAuthSigningClientHttpRequest(delegate.createRequest(uri, httpMethod), signer); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
spring-social-oauth/src/main/java/org/springframework/social/oauth/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Core classes for signing requests with OAuth | ||
*/ | ||
package org.springframework.social.oauth; |
29 changes: 29 additions & 0 deletions
29
...l-oauth/src/main/java/org/springframework/social/oauth1/MissingOAuthLibraryException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2010 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.oauth1; | ||
|
||
import org.springframework.social.core.SocialException; | ||
|
||
/** | ||
* @author Craig Walls | ||
*/ | ||
public class MissingOAuthLibraryException extends SocialException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public MissingOAuthLibraryException(String message) { | ||
super(message); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...cial-oauth/src/main/java/org/springframework/social/oauth1/OAuth1ClientRequestSigner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2010 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.oauth1; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URI; | ||
import java.net.URLDecoder; | ||
import java.util.Map; | ||
|
||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.client.ClientHttpRequest; | ||
import org.springframework.social.oauth.OAuthClientRequestSigner; | ||
|
||
/** | ||
* Abstract implementation of {@link OAuthClientRequestSigner} that adds an | ||
* OAuth 1 Authorization header to the request. Concrete implementations will | ||
* generate the Authorization header by implementing the | ||
* buildAuthorizationHeader() method. | ||
* | ||
* @author Craig Walls | ||
*/ | ||
public abstract class OAuth1ClientRequestSigner implements OAuthClientRequestSigner { | ||
|
||
public void sign(ClientHttpRequest request, Map<String, String> bodyParameters) { | ||
String authorizationHeader = buildAuthorizationHeader(request.getMethod(), request.getURI(), bodyParameters); | ||
if (authorizationHeader != null) { | ||
request.getHeaders().add("Authorization", authorizationHeader); | ||
} | ||
} | ||
|
||
protected String decode(String encoded) { | ||
try { | ||
return URLDecoder.decode(encoded, "UTF-8"); | ||
} catch (UnsupportedEncodingException shouldntHappen) { | ||
return encoded; | ||
} | ||
} | ||
|
||
protected abstract String buildAuthorizationHeader(HttpMethod method, URI url, Map<String, String> parameters); | ||
} |
Oops, something went wrong.