Example usage for javax.security.jacc PolicyContext getContext

List of usage examples for javax.security.jacc PolicyContext getContext

Introduction

In this page you can find the example usage for javax.security.jacc PolicyContext getContext.

Prototype


public static Object getContext(String key) throws javax.security.jacc.PolicyContextException 

Source Link

Document

This method may be used by a 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.

Usage

From source file:test.be.fedict.eid.applet.model.AuthenticationServiceBean.java

public void validateCertificateChain(List<X509Certificate> certificateChain) throws SecurityException {
    LOG.debug("validate certificate chain: " + certificateChain);

    HttpServletRequest httpServletRequest;
    try {//ww w  .j  a  va 2s  . 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();
    httpSession.setAttribute("AuthenticationCertificateChain", certificateChain);
}

From source file:test.be.fedict.eid.applet.model.AuthenticationSignatureServiceBean.java

public void postSign(byte[] signatureValue, List<X509Certificate> authnCertificateChain,
        AuthenticationSignatureContext authenticationSignatureContext) {
    LOG.debug("postSign: " + (signatureValue != null));

    ProxyPrivateKey proxyPrivateKey = (ProxyPrivateKey) authenticationSignatureContext.load("key");
    proxyPrivateKey.setSignatureValue(signatureValue);

    FutureTask<String> signTask = (FutureTask<String>) authenticationSignatureContext.load("signTask");
    String signatureResult;/*from w  w  w.  j a  v  a  2 s. c  om*/
    try {
        signatureResult = signTask.get();
    } catch (Exception e) {
        throw new RuntimeException("sign task error: " + e.getMessage(), e);
    }

    HttpServletRequest httpServletRequest;
    try {
        httpServletRequest = (HttpServletRequest) PolicyContext
                .getContext("javax.servlet.http.HttpServletRequest");
    } catch (PolicyContextException e) {
        throw new RuntimeException("JACC error: " + e.getMessage());
    }

    HttpSession httpSession = httpServletRequest.getSession();
    httpSession.setAttribute("AuthenticationSignatureValue", signatureResult);
}

From source file:test.be.fedict.eid.applet.model.ChannelBindingServiceBean.java

public X509Certificate getServerCertificate() {
    LOG.debug("getServerCertificate");
    HttpServletRequest httpServletRequest;
    try {//from  www  .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();
    X509Certificate serverCertificate = (X509Certificate) httpSession
            .getAttribute(SERVER_CERTIFICATE_SESSION_ATTRIBUTE);
    return serverCertificate;
}

From source file:test.be.fedict.eid.applet.model.FilesSignatureServiceBean.java

public void postSign(byte[] signatureValue, List<X509Certificate> signingCertificateChain) {
    LOG.debug("postSign");

    HttpServletRequest httpServletRequest;
    try {/*w  w  w  . j  a va 2  s .  c  om*/
        httpServletRequest = (HttpServletRequest) PolicyContext
                .getContext("javax.servlet.http.HttpServletRequest");
    } catch (PolicyContextException e) {
        throw new RuntimeException("JACC error: " + e.getMessage());
    }

    String signatureValueStr = new String(Hex.encodeHex(signatureValue));

    HttpSession session = httpServletRequest.getSession();
    session.setAttribute("SignatureValue", signatureValueStr);
    session.setAttribute("SigningCertificateChain", signingCertificateChain);
}

From source file:test.be.fedict.eid.applet.model.FilesSignatureServiceBean.java

public DigestInfo preSign(List<DigestInfo> digestInfos, List<X509Certificate> signingCertificateChain)
        throws NoSuchAlgorithmException {
    LOG.debug("preSign");

    HttpServletRequest httpServletRequest;
    try {//from  ww w  .j  a v a2s .  co  m
        httpServletRequest = (HttpServletRequest) PolicyContext
                .getContext("javax.servlet.http.HttpServletRequest");
    } catch (PolicyContextException e) {
        throw new RuntimeException("JACC error: " + e.getMessage());
    }

    HttpSession session = httpServletRequest.getSession();
    String signDigestAlgo = (String) session.getAttribute("signDigestAlgo");
    LOG.debug("signature digest algo: " + signDigestAlgo);

    List<String> fileDescriptions = new LinkedList<String>();
    MessageDigest messageDigest = MessageDigest.getInstance(signDigestAlgo, new BouncyCastleProvider());
    for (DigestInfo digestInfo : digestInfos) {
        LOG.debug("processing digest for: " + digestInfo.description);
        fileDescriptions.add(digestInfo.description + "\n");
        messageDigest.update(digestInfo.digestValue);
        /*
         * XMLDSig, XAdES or PDF is possible here...
         */
    }
    byte[] digestValue = messageDigest.digest();

    session.setAttribute("signedFiles", fileDescriptions);

    String description = "Local Test Files";
    return new DigestInfo(digestValue, signDigestAlgo, description);
}

From source file:test.be.fedict.eid.applet.model.FilesSignatureServiceBean.java

public String getFilesDigestAlgorithm() {
    LOG.debug("getFileDigestAlgoritm()");
    HttpServletRequest httpServletRequest;
    try {/*  w ww.j  a v a  2s . c  om*/
        httpServletRequest = (HttpServletRequest) PolicyContext
                .getContext("javax.servlet.http.HttpServletRequest");
    } catch (PolicyContextException e) {
        throw new RuntimeException("JACC error: " + e.getMessage());
    }

    HttpSession session = httpServletRequest.getSession();
    String filesDigestAlgo = (String) session.getAttribute("filesDigestAlgo");
    LOG.debug("files digest algo: " + filesDigestAlgo);

    return filesDigestAlgo;
}

From source file:test.be.fedict.eid.applet.model.IdentityIntegrityServiceBean.java

public void checkNationalRegistrationCertificate(List<X509Certificate> certificateChain)
        throws SecurityException {
    LOG.debug("checking national registry certificate...");

    HttpServletRequest httpServletRequest;
    try {/*  ww  w. j a va 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();
    X509Certificate certificate = certificateChain.get(0);
    httpSession.setAttribute("NationalRegistryCertificate", certificate);
}

From source file:test.be.fedict.eid.applet.model.IdentitySignatureServiceBean.java

private HttpSession getHttpSession() {
    HttpServletRequest httpServletRequest;
    try {// w w  w  .j a  va  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();
    return httpSession;
}

From source file:test.be.fedict.eid.applet.model.SecureClientEnvironmentCheckerBean.java

public void checkSecureClientEnvironment(String javaVersion, String javaVendor, String osName, String osArch,
        String osVersion, String userAgent, String navigatorAppName, String navigatorAppVersion,
        String navigatorUserAgent, String remoteAddress, Integer sslKeySize, String sslCipherSuite,
        List<String> readerList) throws SecurityException {
    LOG.debug("java version: " + javaVersion);
    LOG.debug("java vendor: " + javaVendor);
    LOG.debug("OS name: " + osName);
    LOG.debug("OS arch: " + osArch);
    LOG.debug("OS version: " + osVersion);
    LOG.debug("user agent: " + userAgent);
    LOG.debug("navigator app name: " + navigatorAppName);
    LOG.debug("navigator app version: " + navigatorAppVersion);
    LOG.debug("navigator user agent: " + navigatorUserAgent);
    LOG.debug("remote address: " + remoteAddress);
    LOG.debug("ssl key size: " + sslKeySize);
    LOG.debug("ssl cipher suite: " + sslCipherSuite);
    LOG.debug("readers: " + readerList);

    HttpServletRequest httpServletRequest;
    try {//  ww  w  . j a v  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();
    httpSession.setAttribute("ClientJavaVersion", javaVersion);
    httpSession.setAttribute("ClientJavaVendor", javaVendor);
    httpSession.setAttribute("ClientOSName", osName);
    httpSession.setAttribute("ClientOSArch", osArch);
    httpSession.setAttribute("ClientOSVersion", osVersion);
    httpSession.setAttribute("ClientReaders", readerList.toString());
    httpSession.setAttribute("ClientUserAgent", userAgent);
    httpSession.setAttribute("ClientSslCipherSuite", sslCipherSuite);
    httpSession.setAttribute("ClientRemoteAddress", remoteAddress);
    httpSession.setAttribute("ClientSslKeySize", sslKeySize);
    httpSession.setAttribute("ClientNavigatorUserAgent", navigatorUserAgent);
    httpSession.setAttribute("ClientNavigatorAppName", navigatorAppName);
    httpSession.setAttribute("ClientNavigatorAppVersion", navigatorAppVersion);
}

From source file:test.be.fedict.eid.applet.model.SignatureServiceBean.java

public DigestInfo preSign(List<DigestInfo> digestInfos, List<X509Certificate> signingCertificateChain)
        throws NoSuchAlgorithmException {
    LOG.debug("preSign");

    HttpServletRequest httpServletRequest;
    try {/*from   w  w w  .  j ava  2 s.  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 toBeSigned = (String) session.getAttribute("toBeSigned");
    String digestAlgo = (String) session.getAttribute("digestAlgo");
    LOG.debug("digest algo: " + digestAlgo);

    MessageDigest messageDigest = MessageDigest.getInstance(digestAlgo, new BouncyCastleProvider());
    byte[] digestValue = messageDigest.digest(toBeSigned.getBytes());

    String description = "Test Text Document";
    return new DigestInfo(digestValue, digestAlgo, description);
}