View Javadoc
1   /**
2    * This Source Code Form is subject to the terms of the Mozilla Public
3    * License, v. 2.0. If a copy of the MPL was not distributed with this
4    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5    *
6    * If it is not possible or desirable to put the notice in a particular
7    * file, then You may include the notice in a location (such as a LICENSE
8    * file in a relevant directory) where a recipient would be likely to look
9    * for such a notice.
10  
11   * 
12   */
13   
14  /*  ---------------------------------------------------------------------------
15   *  U.S. Government, Department of the Army
16   *  Army Materiel Command
17   *  Research Development Engineering Command
18   *  Communications Electronics Research Development and Engineering Center
19   *  ---------------------------------------------------------------------------
20   */
21  
22  package org.miloss.fgsms.presentation;
23  
24  import java.security.Principal;
25  import java.util.HashSet;
26  import java.util.Set;
27  import javax.xml.namespace.QName;
28  import javax.xml.ws.handler.MessageContext;
29  import javax.xml.ws.handler.soap.SOAPHandler;
30  import javax.xml.ws.handler.soap.SOAPMessageContext;
31  import org.miloss.fgsms.common.Constants;
32  
33  /**
34   *This is a soap handler that injects an http header that identifies the current user context.
35   * It should only be used when using CAC/PKI logins from the fgsms web interface to the fgsms web services
36   * @author AO
37   */
38  public class PKIHandler implements SOAPHandler<SOAPMessageContext> {
39  
40      public PKIHandler() {
41      }
42  
43      public PKIHandler(Principal user) {
44          this.user = user;
45      }
46      private Principal user = null;
47  
48      public Set<QName> getHeaders() {
49          return new HashSet<QName>();
50      }
51  
52      public boolean handleMessage(SOAPMessageContext messageContext) {
53          Boolean isOutbound = (Boolean) messageContext.get(messageContext.MESSAGE_OUTBOUND_PROPERTY);
54  
55          if (isOutbound) {
56  
57              try {
58                  ProcessOutboundMessage(messageContext);
59              } catch (Exception ex) {
60                  //log.log(Level.WARNING, "fgsms Error processing inbound message", ex);
61                  return true;
62              }
63          } else {
64          }
65  
66          return true;
67      }
68  
69      public boolean handleFault(SOAPMessageContext context) {
70          return true;
71      }
72  
73      public void close(MessageContext context) {
74      }
75  
76      private void ProcessOutboundMessage(SOAPMessageContext messageContext) {
77          if (user == null) {
78              return;
79          }
80          messageContext.getMessage().getMimeHeaders().addHeader(org.miloss.fgsms.common.Constants.CAC_DELEGATE_Authorization_Header, user.getName());
81      }
82  }