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

📄 downloadinfocardaction.java

📁 开源的OpenId的一个java实现
💻 JAVA
字号:
/* * Copyright 2005-2007 WSO2, Inc. (http://wso2.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.wso2.solutions.identity.user.ui.action;import java.io.OutputStream;import java.util.Map;import javax.servlet.http.HttpServletResponse;import javax.xml.transform.TransformerFactory;import javax.xml.transform.dom.DOMSource;import javax.xml.transform.stream.StreamResult;import org.apache.struts2.StrutsStatics;import org.w3c.dom.Element;import org.wso2.solutions.identity.IdentityConstants;import org.wso2.solutions.identity.IdentityProviderException;import org.wso2.solutions.identity.cards.CardIssuer;import org.wso2.solutions.identity.relyingparty.RelyingPartyException;import org.wso2.solutions.identity.user.ui.UIConstants;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class DownloadInfoCardAction extends ActionSupport {    private static final long serialVersionUID = -1545801495450399056L;    private String selfIssuedPpid;        private String x509Certificate;    public String execute() throws Exception {        ActionContext context = ActionContext.getContext();        Map session = context.getSession();        String userName = (String) session.get(UIConstants.USER);        String sessionPpid = (String) session.get(UIConstants.PPID);        CardIssuer cardIssuer = getCardIssuer();        HttpServletResponse response = (HttpServletResponse) context                .get(StrutsStatics.HTTP_RESPONSE);        response.setContentType("application/x-informationCard");        response.setHeader("Content-Disposition",                "attachment; filename=\"wso2infoCard.crd\"");        response.setHeader("cache-control", "maxage=3");        response.setHeader("Pragma", "public");        Element card = null;        String details = null;        if (selfIssuedPpid != null) {            card = cardIssuer.issueCardForSelfIssuedCard(selfIssuedPpid, true);        } else if(x509Certificate != null) {            card = cardIssuer.issueCardForX509V3Certificate(userName, x509Certificate, true);        } else if (sessionPpid != null) {            card = cardIssuer.issueCardForSelfIssuedCard(sessionPpid, true);        } else {            card = cardIssuer.issueCardForUsername(userName, true);        }        OutputStream out = response.getOutputStream();        TransformerFactory.newInstance().newTransformer().transform(                new DOMSource(card), new StreamResult(out));        out.flush();        out.close();        return NONE;    }    public void setSelfIssuedPpid(String selfIssuedPpids) {        this.selfIssuedPpid = selfIssuedPpids;    }    public void setX509Certificate(String certificate) {        x509Certificate = certificate;    }    /**     * Provide an instance of the information card issuer.     * @return     * @throws RelyingPartyException     */    protected CardIssuer getCardIssuer() throws RelyingPartyException {        try {            return new CardIssuer();        } catch (IdentityProviderException e) {            throw new RelyingPartyException(                    IdentityConstants.ErrorCodes.CARD_ISSUER_INIT_FAILURE);        }    }}

⌨️ 快捷键说明

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