
net.customware.license.support.event.LicenseEvent Maven / Gradle / Ivy
The newest version!
package net.customware.license.support.event;
import de.schlichtherle.license.LicenseContent;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.security.auth.x500.X500Principal;
import java.util.HashMap;
import java.util.Map;
/**
* @author abi.dzar
* @author aneel
* @since 20130912
*/
public abstract class LicenseEvent {
private LicenseContent licenseContent;
protected LicenseEvent(LicenseContent licenseContent){
this.licenseContent = licenseContent;
}
public LicenseContent getSource() {
return licenseContent;
}
public Map getSourceAsMap(){
return new HashMap() {{
Map holder = extractPrincipal(licenseContent.getHolder());
Map issuer = extractPrincipal(licenseContent.getIssuer());
put("issuer", issuer);
put("holder", holder);
put("subject", licenseContent.getSubject());
put("issued", licenseContent.getIssued());
put("notBefore", licenseContent.getNotBefore());
put("notAfter", licenseContent.getNotAfter());
put("consumerType", licenseContent.getConsumerType());
put("consumerAmount", licenseContent.getConsumerAmount());
put("info", licenseContent.getInfo());
put("extra" , licenseContent.getExtra());
}};
}
private Map extractPrincipal(X500Principal principal){
Map details = new HashMap();
try {
LdapName ldapDN = new LdapName(principal.getName("RFC1779"));
for (Rdn rdn : ldapDN.getRdns()) {
String type = rdn.getType();
if(type.startsWith("OID")){
type = "email";
}
details.put(type , rdn.getValue());
}
} catch (InvalidNameException e) {
throw new IllegalStateException("License's principals are in invalid format: " + e.getMessage());
}
return details;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy