com.sun.enterprise.security.webservices.WebServicesDelegateImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of payara-client Show documentation
Show all versions of payara-client Show documentation
Appclient for Payara Server
The newest version!
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018-2024] [Payara Foundation and/or its affiliates]
package com.sun.enterprise.security.webservices;
import com.sun.enterprise.deployment.ServiceRefPortInfo;
import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
import com.sun.enterprise.deployment.runtime.common.MessageSecurityBindingDescriptor;
import com.sun.enterprise.security.ee.authentication.jakarta.WebServicesDelegate;
import com.sun.enterprise.security.jauth.jaspic.provider.PacketMessageInfo;
import com.sun.xml.ws.api.message.Message;
import com.sun.xml.ws.api.message.Packet;
import com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation;
import com.sun.xml.ws.api.model.wsdl.WSDLPort;
import jakarta.inject.Singleton;
import jakarta.security.auth.message.MessageInfo;
import jakarta.xml.soap.MimeHeaders;
import jakarta.xml.soap.Name;
import jakarta.xml.soap.Node;
import jakarta.xml.soap.SOAPBody;
import jakarta.xml.soap.SOAPElement;
import jakarta.xml.soap.SOAPEnvelope;
import jakarta.xml.soap.SOAPException;
import jakarta.xml.soap.SOAPMessage;
import jakarta.xml.soap.SOAPPart;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.jvnet.hk2.annotations.Service;
/**
*
* @author kumar.jayanti
*/
@Service
@Singleton
public class WebServicesDelegateImpl implements WebServicesDelegate {
protected static final Logger _logger = LogUtils.getLogger();
private static final String DEFAULT_WEBSERVICES_PROVIDER = "com.sun.xml.wss.provider.wsit.WSITAuthConfigProvider";
@Override
public MessageSecurityBindingDescriptor getBinding(ServiceReferenceDescriptor svcRef, Map properties) {
MessageSecurityBindingDescriptor binding = null;
WSDLPort p = (WSDLPort) properties.get("WSDL_MODEL");
QName portName = null;
if (p != null) {
portName = p.getName();
}
if (portName != null) {
ServiceRefPortInfo i = svcRef.getPortInfoByPort(portName);
if (i != null) {
binding = i.getMessageSecurityBinding();
}
}
return binding;
}
@Override
public String getDefaultWebServicesProvider() {
return DEFAULT_WEBSERVICES_PROVIDER;
}
@Override
public String getAuthContextID(MessageInfo messageInfo) {
if (!(messageInfo instanceof PacketMessageInfo)) {
return getOpName((SOAPMessage) messageInfo.getRequestMessage());
}
// Make this more efficient by operating on packet
String authContextID = null;
PacketMessageInfo pmi = (PacketMessageInfo) messageInfo;
Packet requestPacket = pmi.getRequestPacket();
if (requestPacket != null) {
Message message = requestPacket.getMessage();
if (message != null) {
WSDLPort port = (WSDLPort) messageInfo.getMap().get("WSDL_MODEL");
if (port != null) {
WSDLBoundOperation boundOperation = message.getOperation(port);
if (boundOperation != null) {
QName name = boundOperation.getName();
if (name != null) {
authContextID = name.getLocalPart();
}
}
}
}
}
return authContextID;
}
private String getOpName(SOAPMessage message) {
if (message == null) {
return null;
}
String opName = null;
// First look for a SOAPAction header.
// this is what .net uses to identify the operation
MimeHeaders headers = message.getMimeHeaders();
if (headers != null) {
String[] actions = headers.getHeader("SOAPAction");
if (actions != null && actions.length > 0) {
opName = actions[0];
if (opName != null && opName.equals("\"\"")) {
opName = null;
}
}
}
// If that doesn't work then we default to trying the name
// of the first child element of the SOAP envelope.
if (opName == null) {
Name name = getName(message);
if (name != null) {
opName = name.getLocalName();
}
}
return opName;
}
private Name getName(SOAPMessage message) {
Name rvalue = null;
SOAPPart soap = message.getSOAPPart();
if (soap != null) {
try {
SOAPEnvelope envelope = soap.getEnvelope();
if (envelope != null) {
SOAPBody body = envelope.getBody();
if (body != null) {
Iterator it = body.getChildElements();
while (it.hasNext()) {
Node node = it.next();
if (node instanceof SOAPElement) {
rvalue = ((SOAPElement) node).getElementName();
break;
}
}
}
}
} catch (SOAPException se) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "WSS: Unable to get SOAP envelope", se);
}
}
}
return rvalue;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy