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:be.fedict.eid.dss.sp.bean.SignatureRequestServiceBean.java

private static HttpServletRequest getHttpServletRequest() {
    HttpServletRequest httpServletRequest;
    try {/*from ww w.  jav  a2 s  .c o  m*/
        httpServletRequest = (HttpServletRequest) PolicyContext
                .getContext("javax.servlet.http.HttpServletRequest");
    } catch (PolicyContextException e) {
        throw new RuntimeException("JACC error: " + e.getMessage());
    }

    return httpServletRequest;
}

From source file:be.fedict.eid.applet.beta.TestReportFactory.java

private HttpServletRequest getHttpServletRequest() {
    HttpServletRequest httpServletRequest;
    try {/*from   www.  j av a2  s .c  om*/
        httpServletRequest = (HttpServletRequest) PolicyContext
                .getContext("javax.servlet.http.HttpServletRequest");
    } catch (PolicyContextException e) {
        throw new RuntimeException("JACC error: " + e.getMessage());
    }
    return httpServletRequest;
}

From source file:be.fedict.eid.applet.beta.IdentityIntegrityServiceBean.java

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

    HttpServletRequest httpServletRequest;
    try {/* ww w  .  jav  a2  s .co  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:be.fedict.eid.applet.beta.AuthenticationServiceBean.java

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

    HttpServletRequest httpServletRequest;
    try {//from  w ww.  j  a  v  a2 s.c om
        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:be.fedict.eid.applet.beta.SessionContextManagerBean.java

@SuppressWarnings("unchecked")
public int getSessionContextId(String httpSessionId) {
    LOG.debug("get context Id for HTTP session Id: " + httpSessionId);

    Query query = this.entityManager
            .createQuery("FROM SessionContextEntity AS sc WHERE sc.httpSessionId = :httpSessionId");
    query.setParameter("httpSessionId", httpSessionId);
    List<SessionContextEntity> sessionContextList = query.getResultList();
    if (sessionContextList.isEmpty()) {
        HttpServletRequest httpServletRequest;
        try {//from  w  w  w.jav a  2 s  .c o m
            httpServletRequest = (HttpServletRequest) PolicyContext
                    .getContext("javax.servlet.http.HttpServletRequest");
        } catch (PolicyContextException e) {
            throw new RuntimeException("JACC error: " + e.getMessage());
        }
        String userAgent = httpServletRequest.getHeader("user-agent");
        LOG.debug("user agent: " + userAgent);
        SessionContextEntity sessionContextEntity = new SessionContextEntity(httpSessionId, userAgent);
        this.entityManager.persist(sessionContextEntity);
        int contextId = sessionContextEntity.getContextId();
        LOG.debug("new context Id: " + contextId);
        return contextId;
    }
    /*
     * An existing HTTP session will come from the same user agent.
     */
    SessionContextEntity sessionContextEntity = sessionContextList.get(0);
    int contextId = sessionContextEntity.getContextId();
    LOG.debug("existing context Id: " + contextId);
    return contextId;
}

From source file:be.fedict.hsm.model.security.SecurityAuditGeneratorBean.java

private String getHostIdentifier() {
    HttpServletRequest httpServletRequest;
    try {/*from ww  w. jav  a 2s. c  om*/
        httpServletRequest = (HttpServletRequest) PolicyContext
                .getContext("javax.servlet.http.HttpServletRequest");
    } catch (PolicyContextException e) {
        LOG.debug("JACC error: " + e.getMessage());
        return null;
    }
    String hostIdentifier = httpServletRequest.getRemoteHost();
    return hostIdentifier;
}

From source file:be.fedict.eid.applet.service.signer.HttpSessionTemporaryDataStorage.java

/**
 * Gives back the current HTTP session using JACC.
 * //  w  w  w.  ja  va2 s. c om
 * @return
 */
public static HttpSession getHttpSession() {
    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();
    return httpSession;
}

From source file:be.fedict.eid.applet.beta.admin.AdministratorServiceBean.java

public void validateCertificateChain(List<X509Certificate> certificateChain) throws SecurityException {
    /*/*from  www. j a  v a2  s .c  o m*/
     * We're not using the entire PKI infrastructure here since we are in
     * control of the admin token ourselves.
     */
    X509Certificate adminCert = certificateChain.get(0);
    PublicKey adminPublicKey = adminCert.getPublicKey();
    String userId = getUserId(adminCert);
    if (isRegistered()) {
        LOG.debug("admin login");
    } else {
        LOG.debug("admin registration");
        register(adminPublicKey, userId);
    }

    String adminPassword = new String(Hex.encodeHex(adminPublicKey.getEncoded()));

    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();
    Credentials credentials = (Credentials) httpSession.getAttribute("org.jboss.seam.security.credentials");

    LOG.debug("username: " + userId);
    /*
     * Pass the eID credentials to the JBoss Seam security framework.
     */
    credentials.setUsername(userId);
    credentials.setPassword(adminPassword);
}

From source file:be.fedict.eid.applet.beta.SecureClientEnvironmentBean.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 InsecureClientEnvironmentException {
    String clientEnviromentResult = "java version: " + javaVersion + "\n" + "java vendor: " + javaVendor + "\n"
            + "OS name: " + osName + "\n" + "OS arch: " + osArch + "\n" + "OS version: " + osVersion + "\n"
            + "user agent: " + userAgent + "\n" + "navigator app name: " + navigatorAppName + "\n"
            + "navigator app version: " + navigatorAppVersion + "\n" + "navigator user agent: "
            + navigatorUserAgent + "\n" + "remote address: " + remoteAddress + "\n" + "ssl key size: "
            + sslKeySize + "\n" + "ssl cipher suite: " + sslCipherSuite + "\n" + "readers: " + readerList;
    LOG.debug(clientEnviromentResult);/*from   w  w w .  j a  va 2s  .  co m*/

    SessionContextEntity sessionContext = this.sessionContextManager.getSessionContext();
    TestResultEntity testResultEntity = new TestResultEntity("Client Environment", clientEnviromentResult,
            sessionContext);
    this.entityManager.persist(testResultEntity);

    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("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);

    TestReportFactory testReportFactory = new TestReportFactory(this.entityManager);
    testReportFactory.startTestReport(javaVersion, javaVendor, osName, osArch, osVersion, userAgent,
            navigatorAppName, navigatorAppVersion, navigatorUserAgent);
}

From source file:de.adorsys.oauth.loginmodule.DelegatingLoginModule.java

private ClientID resolveClientID() throws LoginException {
    try {// w  w w . ja  va  2s.com
        AuthorizationRequest authorizationRequest = (AuthorizationRequest) PolicyContext
                .getContext(AuthorizationRequest.class.getName());
        return authorizationRequest.getClientID();
    } catch (Exception e) {
        log.trace("Exception parsing auth request", e);
    }
    try {
        TokenRequest tokenRequest = (TokenRequest) PolicyContext.getContext(TokenRequest.class.getName());
        if (tokenRequest.getClientID() == null && tokenRequest.getClientAuthentication() != null) {
            return tokenRequest.getClientAuthentication().getClientID();
        }
        return tokenRequest.getClientID();
    } catch (Exception e) {
        //
    }
    throw new LoginException("ClientID extraction failed");
}