View Javadoc

1   package com.atlassian.security.auth.trustedapps;
2   
3   import java.security.PrivateKey;
4   import java.security.PublicKey;
5   
6   public class DefaultCurrentApplication implements CurrentApplication
7   {
8       private final EncryptionProvider encryptionProvider;
9   
10      protected final String id;
11      protected final PublicKey publicKey;
12      protected final PrivateKey privateKey;
13  
14      public DefaultCurrentApplication(EncryptionProvider encryptionProvider, PublicKey publicKey, PrivateKey privateKey, String id)
15      {
16          Null.not("encryptionProvider", encryptionProvider);
17          Null.not("publicKey", publicKey);
18          Null.not("privateKey", privateKey);
19          Null.not("id", id);
20  
21          this.encryptionProvider = encryptionProvider;
22          this.publicKey = publicKey;
23          this.privateKey = privateKey;
24          this.id = id;
25      }
26  
27      public DefaultCurrentApplication(PublicKey publicKey, PrivateKey privateKey, String id)
28      {
29          this(new BouncyCastleEncryptionProvider(), publicKey, privateKey, id);
30      }
31  
32      /**
33       * Returned String can be used as a certificate to talk
34       * to the server that trusts this application. I.e. the ID of this app and the certificate go into the following header parameters:
35       * {@link CurrentApplication#HEADER_TRUSTED_APP_CERT}
36       * {@link CurrentApplication#HEADER_TRUSTED_APP_ID}
37       */
38      public EncryptedCertificate encode(String userName)
39      {
40          return encryptionProvider.createEncryptedCertificate(userName, privateKey, getID());
41      }
42  
43      public String getID()
44      {
45          return id;
46      }
47  
48      public PublicKey getPublicKey()
49      {
50          return publicKey;
51      }
52  }