List of usage examples for org.bouncycastle.asn1.x500 X500Name getRDNs
public RDN[] getRDNs(ASN1ObjectIdentifier attributeType)
From source file:ee.ria.xroad.common.util.CertUtils.java
License:Open Source License
/** * @param name the name//from w w w. j a va2s .c om * @param id the identifier of the value * @return the RDN value from the X500Name. */ public static String getRDNValue(X500Name name, ASN1ObjectIdentifier id) { RDN[] cnList = name.getRDNs(id); if (cnList.length == 0) { return null; } return IETFUtils.valueToString(cnList[0].getFirst().getValue()); }
From source file:eu.europa.esig.dss.DSSASN1Utils.java
License:Open Source License
public static String extractAttributeFromX500Principal(ASN1ObjectIdentifier identifier, X500Principal X500PrincipalName) { final X500Name x500Name = X500Name.getInstance(X500PrincipalName.getEncoded()); RDN[] rdns = x500Name.getRDNs(identifier); if (rdns.length > 0) { return rdns[0].getFirst().getValue().toString(); }// w w w. j a va 2s .co m return null; }
From source file:io.macgyver.core.util.CertChecker.java
License:Apache License
public String extractCN(X509Certificate cert) throws GeneralSecurityException { X500Name x500name = new JcaX509CertificateHolder(cert).getSubject(); RDN cn = x500name.getRDNs(BCStyle.CN)[0]; String valx = IETFUtils.valueToString(cn.getFirst().getValue()); return valx;/*from ww w. j a v a 2 s .c om*/ }
From source file:keywhiz.auth.ldap.LdapAuthenticator.java
License:Apache License
private Set<String> rolesFromDN(String userDN) throws LDAPException, GeneralSecurityException { SearchRequest searchRequest = new SearchRequest(config.getRoleBaseDN(), SearchScope.SUB, Filter.createEqualityFilter("uniqueMember", userDN)); Set<String> roles = Sets.newLinkedHashSet(); LDAPConnection connection = connectionFactory.getLDAPConnection(); try {//from w w w . java 2s . co m SearchResult sr = connection.search(searchRequest); for (SearchResultEntry sre : sr.getSearchEntries()) { X500Name x500Name = new X500Name(sre.getDN()); RDN[] rdns = x500Name.getRDNs(BCStyle.CN); if (rdns.length == 0) { logger.error("Could not create X500 Name for role:" + sre.getDN()); } else { String commonName = IETFUtils.valueToString(rdns[0].getFirst().getValue()); roles.add(commonName); } } } finally { connection.close(); } return roles; }
From source file:keywhiz.service.providers.ClientAuthFactory.java
License:Apache License
static Optional<String> getClientName(ContainerRequest request) { Principal principal = request.getSecurityContext().getUserPrincipal(); if (principal == null) { return Optional.empty(); }//w w w .j ava2 s .c o m X500Name name = new X500Name(principal.getName()); RDN[] rdns = name.getRDNs(BCStyle.CN); if (rdns.length == 0) { logger.warn("Certificate does not contain CN=xxx,...: {}", principal.getName()); return Optional.empty(); } return Optional.of(IETFUtils.valueToString(rdns[0].getFirst().getValue())); }
From source file:model.CCAlias.java
License:Open Source License
private String getCN() throws CertificateEncodingException { X509Certificate x509cert = (X509Certificate) getMainCertificate(); org.bouncycastle.asn1.x500.X500Name x500name = new JcaX509CertificateHolder(x509cert).getSubject(); RDN rdn = x500name.getRDNs(BCStyle.CN)[0]; return IETFUtils.valueToString(rdn.getFirst().getValue()); }
From source file:model.SignatureValidation.java
License:Open Source License
public String getSignerName() { X509Certificate x509cert = (X509Certificate) pdfPkcs7.getSigningCertificate(); org.bouncycastle.asn1.x500.X500Name x500name = null; try {//from www .jav a 2 s. c o m x500name = new JcaX509CertificateHolder(x509cert).getSubject(); } catch (CertificateEncodingException ex) { return Bundle.getBundle().getString("unknown"); } RDN rdn = x500name.getRDNs(BCStyle.CN)[0]; return WordUtils.capitalize(IETFUtils.valueToString(rdn.getFirst().getValue()).toLowerCase()); }
From source file:net.jmhertlein.mcanalytics.api.auth.SSLUtil.java
License:Open Source License
public static Set<String> getNames(ASN1ObjectIdentifier type, X500Name name) { return Stream.of(name.getRDNs(type)).flatMap(n -> Stream.of(n.getTypesAndValues())) .map(n -> IETFUtils.valueToString(n.getValue())).collect(Collectors.toSet()); }
From source file:net.maritimecloud.identityregistry.keycloak.spi.authenticators.certificate.utils.CertificateUtil.java
License:Apache License
/** * Extract a value from the DN extracted from a certificate * * @param x500name//from www .jav a 2 s. c o m * @param style * @return */ public static String getElement(X500Name x500name, ASN1ObjectIdentifier style) { try { RDN cn = x500name.getRDNs(style)[0]; return valueToString(cn.getFirst().getValue()); } catch (ArrayIndexOutOfBoundsException e) { return ""; } }
From source file:net.maritimecloud.identityregistry.security.X509UserDetailsService.java
License:Apache License
/** * Extract a value from the DN extracted from a certificate * // ww w . j a v a2s . co m * @param x500name * @param style * @return */ private String getElement(X500Name x500name, ASN1ObjectIdentifier style) { RDN cn = x500name.getRDNs(style)[0]; return IETFUtils.valueToString(cn.getFirst().getValue()); }