下面列出了java.security.cert.PKIXCertPathValidatorResult#javax.naming.InvalidNameException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Adds components to the end of remaining name.
*
* @param name The components to add. Can be null.
* @see #getRemainingName
* @see #setRemainingName
* @see #appendRemainingComponent
*/
public void appendRemainingName(Name name) {
// System.out.println("appendingRemainingName: " + name.toString());
// Exception e = new Exception();
// e.printStackTrace();
if (name != null) {
if (this.remainingName != null) {
try {
this.remainingName.addAll(name);
} catch (InvalidNameException e) {
// ignore; shouldn't happen for composite name
}
} else {
this.remainingName = (Name)(name.clone());
}
}
}
/**
* Compares this principal to the specified object.
*
* @param object The object to compare this principal against.
* @return true if they are equal; false otherwise.
*/
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof LdapPrincipal) {
try {
return
name.equals(getLdapName(((LdapPrincipal)object).getName()));
} catch (InvalidNameException e) {
return false;
}
}
return false;
}
private Rdn doParse(Rdn rdn) throws InvalidNameException {
while (cur < len) {
consumeWhitespace();
String attrType = parseAttrType();
consumeWhitespace();
if (cur >= len || chars[cur] != '=') {
throw new InvalidNameException("Invalid name: " + name);
}
++cur; // consume '='
consumeWhitespace();
String value = parseAttrValue();
consumeWhitespace();
rdn.put(attrType, Rdn.unescapeValue(value));
if (cur >= len || chars[cur] != '+') {
break;
}
++cur; // consume '+'
}
rdn.sort();
return rdn;
}
private void createSelfSignedCertificate() {
idControll.setUpData(commonNameField.getText(), organizationUnitField.getText(), organizationField.getText(), countryField.getText(),
cityField.getText());
try {
KeyPair keyPair = idControll.createKeyPair();
X509Certificate cert = idControll.createSelfSignedCertificate(keyPair);
if (saveCertToFile.isSelected()) {
PemBuilder pemBuilder = new PemHelper().new PemBuilder();
pemBuilder.add(keyPair.getPrivate());
pemBuilder.add(cert);
pemBuilder.saveToPemFile(IdentityController.CERT_FILE);
JOptionPane.showMessageDialog(null,
Res.getString("dialog.self.signed.certificate.has.been.created") + IdentityController.SECURITY_DIRECTORY.toString());
} else {
try {
idControll.addEntryToKeyStore(cert, keyPair.getPrivate());
} catch (HeadlessException | InvalidNameException | KeyStoreException e) {
Log.error("Couldn't save entry to IdentityStore", e);
}
}
} catch (NoSuchAlgorithmException | NoSuchProviderException | IOException | OperatorCreationException | CertificateException e1) {
Log.error("Couldn't create Self Signed Certificate", e1);
}
}
private String parseAttrType() throws InvalidNameException {
final int beg = cur;
while (cur < len) {
char c = chars[cur];
if (Character.isLetterOrDigit(c) ||
c == '.' ||
c == '-' ||
c == ' ') {
++cur;
} else {
break;
}
}
// Back out any trailing spaces.
while ((cur > beg) && (chars[cur - 1] == ' ')) {
--cur;
}
if (beg == cur) {
throw new InvalidNameException("Invalid name: " + name);
}
return new String(chars, beg, cur - beg);
}
/**
* Retrieves the named object.
*
* @param strName the name of the object to look up
* @return the object bound to name
*/
@Override
protected Object doLookup(String strName) {
Name name;
try {
name = getEscapedJndiName(strName);
} catch (InvalidNameException e) {
log.info(sm.getString("resources.invalidName", strName), e);
return null;
}
if (name.isEmpty())
return this;
Entry entry = treeLookup(name);
if (entry == null)
return null;
ZipEntry zipEntry = entry.getEntry();
if (zipEntry.isDirectory())
return new WARDirContext(base, entry);
else
return new WARResource(entry.getEntry());
}
/**
* Add and remove a user to the LDAP repository.
*
* @throws InvalidNameException
*/
@Test
public void addUser() throws InvalidNameException {
Person walter = new Person();
walter.setFullName("Walter White");
walter.setUid("heisenberg");
walter.setLastname("White");
personRepository.save(walter);
List<Person> people = personRepository.findByUid("heisenberg");
assertThat(people).hasSize(1).extracting("fullName").contains("Walter White");
personRepository.delete(people.get(0));
}
private String parseAttrType() throws InvalidNameException {
final int beg = cur;
while (cur < len) {
char c = chars[cur];
if (Character.isLetterOrDigit(c) ||
c == '.' ||
c == '-' ||
c == ' ') {
++cur;
} else {
break;
}
}
// Back out any trailing spaces.
while ((cur > beg) && (chars[cur - 1] == ' ')) {
--cur;
}
if (beg == cur) {
throw new InvalidNameException("Invalid name: " + name);
}
return new String(chars, beg, cur - beg);
}
private String parseStringAttrValue() throws InvalidNameException {
final int beg = cur;
int esc = -1; // index of the most recently escaped character
while ((cur < len) && !atTerminator()) {
if (chars[cur] == '\\') {
++cur; // consume backslash, then what follows
esc = cur;
}
++cur;
}
if (cur > len) { // 'twas backslash followed by nothing
throw new InvalidNameException("Invalid name: " + name);
}
// Trim off (unescaped) trailing whitespace.
int end;
for (end = cur; end > beg; end--) {
if (!isWhitespace(chars[end - 1]) || (esc == end - 1)) {
break;
}
}
return new String(chars, beg, end - beg);
}
public DistinguishedName(X500Principal principal) throws TechnicalConnectorException {
CertificateParser parser = new CertificateParser(principal.getName("RFC2253"));
this.setId(parser.getId());
this.setType(parser.getIdentifier());
this.setApplicationId(parser.getApplication());
try {
List<Rdn> rdns = (new LdapName(principal.getName("RFC1779"))).getRdns();
Iterator i$ = rdns.iterator();
while(i$.hasNext()) {
Rdn rdn = (Rdn)i$.next();
if (rdn.getType().equals("OU")) {
String value = this.getValue(rdn.getValue());
if (!"eHealth-platform Belgium".equals(value) && !value.contains("=")) {
this.setName(this.getValue(rdn.getValue()));
break;
}
}
}
} catch (InvalidNameException var7) {
throw new IllegalArgumentException("Invalid Principal", var7);
}
}
/**
* Constructs an Rdn from the given attribute set. See
* {@link javax.naming.directory.Attributes Attributes}.
* <p>
* The string attribute values are not interpreted as
* <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a>
* formatted RDN strings. That is, the values are used
* literally (not parsed) and assumed to be unescaped.
*
* @param attrSet The non-null and non-empty attributes containing
* type/value mappings.
* @throws InvalidNameException If contents of <tt>attrSet</tt> cannot
* be used to construct a valid RDN.
*/
public Rdn(Attributes attrSet) throws InvalidNameException {
if (attrSet.size() == 0) {
throw new InvalidNameException("Attributes cannot be empty");
}
entries = new ArrayList<>(attrSet.size());
NamingEnumeration<? extends Attribute> attrs = attrSet.getAll();
try {
for (int nEntries = 0; attrs.hasMore(); nEntries++) {
RdnEntry entry = new RdnEntry();
Attribute attr = attrs.next();
entry.type = attr.getID();
entry.value = attr.get();
entries.add(nEntries, entry);
}
} catch (NamingException e) {
InvalidNameException e2 = new InvalidNameException(
e.getMessage());
e2.initCause(e);
throw e2;
}
sort(); // arrange entries for comparison
}
private String parseQuotedAttrValue() throws InvalidNameException {
final int beg = cur;
++cur; // consume '"'
while ((cur < len) && chars[cur] != '"') {
if (chars[cur] == '\\') {
++cur; // consume backslash, then what follows
}
++cur;
}
if (cur >= len) { // no closing quote
throw new InvalidNameException("Invalid name: " + name);
}
++cur; // consume closing quote
return new String(chars, beg, cur - beg);
}
private String parseStringAttrValue() throws InvalidNameException {
final int beg = cur;
int esc = -1; // index of the most recently escaped character
while ((cur < len) && !atTerminator()) {
if (chars[cur] == '\\') {
++cur; // consume backslash, then what follows
esc = cur;
}
++cur;
}
if (cur > len) { // 'twas backslash followed by nothing
throw new InvalidNameException("Invalid name: " + name);
}
// Trim off (unescaped) trailing whitespace.
int end;
for (end = cur; end > beg; end--) {
if (!isWhitespace(chars[end - 1]) || (esc == end - 1)) {
break;
}
}
return new String(chars, beg, end - beg);
}
private String decodeNaptr(int pos) throws InvalidNameException {
int order = getUShort(pos);
pos += 2;
int preference = getUShort(pos);
pos += 2;
StringBuffer flags = new StringBuffer();
pos += decodeCharString(pos, flags);
StringBuffer services = new StringBuffer();
pos += decodeCharString(pos, services);
StringBuffer regexp = new StringBuffer(rdlen);
pos += decodeCharString(pos, regexp);
DnsName replacement = decodeName(pos);
return (order + " " + preference + " " + flags + " " +
services + " " + regexp + " " + replacement);
}
/**
* Constructs an Rdn from the given attribute set. See
* {@link javax.naming.directory.Attributes Attributes}.
* <p>
* The string attribute values are not interpreted as
* <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a>
* formatted RDN strings. That is, the values are used
* literally (not parsed) and assumed to be unescaped.
*
* @param attrSet The non-null and non-empty attributes containing
* type/value mappings.
* @throws InvalidNameException If contents of <tt>attrSet</tt> cannot
* be used to construct a valid RDN.
*/
public Rdn(Attributes attrSet) throws InvalidNameException {
if (attrSet.size() == 0) {
throw new InvalidNameException("Attributes cannot be empty");
}
entries = new ArrayList<>(attrSet.size());
NamingEnumeration<? extends Attribute> attrs = attrSet.getAll();
try {
for (int nEntries = 0; attrs.hasMore(); nEntries++) {
RdnEntry entry = new RdnEntry();
Attribute attr = attrs.next();
entry.type = attr.getID();
entry.value = attr.get();
entries.add(nEntries, entry);
}
} catch (NamingException e) {
InvalidNameException e2 = new InvalidNameException(
e.getMessage());
e2.initCause(e);
throw e2;
}
sort(); // arrange entries for comparison
}
/**
* Adds components to the end of remaining name.
*
* @param name The components to add. Can be null.
* @see #getRemainingName
* @see #setRemainingName
* @see #appendRemainingComponent
*/
public void appendRemainingName(Name name) {
// System.out.println("appendingRemainingName: " + name.toString());
// Exception e = new Exception();
// e.printStackTrace();
if (name != null) {
if (this.remainingName != null) {
try {
this.remainingName.addAll(name);
} catch (InvalidNameException e) {
// ignore; shouldn't happen for composite name
}
} else {
this.remainingName = (Name)(name.clone());
}
}
}
private String parseAttrType() throws InvalidNameException {
final int beg = cur;
while (cur < len) {
char c = chars[cur];
if (Character.isLetterOrDigit(c) ||
c == '.' ||
c == '-' ||
c == ' ') {
++cur;
} else {
break;
}
}
// Back out any trailing spaces.
while ((cur > beg) && (chars[cur - 1] == ' ')) {
--cur;
}
if (beg == cur) {
throw new InvalidNameException("Invalid name: " + name);
}
return new String(chars, beg, cur - beg);
}
private String parseQuotedAttrValue() throws InvalidNameException {
final int beg = cur;
++cur; // consume '"'
while ((cur < len) && chars[cur] != '"') {
if (chars[cur] == '\\') {
++cur; // consume backslash, then what follows
}
++cur;
}
if (cur >= len) { // no closing quote
throw new InvalidNameException("Invalid name: " + name);
}
++cur; // consume closing quote
return new String(chars, beg, cur - beg);
}
private String parseAttrType() throws InvalidNameException {
final int beg = cur;
while (cur < len) {
char c = chars[cur];
if (Character.isLetterOrDigit(c) ||
c == '.' ||
c == '-' ||
c == ' ') {
++cur;
} else {
break;
}
}
// Back out any trailing spaces.
while ((cur > beg) && (chars[cur - 1] == ' ')) {
--cur;
}
if (beg == cur) {
throw new InvalidNameException("Invalid name: " + name);
}
return new String(chars, beg, cur - beg);
}
public static void removeInstance(String uid, String name, Properties properties) {
//TODO: theoretically non-threadsafe...
if (name!=null) {
log.info("Unbinding factory from JNDI name: " + name);
try {
Context ctx = NamingHelper.getInitialContext(properties);
ctx.unbind(name);
log.info("Unbound factory from JNDI name: " + name);
}
catch (InvalidNameException ine) {
log.error("Invalid JNDI name: " + name, ine);
}
catch (NamingException ne) {
log.warn("Could not unbind factory from JNDI", ne);
}
NAMED_INSTANCES.remove(name);
}
INSTANCES.remove(uid);
}
/**
* Compares this principal to the specified object.
*
* @param object The object to compare this principal against.
* @return true if they are equal; false otherwise.
*/
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof LdapPrincipal) {
try {
return
name.equals(getLdapName(((LdapPrincipal)object).getName()));
} catch (InvalidNameException e) {
return false;
}
}
return false;
}
List<Rdn> parseDn() throws InvalidNameException {
cur = 0;
// ArrayList<Rdn> rdns =
// new ArrayList<Rdn>(len / 3 + 10); // leave room for growth
ArrayList<Rdn> rdns =
new ArrayList<>(len / 3 + 10); // leave room for growth
if (len == 0) {
return rdns;
}
rdns.add(doParse(new Rdn()));
while (cur < len) {
if (chars[cur] == ',' || chars[cur] == ';') {
++cur;
rdns.add(0, doParse(new Rdn()));
} else {
throw new InvalidNameException("Invalid name: " + name);
}
}
return rdns;
}
public static List<PDFSignatureInfo> getPDFSignatureInfo(InputStream is ) throws IOException, CertificateException,
NoSuchAlgorithmException, InvalidKeyException,
NoSuchProviderException, SignatureException, InvalidNameException {
byte[] byteArray = getbyteArray(is);
return getPDFSignatureInfo(byteArray);
}
private String parseAttrValue() throws InvalidNameException {
if (cur < len && chars[cur] == '#') {
return parseBinaryAttrValue();
} else if (cur < len && chars[cur] == '"') {
return parseQuotedAttrValue();
} else {
return parseStringAttrValue();
}
}
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
s.defaultReadObject();
entries = new ArrayList<>(DEFAULT_SIZE);
String unparsed = (String) s.readObject();
try {
(new Rfc2253Parser(unparsed)).parseRdn(this);
} catch (InvalidNameException e) {
// shouldn't happen
throw new java.io.StreamCorruptedException(
"Invalid name: " + unparsed);
}
}
static String extractCN(final String subjectPrincipal) throws SSLException {
if (subjectPrincipal == null) {
return null;
}
try {
final LdapName subjectDN = new LdapName(subjectPrincipal);
final List<Rdn> rdns = subjectDN.getRdns();
for (int i = rdns.size() - 1; i >= 0; i--) {
final Rdn rds = rdns.get(i);
final Attributes attributes = rds.toAttributes();
final Attribute cn = attributes.get("cn");
if (cn != null) {
try {
final Object value = cn.get();
if (value != null) {
return value.toString();
}
} catch (NoSuchElementException | NamingException ignore) {
//
}
}
}
return null;
} catch (InvalidNameException e) {
throw new SSLException(subjectPrincipal + " is not a valid X500 distinguished name");
}
}
private String parseAttrValue() throws InvalidNameException {
if (cur < len && chars[cur] == '#') {
return parseBinaryAttrValue();
} else if (cur < len && chars[cur] == '"') {
return parseQuotedAttrValue();
} else {
return parseStringAttrValue();
}
}
/**
* Adds a single component to the end of remaining name.
*
* @param name The component to add. Can be null.
* @see #getRemainingName
* @see #appendRemainingName
*/
public void appendRemainingComponent(String name) {
if (name != null) {
CompositeName rname = new CompositeName();
try {
rname.add(name);
} catch (InvalidNameException e) {
// ignore; shouldn't happen for empty composite name
}
appendRemainingName(rname);
}
}
private String checkName(String name) throws CertStoreException {
if (name == null) {
throw new CertStoreException("Name absent");
}
try {
if (new CompositeName(name).size() > 1) {
throw new CertStoreException("Invalid name: " + name);
}
} catch (InvalidNameException ine) {
throw new CertStoreException("Invalid name: " + name, ine);
}
return name;
}
private String extractCommonName(String certName) throws InvalidNameException {
String name = null;
LdapName ldapDN = new LdapName(certName);
for (Rdn rdn : ldapDN.getRdns()) {
if (rdn.getType().equals("CN")) {
name = rdn.getValue().toString();
}
}
return name;
}