Я новичок в WSO2 API Manager
версии 1.9.1
. Я хотел, чтобы x-jwt-assertion
был декодирован с использованием библиотеки OpenSAML
(http://mvnrepository.com/artifact/org.opensaml/opensaml/2.6.4). Я хотел, чтобы такое же x-jwt-assertion (показано в этой ссылке Decode X-JWT-Assertion using axiom-api in java) было декодировано/проанализировано, но при реализации ниже кода я вижу следующие ошибки. Пожалуйста, направляйте.Исключение в теме "main" org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Содержимое не допускается в прологе
Можно ли декодировать x-jwt-assertion
WSO2 APIM (менеджер API) с помощью OpenSAML?
Код для ссылки:
Exception in thread "main" org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
at com.mkyong.app.OpenSAMLDemo.main(OpenSAMLDemo.java:46)
Код для ссылки:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.codec.binary.Base64;
import org.opensaml.Configuration;
import org.opensaml.DefaultBootstrap;
import org.opensaml.saml2.core.Assertion;
import org.opensaml.saml2.core.Response;
import org.opensaml.xml.ConfigurationException;
import org.opensaml.xml.XMLObject;
import org.opensaml.xml.io.Unmarshaller;
import org.opensaml.xml.io.UnmarshallerFactory;
import org.opensaml.xml.io.UnmarshallingException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
public class OpenSAMLDemo {
public static void main(String[] args) throws IOException,
ParserConfigurationException, SAXException, ConfigurationException, UnmarshallingException {
Properties prop = new Properties();
prop.load(OpenSAMLDemo.class.getClassLoader().getResourceAsStream("jwtAssertion.properties"));
String responseMessage = prop.getProperty("jwt");
System.out.println(responseMessage);
Base64 base64 = new Base64();
byte[] base64DecodedResponse = base64.decode(responseMessage);
DefaultBootstrap.bootstrap();
ByteArrayInputStream is = new ByteArrayInputStream(base64DecodedResponse);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(is);
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
XMLObject responseXmlObj = unmarshaller.unmarshall(element);
Response response = (Response) responseXmlObj;
Assertion assertion = response.getAssertions().get(0);
String subject = assertion.getSubject().getNameID().getValue();
System.out.println("SUBJECT : " + subject);
String issuer = assertion.getIssuer().getValue();
System.out.println("ISSUER : " + issuer);
String audience = assertion.getConditions().getAudienceRestrictions().get(0).getAudiences().get(0).getAudienceURI();
System.out.println("AUDIENCE : " + audience);
}
}
Просто для проверки может у попробовать расшифровывает с помощью аксиомы http://stackoverflow.com/questions/34498830/decode-x-jwt-assertion-using-axiom-api-in-java –
Вы можете разместить responseMessage вы получили (сообщение, которое вы пытаетесь описать)? – lakshman