use of org.maxkey.crypto.keystore.KeyStoreLoader in project MaxKey by dromara.
the class ApplicationAutoConfiguration method spKeyStoreLoader.
/**
* spKeyStoreLoader .
* @return
*/
@Bean(name = "spKeyStoreLoader")
public KeyStoreLoader spKeyStoreLoader(@Value("${maxkey.saml.v20.sp.issuing.entity.id}") String entityName, @Value("${maxkey.saml.v20.sp.keystore.password}") String keystorePassword, @Value("${maxkey.saml.v20.sp.keystore}") Resource keystoreFile) {
KeyStoreLoader keyStoreLoader = new KeyStoreLoader();
keyStoreLoader.setEntityName(entityName);
keyStoreLoader.setKeystorePassword(keystorePassword);
keyStoreLoader.setKeystoreFile(keystoreFile);
return keyStoreLoader;
}
use of org.maxkey.crypto.keystore.KeyStoreLoader in project MaxKey by dromara.
the class ApplicationAutoConfiguration method keyStoreLoader.
/**
* keyStoreLoader .
* @return
*/
@Bean(name = "keyStoreLoader")
public KeyStoreLoader keyStoreLoader(@Value("${maxkey.saml.v20.idp.issuing.entity.id}") String entityName, @Value("${maxkey.saml.v20.idp.keystore.password}") String keystorePassword, @Value("${maxkey.saml.v20.idp.keystore}") Resource keystoreFile) {
KeyStoreLoader keyStoreLoader = new KeyStoreLoader();
keyStoreLoader.setEntityName(entityName);
keyStoreLoader.setKeystorePassword(keystorePassword);
keyStoreLoader.setKeystoreFile(keystoreFile);
return keyStoreLoader;
}
use of org.maxkey.crypto.keystore.KeyStoreLoader in project MaxKey by dromara.
the class AbstractAuthorizeAdapter method sign.
public Object sign(Object data, String signatureKey, String signature) {
if (ConstsBoolean.isTrue(app.getIsSignature())) {
KeyStoreLoader keyStoreLoader = WebContext.getBean("keyStoreLoader", KeyStoreLoader.class);
try {
byte[] signData = CertSigner.sign(data.toString().getBytes(), keyStoreLoader.getKeyStore(), keyStoreLoader.getEntityName(), keyStoreLoader.getKeystorePassword());
_logger.debug("signed Token : " + data);
_logger.debug("signature : " + signData.toString());
return Base64Utils.base64UrlEncode(data.toString().getBytes("UTF-8")) + "." + Base64Utils.base64UrlEncode(signData);
} catch (UnsupportedEncodingException e) {
_logger.error("UnsupportedEncodingException ", e);
} catch (Exception e) {
_logger.error("Exception ", e);
}
_logger.debug("Token {}", data);
} else {
_logger.debug("data not need sign .");
return data;
}
return null;
}
use of org.maxkey.crypto.keystore.KeyStoreLoader in project MaxKey by dromara.
the class MetadataGenerator method samlmtest.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void samlmtest() {
try {
KeyStoreLoader keyStoreLoader = new KeyStoreLoader();
keyStoreLoader.setKeystorePassword("secret");
keyStoreLoader.setKeystoreFile(new FileSystemResource("D:/JavaIDE/cert/idp-keystore.jks"));
keyStoreLoader.afterPropertiesSet();
KeyStore trustKeyStore = keyStoreLoader.getKeyStore();
IssueInstantRule issueInstantRule = new IssueInstantRule(90, 300);
ReplayCache replayCache = new ReplayCache(new MapBasedStorageService(), 14400000);
MessageReplayRule messageReplayRule = new MessageReplayRule(replayCache);
TrustResolver trustResolver = new TrustResolver(trustKeyStore, "idp", keyStoreLoader.getKeystorePassword(), issueInstantRule, messageReplayRule, "POST");
CredentialResolver credentialResolver = (CredentialResolver) trustResolver.getKeyStoreCredentialResolver();
CriteriaSet criteriaSet = new CriteriaSet();
criteriaSet.add(new EntityIDCriteria("idp"));
criteriaSet.add(new UsageCriteria(UsageType.SIGNING));
Credential signingCredential = null;
try {
signingCredential = credentialResolver.resolveSingle(criteriaSet);
} catch (SecurityException e) {
System.out.println("Credential resolve error : " + e);
throw new Exception(e);
}
IDPSSODescriptor descriptor = buildIDPSSODescriptor();
descriptor.getSingleSignOnServices().add(getSingleSignOnService("http://sso.maxkey.org/sso", null));
descriptor.getSingleSignOnServices().add(getSingleSignOnService("http://sso.maxkey.org/sso", SAMLConstants.SAML2_POST_SIMPLE_SIGN_BINDING_URI));
descriptor.getSingleLogoutServices().add(getSingleLogoutService("http://sso.maxkey.org/slo", null));
descriptor.getKeyDescriptors().add(generateEncryptionKeyDescriptor(signingCredential));
descriptor.getKeyDescriptors().add(generateSignKeyDescriptor(signingCredential));
descriptor.getNameIDFormats().add(generateNameIDFormat(NameIDType.TRANSIENT));
descriptor.getNameIDFormats().add(generateNameIDFormat(NameIDType.PERSISTENT));
descriptor.getNameIDFormats().add(generateNameIDFormat(NameIDType.EMAIL));
descriptor.getNameIDFormats().add(generateNameIDFormat(NameIDType.ENTITY));
descriptor.getContactPersons().add(getContactPerson("maxkey", "shi", "ming", "shimingxy@163.com", "18724229876", null));
descriptor.setOrganization(getOrganization("maxkey", "maxkey", "http://sso.maxkey.org"));
String entityId = "http://www.test.com";
EntityDescriptor entityDescriptor = buildEntityDescriptor(entityId, descriptor);
String descriptorelementxml = XMLHelper.prettyPrintXML(marshallerMetadata(entityDescriptor));
System.out.println("descriptor elementxm:\\n");
System.out.println(descriptorelementxml);
logger.info(descriptorelementxml);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations