~s-friedemann/tomdroid/sshfs

« back to all changes in this revision

Viewing changes to lib/signpost/signpost-core/src/main/java/oauth/signpost/signature/OAuthMessageSigner.java

  • Committer: Guilherme Salgado
  • Date: 2010-08-31 21:44:24 UTC
  • mfrom: (185.1.51 sync-ui)
  • mto: (185.1.54 sync-ui)
  • mto: This revision was merged to the branch mainline in revision 186.
  • Revision ID: salgado@canonical.com-20100831214424-06b64zz707lwpmcl
mergeĀ lp:~tomdroid-developers/sync-ui

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2009 Matthias Kaeppler
2
 
 *
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
6
 
 *
7
 
 *     http://www.apache.org/licenses/LICENSE-2.0
8
 
 *
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.
14
 
 */
15
 
package oauth.signpost.signature;
16
 
 
17
 
import java.io.IOException;
18
 
import java.io.Serializable;
19
 
import java.util.Map;
20
 
 
21
 
import oauth.signpost.exception.OAuthMessageSignerException;
22
 
import oauth.signpost.http.HttpRequest;
23
 
 
24
 
import org.apache.commons.codec.binary.Base64;
25
 
 
26
 
public abstract class OAuthMessageSigner implements Serializable {
27
 
 
28
 
    private transient Base64 base64;
29
 
 
30
 
    private String consumerSecret;
31
 
 
32
 
    private String tokenSecret;
33
 
 
34
 
    public static OAuthMessageSigner create(SignatureMethod signatureMethod) {
35
 
 
36
 
        switch (signatureMethod) {
37
 
 
38
 
        case PLAINTEXT:
39
 
            return new PlainTextMessageSigner();
40
 
 
41
 
        case HMAC_SHA1:
42
 
            return new HmacSha1MessageSigner();
43
 
        }
44
 
 
45
 
        return null;
46
 
    }
47
 
 
48
 
    public OAuthMessageSigner() {
49
 
        this.base64 = new Base64();
50
 
    }
51
 
 
52
 
    public abstract String sign(HttpRequest request,
53
 
            Map<String, String> oauthParameters)
54
 
            throws OAuthMessageSignerException;
55
 
 
56
 
    protected String getConsumerSecret() {
57
 
        return consumerSecret;
58
 
    }
59
 
 
60
 
    public String getTokenSecret() {
61
 
        return tokenSecret;
62
 
    }
63
 
 
64
 
    public void setConsumerSecret(String consumerSecret) {
65
 
        this.consumerSecret = consumerSecret;
66
 
    }
67
 
 
68
 
    public void setTokenSecret(String tokenSecret) {
69
 
        this.tokenSecret = tokenSecret;
70
 
    }
71
 
 
72
 
    protected byte[] decodeBase64(String s) {
73
 
        return base64.decode(s.getBytes());
74
 
    }
75
 
 
76
 
    protected String base64Encode(byte[] b) {
77
 
        return new String(base64.encode(b));
78
 
    }
79
 
 
80
 
    protected String computeSignatureBaseString(HttpRequest request,
81
 
            Map<String, String> oauthParameters)
82
 
            throws OAuthMessageSignerException {
83
 
        SignatureBaseString sbs = new SignatureBaseString(request,
84
 
                oauthParameters);
85
 
        return sbs.compute();
86
 
    }
87
 
 
88
 
    private void readObject(java.io.ObjectInputStream stream)
89
 
            throws IOException, ClassNotFoundException {
90
 
        stream.defaultReadObject();
91
 
        this.base64 = new Base64();
92
 
    }
93
 
}