|
|
@ -33,8 +33,6 @@ import org.apache.catalina.connector.Request;
|
|
|
|
import org.apache.catalina.connector.Response;
|
|
|
|
import org.apache.catalina.connector.Response;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.coyote.InputBuffer;
|
|
|
|
|
|
|
|
import org.apache.tomcat.util.buf.ByteChunk;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.xml.stream.XMLStreamException;
|
|
|
|
import javax.xml.stream.XMLStreamException;
|
|
|
|
import javax.xml.stream.XMLStreamReader;
|
|
|
|
import javax.xml.stream.XMLStreamReader;
|
|
|
@ -42,7 +40,12 @@ import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Base64;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import java.util.StringTokenizer;
|
|
|
|
|
|
|
|
|
|
|
|
public class BSTAuthenticator implements WebappAuthenticator {
|
|
|
|
public class BSTAuthenticator implements WebappAuthenticator {
|
|
|
|
|
|
|
|
|
|
|
@ -146,30 +149,27 @@ public class BSTAuthenticator implements WebappAuthenticator {
|
|
|
|
|
|
|
|
|
|
|
|
private String getBSTHeader(Request request) throws IOException, XMLStreamException {
|
|
|
|
private String getBSTHeader(Request request) throws IOException, XMLStreamException {
|
|
|
|
org.apache.coyote.Request coyoteReq = request.getCoyoteRequest();
|
|
|
|
org.apache.coyote.Request coyoteReq = request.getCoyoteRequest();
|
|
|
|
InputBuffer buf = coyoteReq.getInputBuffer();
|
|
|
|
String securityHeader = coyoteReq.getHeader("Security");
|
|
|
|
ByteChunk bc = new ByteChunk();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf.doRead(bc, coyoteReq);
|
|
|
|
if (securityHeader == null || securityHeader.isEmpty()) {
|
|
|
|
try (InputStream is = new ByteArrayInputStream(getUTF8Bytes(bc.toString()))) {
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Process the "Security" header value as needed
|
|
|
|
|
|
|
|
try (InputStream is = new ByteArrayInputStream(getUTF8Bytes(securityHeader))) {
|
|
|
|
XMLStreamReader reader = StAXUtils.createXMLStreamReader(is);
|
|
|
|
XMLStreamReader reader = StAXUtils.createXMLStreamReader(is);
|
|
|
|
StAXBuilder builder = new StAXSOAPModelBuilder(reader);
|
|
|
|
StAXBuilder builder = new StAXSOAPModelBuilder(reader);
|
|
|
|
SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
|
|
|
|
SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
|
|
|
|
envelope.build();
|
|
|
|
envelope.build();
|
|
|
|
|
|
|
|
|
|
|
|
SOAPHeader header = envelope.getHeader();
|
|
|
|
SOAPHeader header = envelope.getHeader();
|
|
|
|
Iterator headerEls = header.getChildrenWithLocalName("Security");
|
|
|
|
Iterator headerEls = header.getChildrenWithLocalName("BinarySecurityToken");
|
|
|
|
if (!headerEls.hasNext()) {
|
|
|
|
if (!headerEls.hasNext()) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OMElement securityHeader = (OMElement) headerEls.next();
|
|
|
|
OMElement bstHeader = (OMElement) headerEls.next();
|
|
|
|
Iterator securityHeaderEls = securityHeader.getChildrenWithLocalName("BinarySecurityToken");
|
|
|
|
|
|
|
|
if (!securityHeaderEls.hasNext()) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OMElement bstHeader = (OMElement) securityHeaderEls.next();
|
|
|
|
|
|
|
|
bstHeader.build();
|
|
|
|
bstHeader.build();
|
|
|
|
return bstHeader.getText();
|
|
|
|
return bstHeader.getText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|