本文整理汇总了Java中org.wso2.carbon.core.util.KeyStoreManager类的典型用法代码示例。如果您正苦于以下问题:Java KeyStoreManager类的具体用法?Java KeyStoreManager怎么用?Java KeyStoreManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyStoreManager类属于org.wso2.carbon.core.util包,在下文中一共展示了KeyStoreManager类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createBasicCredentials
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
/**
* Create basic credentials needed to generate signature using EntitlementServiceComponent
*
* @return basicX509Credential
*/
private static BasicX509Credential createBasicCredentials() {
Certificate certificate = null;
PrivateKey issuerPK = null;
KeyStoreManager keyMan = KeyStoreManager.getInstance(-1234);
try {
certificate = keyMan.getDefaultPrimaryCertificate();
issuerPK = keyMan.getDefaultPrivateKey();
} catch (Exception e) {
log.error("Error occurred while getting the KeyStore from KeyManger.", e);
}
BasicX509Credential basicCredential = new BasicX509Credential();
basicCredential.setEntityCertificate((java.security.cert.X509Certificate) certificate);
basicCredential.setPrivateKey(issuerPK);
return basicCredential;
}
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:26,代码来源:WSXACMLMessageReceiver.java
示例2: getPublicX509CredentialImpl
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
/**
* get a org.wso2.carbon.identity.entitlement.wsxacml.X509CredentialImpl using RegistryService
*
* @return created X509Credential
*/
private X509CredentialImpl getPublicX509CredentialImpl() throws Exception {
X509CredentialImpl credentialImpl;
KeyStoreManager keyStoreManager;
try {
keyStoreManager = KeyStoreManager.getInstance(-1234);
// load the default pub. cert using the configuration in carbon.xml
java.security.cert.X509Certificate cert = keyStoreManager.getDefaultPrimaryCertificate();
credentialImpl = new X509CredentialImpl(cert);
return credentialImpl;
} catch (Exception e) {
log.error("Error instantiating an org.wso2.carbon.identity.entitlement.wsxacml.X509CredentialImpl " +
"object for the public cert.", e);
throw new Exception("Error instantiating an org.wso2.carbon.identity.entitlement.wsxacml.X509CredentialImpl " +
"object for the public cert.", e);
}
}
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:23,代码来源:WSXACMLMessageReceiver.java
示例3: getPrivateKey
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
public Key getPrivateKey(String alias, boolean isSuperTenant) throws SecurityConfigException {
KeyStoreData[] keystores = getKeyStores(isSuperTenant);
KeyStore keyStore = null;
String privateKeyPassowrd = null;
try {
for (int i = 0; i < keystores.length; i++) {
if (KeyStoreUtil.isPrimaryStore(keystores[i].getKeyStoreName())) {
KeyStoreManager keyMan = KeyStoreManager.getInstance(tenantId);
keyStore = keyMan.getPrimaryKeyStore();
ServerConfiguration serverConfig = ServerConfiguration.getInstance();
privateKeyPassowrd = serverConfig
.getFirstProperty(RegistryResources.SecurityManagement.SERVER_PRIVATE_KEY_PASSWORD);
return keyStore.getKey(alias, privateKeyPassowrd.toCharArray());
}
}
} catch (Exception e) {
String msg = "Error has encounted while loading the key for the given alias " + alias;
log.error(msg, e);
throw new SecurityConfigException(msg);
}
return null;
}
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:25,代码来源:KeyStoreAdmin.java
示例4: SignKeyDataHolder
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
public SignKeyDataHolder() throws Exception {
try {
String keyAlias = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.KeyAlias");
KeyStoreManager keyMan = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
Certificate[] certificates = keyMan.getPrimaryKeyStore().getCertificateChain(keyAlias);
issuerPK = keyMan.getDefaultPrivateKey();
issuerCerts = new X509Certificate[certificates.length];
int i = 0;
for (Certificate certificate : certificates) {
issuerCerts[i++] = (X509Certificate) certificate;
}
signatureAlgorithm = XMLSignature.ALGO_ID_SIGNATURE_RSA;
String pubKeyAlgo = issuerCerts[0].getPublicKey().getAlgorithm();
if (pubKeyAlgo.equalsIgnoreCase("DSA")) {
signatureAlgorithm = XMLSignature.ALGO_ID_SIGNATURE_DSA;
}
} catch (Exception e) {
throw new Exception("Error while reading the key", e);
}
}
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:23,代码来源:SignKeyDataHolder.java
示例5: extractAppIdFromIdToken
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
private String extractAppIdFromIdToken(String token) {
String appId = null;
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
try {
keyStoreManager.getDefaultPrimaryCertificate();
JWSVerifier verifier =
new RSASSAVerifier((RSAPublicKey) keyStoreManager.getDefaultPublicKey());
SignedJWT jwsObject = SignedJWT.parse(token);
if (jwsObject.verify(verifier)) {
appId = jwsObject.getJWTClaimsSet().getStringClaim("appId");
}
} catch (Exception e) {
String message = "Could not extract application id from id token";
log.error(message, e);
}
return appId;
}
开发者ID:apache,项目名称:stratos,代码行数:19,代码来源:OAuthHandler.java
示例6: getServerCryptoProperties
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
public Properties getServerCryptoProperties(String privateStore, String[] trustedCertStores)
throws Exception {
Properties props = new Properties();
int tenantId = ((UserRegistry) registry).getTenantId();
if (trustedCertStores != null && trustedCertStores.length > 0) {
StringBuilder trustString = new StringBuilder();
for (String trustedCertStore : trustedCertStores) {
if (trustString.length() > 0) {
trustString.append(",");
}
trustString.append(trustedCertStore);
}
props.setProperty(ServerCrypto.PROP_ID_TRUST_STORES, trustString.toString());
}
if (privateStore != null) {
props.setProperty(ServerCrypto.PROP_ID_PRIVATE_STORE, privateStore);
KeyStoreManager keyMan = KeyStoreManager.getInstance(tenantId);
KeyStore ks = keyMan.getKeyStore(privateStore);
String privKeyAlias = KeyStoreUtil.getPrivateKeyAlias(ks);
props.setProperty(ServerCrypto.PROP_ID_DEFAULT_ALIAS, privKeyAlias);
props.setProperty(USER, privKeyAlias);
}
if (privateStore != null || (trustedCertStores != null && trustedCertStores.length > 0)) {
//Set the tenant-ID in the properties
props.setProperty(ServerCrypto.PROP_ID_TENANT_ID,
Integer.toString(tenantId));
}
return props;
}
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:37,代码来源:SecurityConfigAdmin.java
示例7: getServerCryptoProperties
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
public Properties getServerCryptoProperties(String privateStore, String[] trustedCertStores)
throws Exception {
Properties props = new Properties();
int tenantId = ((UserRegistry) registry).getTenantId();
if (trustedCertStores != null && trustedCertStores.length > 0) {
StringBuilder trustString = new StringBuilder();
for (String trustedCertStore : trustedCertStores) {
if (trustString.length() > 0) {
trustString.append(",");
}
trustString.append(trustedCertStore);
}
if (trustedCertStores.length != 0) {
props.setProperty(ServerCrypto.PROP_ID_TRUST_STORES, trustString.toString());
}
}
if (privateStore != null) {
props.setProperty(ServerCrypto.PROP_ID_PRIVATE_STORE, privateStore);
KeyStoreManager keyMan = KeyStoreManager.getInstance(tenantId);
KeyStore ks = keyMan.getKeyStore(privateStore);
String privKeyAlias = KeyStoreUtil.getPrivateKeyAlias(ks);
props.setProperty(ServerCrypto.PROP_ID_DEFAULT_ALIAS, privKeyAlias);
props.setProperty(USER, privKeyAlias);
}
if (privateStore != null || (trustedCertStores != null && trustedCertStores.length > 0)) {
//Set the tenant-ID in the properties
props.setProperty(ServerCrypto.PROP_ID_TENANT_ID,
Integer.toString(tenantId));
}
return props;
}
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:39,代码来源:SecurityConfigAdmin.java
示例8: getPrivateKey
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
private Key getPrivateKey(String tenantDomain, int tenantId) throws IdentityOAuth2Exception {
if (tenantDomain == null) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
if (tenantId == 0) {
tenantId = OAuth2Util.getTenantId(tenantDomain);
}
Key privateKey = null;
if (!(privateKeys.containsKey(tenantId))) {
// get tenant's key store manager
KeyStoreManager tenantKSM = KeyStoreManager.getInstance(tenantId);
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
// derive key store name
String ksName = tenantDomain.trim().replace(".", "-");
String jksName = ksName + ".jks";
// obtain private key
privateKey = tenantKSM.getPrivateKey(jksName, tenantDomain);
} else {
try {
privateKey = tenantKSM.getDefaultPrivateKey();
} catch (Exception e) {
log.error("Error while obtaining private key for super tenant", e);
}
}
if (privateKey != null) {
privateKeys.put(tenantId, privateKey);
}
} else {
privateKey = privateKeys.get(tenantId);
}
return privateKey;
}
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:39,代码来源:JWTTokenGenerator.java
示例9: getCertificate
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
private Certificate getCertificate(String tenantDomain, int tenantId) throws Exception {
if (tenantDomain == null) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
if (tenantId == 0) {
tenantId = OAuth2Util.getTenantId(tenantDomain);
}
Certificate publicCert = null;
if (!(publicCerts.containsKey(tenantId))) {
// get tenant's key store manager
KeyStoreManager tenantKSM = KeyStoreManager.getInstance(tenantId);
KeyStore keyStore = null;
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
// derive key store name
String ksName = tenantDomain.trim().replace(".", "-");
String jksName = ksName + ".jks";
keyStore = tenantKSM.getKeyStore(jksName);
publicCert = keyStore.getCertificate(tenantDomain);
} else {
publicCert = tenantKSM.getDefaultPrimaryCertificate();
}
if (publicCert != null) {
publicCerts.put(tenantId, publicCert);
}
} else {
publicCert = publicCerts.get(tenantId);
}
return publicCert;
}
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:35,代码来源:JWTTokenGenerator.java
示例10: validateSignature
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
/**
* This method validates the signature of the SAML Response.
* @param resp SAML Response
* @return true, if signature is valid.
*/
public static boolean validateSignature(Response resp, String keyStoreName,
String keyStorePassword, String alias, int tenantId,
String tenantDomain) {
boolean isSigValid = false;
try {
KeyStore keyStore = null;
java.security.cert.X509Certificate cert = null;
if (tenantId != MultitenantConstants.SUPER_TENANT_ID) {
// get an instance of the corresponding Key Store Manager instance
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(tenantId);
keyStore = keyStoreManager.getKeyStore(generateKSNameFromDomainName(tenantDomain));
cert = (java.security.cert.X509Certificate) keyStore.getCertificate(tenantDomain);
} else {
keyStore = KeyStore.getInstance("JKS");
keyStore.load(new FileInputStream(new File(keyStoreName)), keyStorePassword.toCharArray());
cert = (java.security.cert.X509Certificate) keyStore.getCertificate(alias);
}
if(log.isDebugEnabled()){
log.debug("Validating against "+cert.getSubjectDN().getName());
}
X509CredentialImpl credentialImpl = new X509CredentialImpl(cert);
SignatureValidator signatureValidator = new SignatureValidator(credentialImpl);
signatureValidator.validate(resp.getSignature());
isSigValid = true;
return isSigValid;
} catch (Exception e) {
if (log.isDebugEnabled()){
log.debug("Signature verification is failed for "+tenantDomain);
}
return isSigValid;
}
}
开发者ID:wso2,项目名称:carbon-commons,代码行数:38,代码来源:Util.java
示例11: getKeyStore
import org.wso2.carbon.core.util.KeyStoreManager; //导入依赖的package包/类
/**
* Gets the key store for the tenant.
* @return KeyStore
*/
private KeyStore getKeyStore() throws AxisFault{
//get tenant domain
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
//get tenantId
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
KeyStore keyStore = keyStores.get(tenantId);
if(keyStore == null){
//get tenant's key store manager
KeyStoreManager tenantKSM = KeyStoreManager.getInstance(tenantId);
try {
if(!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)){
//derive key store name
String ksName = tenantDomain.trim().replace(".", "-");
String jksName = ksName + ".jks";
keyStore = tenantKSM.getKeyStore(jksName);
}else{
keyStore = tenantKSM.getPrimaryKeyStore();
}
}catch (Exception e) {
throw new AxisFault("Error getting keystore");
}
}
return keyStore;
}
开发者ID:wso2,项目名称:carbon-data,代码行数:31,代码来源:JWTAuthorizationProvider.java
注:本文中的org.wso2.carbon.core.util.KeyStoreManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论