⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 certificaterequestinfo.java

📁 一个java开发的非常全面的关于证书发放
💻 JAVA
字号:
/*
  Name:         CertificateRequestInfo.java
  Licensing:    LGPL

  API:          Sun (http://java.sun.com) JCE 1.2.2 API (cleanroom implementation by Bouncy Castle)
  Provider:     Bouncy Castle (http://www.bouncycastle.org)

  Disclaimer:

  COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND,
  EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE
  IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE
  RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE
  PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR)
  ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY
  CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED
  HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
*/

package net.sourceforge.jcetaglib.taglib.x509;

import net.sourceforge.jcetaglib.lib.X509Cert;
import org.bouncycastle.asn1.pkcs.CertificationRequestInfo;
import org.bouncycastle.asn1.x509.X509Name;
import org.bouncycastle.jce.PKCS10CertificationRequest;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;
import java.security.Security;

/**
 * JSP tag for retrieving info from PKCS#10 requests
 *
 * @jsp.tag
 * name="certificaterequestinfo"
 * display-name="CertificateRequestInfo"
 * body-content="JSP"
 * example="<%-- Get subject DN from request--%>

 *  <jce:certificaterequestinfo

 *		certrequest=\"<%= request.getParameter(\"pkcs10req\") %>\"

 *		subjectdn=\"sdn\"/>"
 *
 * description="JSP tag for retrieving info from PKCS#10 requests"
 *
 * @author Gert Van Ham
 * @author hamgert@users.sourceforge.net
 * @author http://jcetaglib.sourceforge.net
 * @version $Id: CertificateRequestInfo.java,v 1.7 2004/04/15 07:28:36 hamgert Exp $
 */

public class CertificateRequestInfo extends BodyTagSupport {
    private static final String PAGE = "page";
    private static final String REQUEST = "request";
    private static final String SESSION = "session";
    private static final String APPLICATION = "application";

    protected String certrequest; // tag attribute

    private int scope = PageContext.PAGE_SCOPE;

    private String subjectdn;

    public static int getScope(String scope) {
        int ret = PageContext.PAGE_SCOPE; // default

        if (REQUEST.equalsIgnoreCase(scope))
            ret = PageContext.REQUEST_SCOPE;
        else if (SESSION.equalsIgnoreCase(scope))
            ret = PageContext.SESSION_SCOPE;
        else if (APPLICATION.equalsIgnoreCase(scope))
            ret = PageContext.APPLICATION_SCOPE;
        else if (PAGE.equalsIgnoreCase(scope))
            ret = PageContext.PAGE_SCOPE;

        return ret;
    } //getScope()

    public int doEndTag() throws JspException {
        String input;

        // determine the value by...
        if (certrequest != null) {
            // ... reading our attribute
            input = certrequest;
        } else {
            // ... retrieving and trimming our body
            if (bodyContent == null || bodyContent.getString() == null) {
                input = "";
            } else {
                input = bodyContent.getString().trim();
            }
        }

        Security.addProvider(new BouncyCastleProvider());

        try {
            // PKCS10 Request type
            PKCS10CertificationRequest pkcs10 = X509Cert.getPKCS10Request(input);

            if (pkcs10.verify() == false) {
                throw new JspException("JCE Exception: Unable to retrieve info from PKCS#10 request: Not a valid PKCS10 request");
            }

            CertificationRequestInfo reqinfo = pkcs10.getCertificationRequestInfo();
            X509Name x = reqinfo.getSubject();

            pageContext.setAttribute(subjectdn, x.toString(), scope);

        } catch (Exception e) {
            throw new JspException("JCE Exception: Unable to retrieve info from PKCS#10 request: "
                    + e.getMessage(), e);
        }

        return EVAL_PAGE;
    } //doEndTag()

    /**
     * @jsp.attribute
     *     description="Optional attribute, the certificate request. The body of the tag will be taken if omitted"
     *     type="java.lang.String"
     *     required="false"
     *     rtexprvalue="true"
     */
    public void setCertrequest(String certrequest) {
        this.certrequest = certrequest;
    }

    /**
     * @jsp.attribute
     *     description="Scope of the return variables. Can be 'page', 'session', 'request' or 'application'. Default is 'page'"
     *     type="java.lang.String"
     *     required="false"
     *     rtexprvalue="false"
     */
    public void setScope(String scope) {
        this.scope = getScope(scope);
    }

    /**
     * @jsp.attribute
     *     description="Return variable. Contains the subject DN from the PKCS#10 request"
     *     type="java.lang.String"
     *     required="true"
     *     rtexprvalue="false"
     */
    public void setSubjectdn(String subjectdn) {
        this.subjectdn = subjectdn;
    }

    public String getSubjectdn() {
        return subjectdn;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -