View Javadoc
1   /*
2    * Copyright (C) 2003-2019 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
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      // TODO Need to check gadget (Activity Stream ... ) for this change.
63      throw new RuntimeException();
64    }
65  
66    @Override
67    public int getTokenTimeToLive(String s) {
68      // TODO Need to check gadget (Activity Stream ... ) for this change.
69      throw new RuntimeException();
70    }
71  
72  }