List of usage examples for javax.security.jacc PolicyContext getContext
public static Object getContext(String key) throws javax.security.jacc.PolicyContextException
Policy
provider to activate the PolicyContextHandler
registered to the context object key and cause it to return the corresponding policy context object from the container. From source file:test.be.fedict.eid.applet.model.XmlSignatureServiceBean.java
public void postSign(byte[] signatureValue, List<X509Certificate> signingCertificateChain) { LOG.debug("postSign"); HttpServletRequest httpServletRequest; try {//from www. ja va 2s .c o m httpServletRequest = (HttpServletRequest) PolicyContext .getContext("javax.servlet.http.HttpServletRequest"); } catch (PolicyContextException e) { throw new RuntimeException("JACC error: " + e.getMessage()); } HttpSession session = httpServletRequest.getSession(); String documentStr = (String) session.getAttribute("xmlDocument"); Document document; try { document = getDocument(documentStr); } catch (Exception e) { throw new RuntimeException("DOM error: " + e.getMessage(), e); } // insert signature value NodeList signatureValueNodeList = document.getElementsByTagNameNS(javax.xml.crypto.dsig.XMLSignature.XMLNS, "SignatureValue"); Element signatureValueElement = (Element) signatureValueNodeList.item(0); signatureValueElement.setTextContent(Base64.encode(signatureValue)); try { documentStr = toString(document); } catch (Exception e) { throw new RuntimeException("DOM error: " + e.getMessage(), e); } session.setAttribute("xmlDocument", documentStr); }
From source file:test.be.fedict.eid.applet.model.XmlSignatureServiceBean.java
public DigestInfo preSign(List<DigestInfo> digestInfos, List<X509Certificate> signingCertificateChain) throws NoSuchAlgorithmException { LOG.debug("preSign"); HttpServletRequest httpServletRequest; try {/* w w w . j av a 2 s . c o m*/ httpServletRequest = (HttpServletRequest) PolicyContext .getContext("javax.servlet.http.HttpServletRequest"); } catch (PolicyContextException e) { throw new RuntimeException("JACC error: " + e.getMessage()); } HttpSession httpSession = httpServletRequest.getSession(); String digestAlgo = (String) httpSession.getAttribute("signDigestAlgo"); LOG.debug("digest algo: " + digestAlgo); byte[] digestValue; try { digestValue = getXmlSignatureDigestValue(digestAlgo, digestInfos, httpSession); } catch (Exception e) { throw new RuntimeException("XML signature error: " + e.getMessage(), e); } String description = "Test XML Document"; return new DigestInfo(digestValue, digestAlgo, description); }
From source file:test.be.fedict.eid.applet.SignatureServiceImpl.java
private HttpSession getHttpSession() { HttpServletRequest httpServletRequest; try {//w w w .j a va2 s. com httpServletRequest = (HttpServletRequest) PolicyContext .getContext("javax.servlet.http.HttpServletRequest"); } catch (PolicyContextException e) { throw new RuntimeException("JACC error: " + e.getMessage()); } HttpSession session = httpServletRequest.getSession(); return session; }