本文整理汇总了Java中net.shibboleth.utilities.java.support.codec.Base64Support.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64Support.decode方法的具体用法?Java Base64Support.decode怎么用?Java Base64Support.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.shibboleth.utilities.java.support.codec.Base64Support
的用法示例。
在下文中一共展示了Base64Support.decode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBase64DecodedMessage
import net.shibboleth.utilities.java.support.codec.Base64Support; //导入方法依赖的package包/类
protected InputStream getBase64DecodedMessage()
throws MessageDecodingException {
logger.debug("Getting Base64 encoded message from context, ignoring the given request");
String encodedMessage = this.context.getRequestParameter("SAMLRequest");
if(Strings.isNullOrEmpty(encodedMessage)) {
encodedMessage = this.context.getRequestParameter("SAMLResponse");
}
if(Strings.isNullOrEmpty(encodedMessage)) {
throw new MessageDecodingException("Request did not contain either a SAMLRequest or SAMLResponse parameter. Invalid request for SAML 2 HTTP POST binding.");
} else {
logger.trace("Base64 decoding SAML message:\n{}", encodedMessage);
final byte[] decodedBytes = Base64Support.decode(encodedMessage);
if(decodedBytes == null) {
throw new MessageDecodingException("Unable to Base64 decode SAML message");
} else {
try {
logger.trace("Decoded SAML message:\n{}", new String(decodedBytes, HttpConstants.UTF8_ENCODING));
} catch(final UnsupportedEncodingException e) {
throw new TechnicalException(e);
}
return new ByteArrayInputStream(decodedBytes);
}
}
}
示例2: processResponse
import net.shibboleth.utilities.java.support.codec.Base64Support; //导入方法依赖的package包/类
/**
* Processes a SAML 2.0 response depending on its type, either a SAML 2.0 Response for a single-sign-on (SSO)
* SAML 2.0 Request by the client application or a SAML 2.0 Response for a single-logout (SLO) SAML 2.0 Request
* from a service provider.
*
* @param request the servlet request processed
* @throws SSOException if SAML 2.0 response is null
*/
public void processResponse(Request request) throws SSOException {
String saml2SSOResponse = request.getParameter(Constants.HTTP_POST_PARAM_SAML_RESPONSE);
if (saml2SSOResponse != null) {
String decodedResponse = new String(Base64Support.decode(saml2SSOResponse), StandardCharsets.UTF_8);
Optional<XMLObject> samlObject = SSOUtils.unmarshall(decodedResponse);
if (samlObject.isPresent()) {
if (samlObject.get() instanceof LogoutResponse) {
// this is a SAML 2.0 Response for a single logout request from the service provider
performSingleLogout(request);
} else {
processSingleSignInResponse(request);
}
}
} else {
throw new SSOException("Invalid SAML 2.0 Response, SAML Response cannot be null");
}
}
示例3: testMarshallAndUnmarshall
import net.shibboleth.utilities.java.support.codec.Base64Support; //导入方法依赖的package包/类
/**
* Tests marshalling and unmarshalling of {@code CurrentAddressType}.
*
* @throws Exception
* for errors
*/
@Test
public void testMarshallAndUnmarshall() throws Exception {
XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
Object object = builderFactory.getBuilder(CurrentAddressType.TYPE_NAME).buildObject(CurrentAddressType.TYPE_NAME.getNamespaceURI(),
CurrentAddressType.TYPE_NAME.getLocalPart(), "eidas");
CurrentAddressType address = CurrentAddressType.class.cast(object);
fill(address);
// Marshall
Element element = OpenSAMLTestBase.marshall(address);
Assert.assertNotNull(element);
// Verify that we got one child element that is the Base64 encoding.
NodeList childs = element.getChildNodes();
Assert.assertEquals(1, childs.getLength());
String base64 = childs.item(0).getNodeValue();
byte[] bytes = Base64Support.decode(base64);
Assert.assertTrue((new String(bytes)).startsWith("<eidas:"));
// Unmarshall element
CurrentAddressType address2 = OpenSAMLTestBase.unmarshall(element, CurrentAddressType.class);
verify(address, address2);
String swedishEidString = address2.toSwedishEidString();
Assert.assertEquals("LocatorDesignator=6%20tr;LocatorName=10;Thoroughfare=Korta%20gatan;PostName=Solna;PostCode=19174", swedishEidString);
// Test unmarshall again
String xml = SerializeSupport.prettyPrintXML(element);
Document doc = XMLObjectProviderRegistrySupport.getParserPool().parse(new ByteArrayInputStream(xml.toString().getBytes("UTF-8")));
CurrentAddressType address3 = OpenSAMLTestBase.unmarshall(doc.getDocumentElement(), CurrentAddressType.class);
verify(address, address3);
}