1
/* Copyright (c) 2009 Matthias Kaeppler
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
15
package oauth.signpost.signature;
17
import java.io.IOException;
18
import java.io.Serializable;
21
import oauth.signpost.exception.OAuthMessageSignerException;
22
import oauth.signpost.http.HttpRequest;
24
import org.apache.commons.codec.binary.Base64;
26
public abstract class OAuthMessageSigner implements Serializable {
28
private transient Base64 base64;
30
private String consumerSecret;
32
private String tokenSecret;
34
public static OAuthMessageSigner create(SignatureMethod signatureMethod) {
36
switch (signatureMethod) {
39
return new PlainTextMessageSigner();
42
return new HmacSha1MessageSigner();
48
public OAuthMessageSigner() {
49
this.base64 = new Base64();
52
public abstract String sign(HttpRequest request,
53
Map<String, String> oauthParameters)
54
throws OAuthMessageSignerException;
56
protected String getConsumerSecret() {
57
return consumerSecret;
60
public String getTokenSecret() {
64
public void setConsumerSecret(String consumerSecret) {
65
this.consumerSecret = consumerSecret;
68
public void setTokenSecret(String tokenSecret) {
69
this.tokenSecret = tokenSecret;
72
protected byte[] decodeBase64(String s) {
73
return base64.decode(s.getBytes());
76
protected String base64Encode(byte[] b) {
77
return new String(base64.encode(b));
80
protected String computeSignatureBaseString(HttpRequest request,
81
Map<String, String> oauthParameters)
82
throws OAuthMessageSignerException {
83
SignatureBaseString sbs = new SignatureBaseString(request,
88
private void readObject(java.io.ObjectInputStream stream)
89
throws IOException, ClassNotFoundException {
90
stream.defaultReadObject();
91
this.base64 = new Base64();