本文整理汇总了Java中org.bouncycastle.asn1.x500.style.IETFUtils.valueToString方法的典型用法代码示例。如果您正苦于以下问题:Java IETFUtils.valueToString方法的具体用法?Java IETFUtils.valueToString怎么用?Java IETFUtils.valueToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.asn1.x500.style.IETFUtils
的用法示例。
在下文中一共展示了IETFUtils.valueToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rolesFromDN
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
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 {
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;
}
示例2: extractJidAndName
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
public static Pair<Jid,String> extractJidAndName(X509Certificate certificate) throws CertificateEncodingException, InvalidJidException, CertificateParsingException {
Collection<List<?>> alternativeNames = certificate.getSubjectAlternativeNames();
List<String> emails = new ArrayList<>();
if (alternativeNames != null) {
for(List<?> san : alternativeNames) {
Integer type = (Integer) san.get(0);
if (type == 1) {
emails.add((String) san.get(1));
}
}
}
X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject();
if (emails.size() == 0) {
emails.add(IETFUtils.valueToString(x500name.getRDNs(BCStyle.EmailAddress)[0].getFirst().getValue()));
}
String name = IETFUtils.valueToString(x500name.getRDNs(BCStyle.CN)[0].getFirst().getValue());
if (emails.size() >= 1) {
return new Pair<>(Jid.fromString(emails.get(0)), name);
} else {
return null;
}
}
示例3: checkRdn
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
private boolean checkRdn(RDN certRDN, AttributeTypeAndValue expectedTypeAndValue) {
String expectedValue = IETFUtils.valueToString(expectedTypeAndValue.getValue());
boolean constraintFound = false;
AttributeTypeAndValue[] typesAndValues = certRDN.getTypesAndValues();
for (AttributeTypeAndValue typesAndValue : typesAndValues) {
if (typesAndValue.getType().equals(expectedTypeAndValue.getType())) {
String actualValue = IETFUtils.valueToString(typesAndValue.getValue());
if (actualValue.equals(expectedValue)) {
constraintFound = true;
} else {
constraintFound = false;
break;
}
}
}
return constraintFound;
}
示例4: getSubjectCNFromCertificate
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
public static String getSubjectCNFromCertificate(X509Certificate certificate) {
try {
X500Name x500name = new JcaX509CertificateHolder(certificate).getIssuer();
RDN cn = x500name.getRDNs(BCStyle.CN)[0];
return IETFUtils.valueToString(cn.getFirst().getValue());
} catch (CertificateEncodingException e) {
log.error("Unable to get issuer CN", e);
return null;
}
}
示例5: handle
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
@Override
public HttpResponse handle(HttpRequest request, MiddlewareChain chain) {
request = MixinUtils.mixin(request, new Class[]{PrincipalAvailable.class});
String clientDN = request.getHeaders().get("X-Client-DN");
if (!isAuthenticated((PrincipalAvailable) request) && clientDN != null) {
RDN cn = new X500Name(clientDN).getRDNs(BCStyle.CN)[0];
String account = IETFUtils.valueToString(cn.getFirst().getValue());
}
return castToHttpResponse(chain.next(request));
}
示例6: extractJidAndName
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
public static Pair<Jid,String> extractJidAndName(X509Certificate certificate) throws CertificateEncodingException, InvalidJidException, CertificateParsingException {
Collection<List<?>> alternativeNames = certificate.getSubjectAlternativeNames();
List<String> emails = new ArrayList<>();
if (alternativeNames != null) {
for(List<?> san : alternativeNames) {
Integer type = (Integer) san.get(0);
if (type == 1) {
emails.add((String) san.get(1));
}
}
}
X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject();
if (emails.size() == 0 && x500name.getRDNs(BCStyle.EmailAddress).length > 0) {
emails.add(IETFUtils.valueToString(x500name.getRDNs(BCStyle.EmailAddress)[0].getFirst().getValue()));
}
String name = x500name.getRDNs(BCStyle.CN).length > 0 ? IETFUtils.valueToString(x500name.getRDNs(BCStyle.CN)[0].getFirst().getValue()) : null;
if (emails.size() >= 1) {
return new Pair<>(Jid.fromString(emails.get(0)), name);
} else if (name != null){
try {
Jid jid = Jid.fromString(name);
if (jid.isBareJid() && !jid.isDomainJid()) {
return new Pair<>(jid,null);
}
} catch (InvalidJidException e) {
return null;
}
}
return null;
}
示例7: getEmailFromCert
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
/**
* Extract email addresses from a certificate
*
* @param cert the X509 certificate holder
* @return a List of all email addresses found
* @throws CertificateException
*/
private static List<String> getEmailFromCert(X509CertificateHolder cert)
throws CertificateException {
List<String> res = new ArrayList<>();
X500Name subject = cert.getSubject();
for (RDN emails : subject.getRDNs(BCStyle.EmailAddress)) {
for (AttributeTypeAndValue emailAttr: emails.getTypesAndValues()) {
log.debug("Add email from RDN: " + IETFUtils.valueToString(emailAttr.getValue()));
res.add(IETFUtils.valueToString(emailAttr.getValue()));
}
}
Extension subjectAlternativeNames = cert
.getExtension(Extension.subjectAlternativeName);
if (subjectAlternativeNames != null) {
for (GeneralName name : GeneralNames.getInstance(
subjectAlternativeNames.getParsedValue()).getNames()) {
if (name.getTagNo() == GeneralName.rfc822Name) {
String email = IETFUtils.valueToString(name.getName());
log.debug("Add email from subjectAlternativeName: " + email);
res.add(email);
}
}
}
return res;
}
示例8: extractX509CSRCommonName
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
public static String extractX509CSRCommonName(PKCS10CertificationRequest certReq) {
String cn = null;
X500Name x500name = certReq.getSubject();
RDN cnRdn = x500name.getRDNs(BCStyle.CN)[0];
if (cnRdn != null) {
cn = IETFUtils.valueToString(cnRdn.getFirst().getValue());
}
return cn;
}
示例9: extractX509CertCommonName
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
public static String extractX509CertCommonName(X509Certificate x509Cert) {
// in case there are multiple CNs, we're only looking at the first one
String cn = null;
String principalName = x509Cert.getSubjectX500Principal().getName();
if (principalName != null && !principalName.isEmpty()) {
X500Name x500name = new X500Name(principalName);
RDN cnRdn = x500name.getRDNs(BCStyle.CN)[0];
if (cnRdn != null) {
cn = IETFUtils.valueToString(cnRdn.getFirst().getValue());
}
}
return cn;
}
示例10: extractJidAndName
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
public static Pair<Jid, String> extractJidAndName(X509Certificate certificate) throws CertificateEncodingException, InvalidJidException, CertificateParsingException {
Collection<List<?>> alternativeNames = certificate.getSubjectAlternativeNames();
List<String> emails = new ArrayList<>();
if (alternativeNames != null) {
for (List<?> san : alternativeNames) {
Integer type = (Integer) san.get(0);
if (type == 1) {
emails.add((String) san.get(1));
}
}
}
X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject();
if (emails.size() == 0 && x500name.getRDNs(BCStyle.EmailAddress).length > 0) {
emails.add(IETFUtils.valueToString(x500name.getRDNs(BCStyle.EmailAddress)[0].getFirst().getValue()));
}
String name = x500name.getRDNs(BCStyle.CN).length > 0 ? IETFUtils.valueToString(x500name.getRDNs(BCStyle.CN)[0].getFirst().getValue()) : null;
if (emails.size() >= 1) {
return new Pair<>(Jid.fromString(emails.get(0)), name);
} else if (name != null) {
try {
Jid jid = Jid.fromString(name);
if (jid.isBareJid() && !jid.isDomainJid()) {
return new Pair<>(jid, null);
}
} catch (InvalidJidException e) {
return null;
}
}
return null;
}
示例11: getSingleRDN
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
private String getSingleRDN(ASN1ObjectIdentifier oid) {
RDN[] rdn = mName.getRDNs(oid);
if (rdn.length > 0) {
return IETFUtils.valueToString(rdn[0].getFirst().getValue());
}
return null;
}
示例12: getSubjectCommonName
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
/**
* @param aCert
* Source certificate. May not be <code>null</code>.
* @return The common name of the certificate subject
* @throws CertificateEncodingException
* In case of an internal error
*/
@Nonnull
public static String getSubjectCommonName (@Nonnull final X509Certificate aCert) throws CertificateEncodingException
{
ValueEnforcer.notNull (aCert, "Certificate");
final X500Name x500name = new JcaX509CertificateHolder (aCert).getSubject ();
final RDN cn = x500name.getRDNs (BCStyle.CN)[0];
return IETFUtils.valueToString (cn.getFirst ().getValue ());
}
示例13: getSubject
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
public SubjectInfo getSubject(X500Name requestedSubject)
throws CertprofileException, BadCertTemplateException {
SubjectInfo subjectInfo = certprofile.getSubject(requestedSubject);
RDN[] countryRdns = subjectInfo.grantedSubject().getRDNs(ObjectIdentifiers.DN_C);
if (countryRdns != null) {
for (RDN rdn : countryRdns) {
String textValue = IETFUtils.valueToString(rdn.getFirst().getValue());
if (!SubjectDnSpec.isValidCountryAreaCode(textValue)) {
throw new BadCertTemplateException("invalid country/area code '" + textValue
+ "'");
}
}
}
return subjectInfo;
}
示例14: getUserName
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
public String getUserName()
{
try {
X500Name x500name = new JcaX509CertificateHolder(clientCert).getSubject();
RDN cn = x500name.getRDNs(BCStyle.CN)[0];
return IETFUtils.valueToString(cn.getFirst().getValue());
} catch (CertificateEncodingException e) {
return "";
}
}
示例15: ietfUtilsTest
import org.bouncycastle.asn1.x500.style.IETFUtils; //导入方法依赖的package包/类
private void ietfUtilsTest()
throws Exception
{
IETFUtils.valueToString(new DERUTF8String(" "));
}