Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | None | 0 0
  1.  public X509Certificate getCertificate(Map context, String alias, boolean forSigning) throws XWSSecurityException {
  2.         X509Certificate cert = null;
  3.         if (alias != null && (!"".equals(alias) || !forSigning)) {
  4.             Callback[] callbacks;
  5.             if (forSigning) {
  6.                 PrivKeyCertRequest certRequest = new AliasPrivKeyCertRequest(alias);
  7.                 SignatureKeyCallback sigKeyCallback = new SignatureKeyCallback(certRequest);
  8.                 ProcessingContext.copy(sigKeyCallback.getRuntimeProperties(), context);
  9.                 callbacks = new Callback[]{sigKeyCallback};
  10.  
  11.                 try {
  12.                     this.callbackHandler.handle(callbacks);
  13.                 } catch (Exception var10) {
  14.                     log.log(Level.SEVERE, "WSS0216.callbackhandler.handle.exception", new Object[]{"SignatureKeyCallback.AliasPrivKeyCertRequest"});
  15.                     log.log(Level.SEVERE, "WSS0217.callbackhandler.handle.exception.log", var10);
  16.                     throw new XWSSecurityException(var10);
  17.                 }
  18.  
  19.                 cert = certRequest.getX509Certificate();
  20.             } else {
  21.                 X509CertificateRequest certRequest = new AliasX509CertificateRequest(alias);
  22.                 EncryptionKeyCallback encKeyCallback = new EncryptionKeyCallback(certRequest);
  23.                 ProcessingContext.copy(encKeyCallback.getRuntimeProperties(), context);
  24.                 callbacks = new Callback[]{encKeyCallback};
  25.  
  26.                 try {
  27.                     this.callbackHandler.handle(callbacks);
  28.                 } catch (Exception var9) {
  29.                     log.log(Level.SEVERE, "WSS0216.callbackhandler.handle.exception", new Object[]{"EncryptionKeyCallback.AliasX509CertificateRequest"});
  30.                     log.log(Level.SEVERE, "WSS0217.callbackhandler.handle.exception.log", var9);
  31.                     throw new XWSSecurityException(var9);
  32.                 }
  33.  
  34.                 cert = certRequest.getX509Certificate();
  35.             }
  36.  
  37.             if (cert == null) {
  38.                 String val = forSigning ? "Signature" : "Key Encryption";
  39.                 log.log(Level.SEVERE, "WSS0221.cannot.locate.cert", new Object[]{val});
  40.                 throw new XWSSecurityException("Unable to locate certificate for the alias '" + alias + "'");
  41.             } else {
  42.                 return cert;
  43.             }
  44.         } else {
  45.             return this.getDefaultCertificate(context);
  46.         }
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement