private HttpSession getSession() {
   Message message = PhaseInterceptorChain.getCurrentMessage();
   HttpServletRequest request =
       (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
   HttpSession session = request.getSession(true);
   return session;
 }
 @Override
 protected SecurityContext createSecurityContext(final Principal p) {
   Message msg = PhaseInterceptorChain.getCurrentMessage();
   if (msg == null) {
     throw new IllegalStateException("Current message is not available");
   }
   return doCreateSecurityContext(p, msg.get(Subject.class));
 }
示例#3
0
 /**
  * Retrieves the client IP for a SOAP request that is currently being handled by the calling
  * thread.
  *
  * @return the client IP for a current SOAP request being handled, or null if an error occured
  */
 public static String getClientIPForCurrentContext() {
   Message message = PhaseInterceptorChain.getCurrentMessage();
   if (message == null) {
     LOGGER.error("No SOAP message found in context while trying to determine client IP");
     return null;
   }
   Request object = (Request) message.get(AbstractHTTPDestination.HTTP_REQUEST);
   if (object == null) {
     LOGGER.error("No HTTP request attached to SOAP message while trying to determine client IP");
     return null;
   }
   return object.getRemoteAddr();
 }
 protected void setSubject(
     String name, String password, boolean isDigest, String nonce, String created)
     throws WSSecurityException {
   Message msg = PhaseInterceptorChain.getCurrentMessage();
   if (msg == null) {
     throw new IllegalStateException("Current message is not available");
   }
   Subject subject = null;
   try {
     subject = createSubject(name, password, isDigest, nonce, created);
   } catch (Exception ex) {
     String errorMessage = "Failed Authentication : Subject has not been created";
     LOG.severe(errorMessage);
     throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
   }
   if (subject == null
       || subject.getPrincipals().size() == 0
       || !checkUserPrincipal(subject.getPrincipals(), name)) {
     String errorMessage = "Failed Authentication : Invalid Subject";
     LOG.severe(errorMessage);
     throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
   }
   msg.put(Subject.class, subject);
 }
示例#5
0
 public static void logError(String log) {
   Message message = PhaseInterceptorChain.getCurrentMessage();
   SECURITY_LOGGER.error(log + requestIpAndPortMessage(message));
 }
示例#6
0
 public static void logWarn(String log, Throwable throwable) {
   Message message = PhaseInterceptorChain.getCurrentMessage();
   SECURITY_LOGGER.warn(log + requestIpAndPortMessage(message), throwable);
 }
示例#7
0
 /**
  * Get the IP related to this request
  *
  * @return the request remote address
  */
 protected String getUserIp() {
   Message message = PhaseInterceptorChain.getCurrentMessage();
   HttpServletRequest request =
       (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
   return request.getRemoteAddr();
 }
示例#8
0
  // CHECKSTYLE:OFF - spec requires a bunch of params
  public W3CEndpointReference createW3CEndpointReference(
      String address,
      QName interfaceName,
      QName serviceName,
      QName portName,
      List<Element> metadata,
      String wsdlDocumentLocation,
      List<Element> referenceParameters,
      List<Element> elements,
      Map<QName, String> attributes) {
    // CHECKSTYLE:ON
    if (serviceName != null
        && portName != null
        && wsdlDocumentLocation != null
        && interfaceName == null) {
      Bus bus = BusFactory.getThreadDefaultBus();
      WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
      try {
        Definition def = wsdlManager.getDefinition(wsdlDocumentLocation);
        interfaceName =
            def.getService(serviceName)
                .getPort(portName.getLocalPart())
                .getBinding()
                .getPortType()
                .getQName();
      } catch (Exception e) {
        // do nothing
      }
    }
    if (serviceName == null && portName == null && address == null) {
      throw new IllegalStateException(
          "Address in an EPR cannot be null, " + " when serviceName or portName is null");
    }
    try {
      W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
      writer.setPrefix(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.NS_WSA);
      writer.writeStartElement(
          JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_ERF_NAME, JAXWSAConstants.NS_WSA);
      writer.writeNamespace(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.NS_WSA);

      writer.writeStartElement(
          JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_ADDRESS_NAME, JAXWSAConstants.NS_WSA);
      address = address == null ? "" : address;
      writer.writeCharacters(address);
      writer.writeEndElement();

      if (referenceParameters != null) {
        writer.writeStartElement(
            JAXWSAConstants.WSA_PREFIX,
            JAXWSAConstants.WSA_REFERENCEPARAMETERS_NAME,
            JAXWSAConstants.NS_WSA);
        for (Element ele : referenceParameters) {
          StaxUtils.writeElement(ele, writer, true);
        }
        writer.writeEndElement();
      }

      if (wsdlDocumentLocation != null
          || interfaceName != null
          || serviceName != null
          || (metadata != null && metadata.size() > 0)) {

        writer.writeStartElement(
            JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_METADATA_NAME, JAXWSAConstants.NS_WSA);
        writer.writeNamespace(JAXWSAConstants.WSAW_PREFIX, JAXWSAConstants.NS_WSAW);
        writer.writeNamespace(JAXWSAConstants.WSAM_PREFIX, JAXWSAConstants.NS_WSAM);

        if (wsdlDocumentLocation != null) {
          boolean includeLocationOnly = false;
          org.apache.cxf.message.Message message = PhaseInterceptorChain.getCurrentMessage();
          if (message != null) {
            includeLocationOnly =
                MessageUtils.isTrue(
                    message.getContextualProperty("org.apache.cxf.wsa.metadata.wsdlLocationOnly"));
          }
          String attrubuteValue =
              serviceName != null && !includeLocationOnly
                  ? serviceName.getNamespaceURI() + " " + wsdlDocumentLocation
                  : wsdlDocumentLocation;
          writer.writeNamespace(JAXWSAConstants.WSDLI_PFX, JAXWSAConstants.NS_WSDLI);
          writer.writeAttribute(
              JAXWSAConstants.WSDLI_PFX,
              JAXWSAConstants.NS_WSDLI,
              JAXWSAConstants.WSDLI_WSDLLOCATION,
              attrubuteValue);
        }
        if (interfaceName != null) {
          writer.writeStartElement(
              JAXWSAConstants.WSAM_PREFIX,
              JAXWSAConstants.WSAM_INTERFACE_NAME,
              JAXWSAConstants.NS_WSAM);
          String portTypePrefix = interfaceName.getPrefix();
          if (portTypePrefix == null || portTypePrefix.equals("")) {
            portTypePrefix = "ns1";
          }
          writer.writeNamespace(portTypePrefix, interfaceName.getNamespaceURI());
          writer.writeCharacters(portTypePrefix + ":" + interfaceName.getLocalPart());
          writer.writeEndElement();
        }

        String serviceNamePrefix = null;

        if (serviceName != null) {
          serviceNamePrefix =
              (serviceName.getPrefix() == null || serviceName.getPrefix().length() == 0)
                  ? "ns2"
                  : serviceName.getPrefix();

          writer.writeStartElement(
              JAXWSAConstants.WSAM_PREFIX,
              JAXWSAConstants.WSAM_SERVICENAME_NAME,
              JAXWSAConstants.NS_WSAM);

          if (portName != null) {
            writer.writeAttribute(JAXWSAConstants.WSAM_ENDPOINT_NAME, portName.getLocalPart());
          }
          writer.writeNamespace(serviceNamePrefix, serviceName.getNamespaceURI());
          writer.writeCharacters(serviceNamePrefix + ":" + serviceName.getLocalPart());

          writer.writeEndElement();
        }

        if (wsdlDocumentLocation != null) {

          writer.writeStartElement(
              WSDLConstants.WSDL_PREFIX,
              WSDLConstants.QNAME_DEFINITIONS.getLocalPart(),
              WSDLConstants.NS_WSDL11);
          writer.writeNamespace(WSDLConstants.WSDL_PREFIX, WSDLConstants.NS_WSDL11);
          writer.writeStartElement(
              WSDLConstants.WSDL_PREFIX,
              WSDLConstants.QNAME_IMPORT.getLocalPart(),
              WSDLConstants.QNAME_IMPORT.getNamespaceURI());
          if (serviceName != null) {
            writer.writeAttribute(WSDLConstants.ATTR_NAMESPACE, serviceName.getNamespaceURI());
          }
          writer.writeAttribute(WSDLConstants.ATTR_LOCATION, wsdlDocumentLocation);
          writer.writeEndElement();
          writer.writeEndElement();
        }

        if (metadata != null) {
          for (Element e : metadata) {
            StaxUtils.writeElement(e, writer, true);
          }
        }

        writer.writeEndElement();
      }

      if (elements != null) {
        for (Element e : elements) {
          StaxUtils.writeElement(e, writer, true);
        }
      }
      writer.writeEndElement();
      writer.flush();

      Unmarshaller unmarshaller = getJAXBContext().createUnmarshaller();
      return (W3CEndpointReference) unmarshaller.unmarshal(writer.getDocument());
    } catch (Exception e) {
      throw new WebServiceException(
          new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(), e);
    }
  }
 @Override
 public void filter(ContainerRequestContext context) throws IOException {
   InterceptorChain chain = PhaseInterceptorChain.getCurrentMessage().getInterceptorChain();
   chain.add(this);
 }