Java Code Examples for javax.naming.InvalidNameException

The following examples show how to use javax.naming.InvalidNameException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ResolveResult.java    License: Apache License 2.0 6 votes vote down vote up
/**
      * 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());
            }
        }
    }
 
Example #2
Source Project: jdk8u_jdk   Author: JetBrains   File: LdapPrincipal.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: Rfc2253Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
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;
        }
 
Example #4
Source Project: Spark   Author: igniterealtime   File: MutualAuthenticationSettingsPanel.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
   }
 
Example #5
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Rfc2253Parser.java    License: Apache License 2.0 6 votes vote down vote up
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);
        }
 
Example #6
Source Project: Tomcat7.0.67   Author: tryandcatch   File: WARDirContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #7
Source Project: spring-data-examples   Author: spring-projects   File: PersonRepositoryIntegrationTests.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #8
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Rfc2253Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
        }
 
Example #9
Source Project: jdk8u60   Author: chenghanpeng   File: Rfc2253Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
        }
 
Example #10
Source Project: freehealth-connector   Author: taktik   File: DistinguishedName.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
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);
   }
}
 
Example #11
Source Project: openjdk-8-source   Author: keerath   File: Rdn.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
}
 
Example #12
Source Project: dragonwell8_jdk   Author: alibaba   File: Rfc2253Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
        }
 
Example #13
Source Project: dragonwell8_jdk   Author: alibaba   File: Rfc2253Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
        }
 
Example #14
Source Project: openjdk-8   Author: bpupadhyaya   File: ResourceRecord.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #15
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Rdn.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
}
 
Example #16
Source Project: jdk8u60   Author: chenghanpeng   File: ResolveResult.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
      * 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());
            }
        }
    }
 
Example #17
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: Rfc2253Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
        }
 
Example #18
Source Project: jdk8u60   Author: chenghanpeng   File: Rfc2253Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
        }
 
Example #19
Source Project: TencentKona-8   Author: Tencent   File: Rfc2253Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
        }
 
Example #20
Source Project: cacheonix-core   Author: cacheonix   File: SessionFactoryObjectFactory.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
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);

}
 
Example #21
Source Project: openjdk-8   Author: bpupadhyaya   File: LdapPrincipal.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source Project: TencentKona-8   Author: Tencent   File: Rfc2253Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #23
Source Project: pdf-sign-check   Author: spapas   File: PDFSignatureInfoParser.java    License: MIT License 5 votes vote down vote up
public static List<PDFSignatureInfo> getPDFSignatureInfo(InputStream is ) throws IOException, CertificateException,
        NoSuchAlgorithmException, InvalidKeyException,
        NoSuchProviderException, SignatureException, InvalidNameException {

    byte[] byteArray = getbyteArray(is);
    return getPDFSignatureInfo(byteArray);
}
 
Example #24
Source Project: jdk8u60   Author: chenghanpeng   File: Rfc2253Parser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String parseAttrValue() throws InvalidNameException {

            if (cur < len && chars[cur] == '#') {
                return parseBinaryAttrValue();
            } else if (cur < len && chars[cur] == '"') {
                return parseQuotedAttrValue();
            } else {
                return parseStringAttrValue();
            }
        }
 
Example #25
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: Rdn.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #26
Source Project: cxf   Author: apache   File: DefaultHostnameVerifier.java    License: Apache License 2.0 5 votes vote down vote up
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");
    }
}
 
Example #27
Source Project: hottub   Author: dsrg-uoft   File: Rfc2253Parser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String parseAttrValue() throws InvalidNameException {

            if (cur < len && chars[cur] == '#') {
                return parseBinaryAttrValue();
            } else if (cur < len && chars[cur] == '"') {
                return parseQuotedAttrValue();
            } else {
                return parseStringAttrValue();
            }
        }
 
Example #28
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ResolveResult.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
  * 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);
    }
}
 
Example #29
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: LDAPCertStore.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #30
Source Project: Spark   Author: igniterealtime   File: CertificateModel.java    License: Apache License 2.0 5 votes vote down vote up
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;
}