📄 x509credentialimpl.java
字号:
/* * Copyright 2005-2008 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.sts.saml;import java.io.InputStream;import java.security.KeyStore;import java.security.KeyStoreException;import java.security.NoSuchAlgorithmException;import java.security.PrivateKey;import java.security.PublicKey;import java.security.UnrecoverableKeyException;import java.security.cert.X509CRL;import java.security.cert.X509Certificate;import java.util.ArrayList;import java.util.Collection;import java.util.List;import javax.crypto.SecretKey;import org.opensaml.xml.security.credential.Credential;import org.opensaml.xml.security.credential.CredentialContextSet;import org.opensaml.xml.security.credential.UsageType;import org.opensaml.xml.security.x509.X509Credential;public class X509CredentialImpl implements X509Credential { private KeyStore store = null; public X509CredentialImpl() throws Exception { InputStream in = this.getClass().getClassLoader().getResourceAsStream( "wso2is.jks"); // InputStream in = new FileInputStream("wso2is.jks"); store = KeyStore.getInstance("JKS"); store.load(in, "wso2is".toCharArray()); } public Collection<X509CRL> getCRLs() { return null; } public X509Certificate getEntityCertificate() { X509Certificate cert = null; try { cert = (X509Certificate) store.getCertificate("localhost"); } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } return cert; } public Collection<X509Certificate> getEntityCertificateChain() { List<X509Certificate> lst = new ArrayList(); try { X509Certificate[] certs = (X509Certificate[]) store .getCertificateChain("localhost"); for (int i = 0; i < certs.length; i++) { lst.add(certs[i]); } } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } return lst; } public CredentialContextSet getCredentalContextSet() { // TODO Auto-generated method stub return null; } public Class<? extends Credential> getCredentialType() { // TODO Auto-generated method stub return null; } public String getEntityId() { // TODO Auto-generated method stub return null; } public Collection<String> getKeyNames() { // TODO Auto-generated method stub return null; } public PrivateKey getPrivateKey() { PrivateKey key = null; try { key = (PrivateKey) store .getKey("localhost", "wso2is".toCharArray()); } catch (KeyStoreException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } return key; } public PublicKey getPublicKey() { X509Certificate cert = null; try { cert = (X509Certificate) store.getCertificate("localhost"); } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } return cert.getPublicKey(); } public SecretKey getSecretKey() { // TODO Auto-generated method stub return null; } public UsageType getUsageType() { // TODO Auto-generated method stub return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -