1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.social.opensocial.auth;
18
19 import java.util.Map;
20
21 import org.apache.shindig.auth.BasicSecurityTokenCodec;
22 import org.apache.shindig.auth.SecurityToken;
23 import org.apache.shindig.auth.SecurityTokenCodec;
24 import org.apache.shindig.auth.SecurityTokenException;
25 import org.apache.shindig.config.ContainerConfig;
26
27 import com.google.inject.Inject;
28 import com.google.inject.Singleton;
29
30 @Singleton
31 public class ExoSecurityTokenDecoder implements SecurityTokenCodec {
32
33 private static final String SECURITY_TOKEN_TYPE = "gadgets.securityTokenType";
34
35 private SecurityTokenCodec decoder;
36
37 @Inject
38 public ExoSecurityTokenDecoder(ContainerConfig config) {
39
40 String tokenType = config.getString(ContainerConfig.DEFAULT_CONTAINER, SECURITY_TOKEN_TYPE);
41 if ("insecure".equals(tokenType)) {
42 decoder = new BasicSecurityTokenCodec();
43 } else if ("secure".equals(tokenType)) {
44 decoder = new ExoBlobCrypterSecurityDecoder(config);
45 } else {
46 throw new RuntimeException("Unknown security token type specified in "
47 + ContainerConfig.DEFAULT_CONTAINER + " container configuration. " + SECURITY_TOKEN_TYPE
48 + ": " + tokenType);
49 }
50 }
51
52 public SecurityToken createToken(Map<String, String> tokenParameters) throws SecurityTokenException {
53 return decoder.createToken(tokenParameters);
54 }
55
56 public String encodeToken(final SecurityToken token) throws SecurityTokenException {
57 return decoder.encodeToken(token);
58 }
59
60 @Override
61 public int getTokenTimeToLive() {
62
63 throw new RuntimeException();
64 }
65
66 @Override
67 public int getTokenTimeToLive(String s) {
68
69 throw new RuntimeException();
70 }
71
72 }