javax.naming.InvalidNameException Java Examples

The following examples show how to use javax.naming.InvalidNameException. 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 File: Rfc2253Parser.java    From jdk8u-jdk with 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 #2
Source File: ResourceRecord.java    From openjdk-8 with 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 #3
Source File: Rfc2253Parser.java    From jdk1.8-source-analysis with 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 #4
Source File: Rdn.java    From openjdk-jdk8u with 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 #5
Source File: Rfc2253Parser.java    From openjdk-jdk8u with 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 #6
Source File: Rdn.java    From openjdk-8-source with 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 #7
Source File: MutualAuthenticationSettingsPanel.java    From Spark with 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 #8
Source File: Rfc2253Parser.java    From jdk8u-jdk with 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 #9
Source File: Rfc2253Parser.java    From dragonwell8_jdk with 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 File: WARDirContext.java    From Tomcat7.0.67 with 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 #11
Source File: PersonRepositoryIntegrationTests.java    From spring-data-examples with 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 #12
Source File: ResolveResult.java    From jdk8u60 with 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 #13
Source File: Rfc2253Parser.java    From jdk8u60 with 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 #14
Source File: LdapPrincipal.java    From jdk8u_jdk with 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 #15
Source File: Rfc2253Parser.java    From TencentKona-8 with 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 #16
Source File: Rfc2253Parser.java    From dragonwell8_jdk with 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 #17
Source File: ResolveResult.java    From jdk1.8-source-analysis with 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 #18
Source File: SessionFactoryObjectFactory.java    From cacheonix-core with 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 #19
Source File: Rfc2253Parser.java    From jdk8u60 with 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 #20
Source File: LdapPrincipal.java    From openjdk-8 with 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 #21
Source File: DistinguishedName.java    From freehealth-connector with 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 #22
Source File: Rfc2253Parser.java    From TencentKona-8 with 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 File: Rfc2253Parser.java    From openjdk-8 with 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 #24
Source File: LdapName.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void readObject(ObjectInputStream s)
        throws java.io.IOException, ClassNotFoundException {
    s.defaultReadObject();
    unparsed = (String)s.readObject();
    try {
        parse();
    } catch (InvalidNameException e) {
        // shouldn't happen
        throw new java.io.StreamCorruptedException(
                "Invalid name: " + unparsed);
    }
}
 
Example #25
Source File: SSLUtil.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public static boolean checkHostname(String hostname, X509Certificate cert)
{
    try
    {
        return verifyHostname(hostname, getNamesFromCert(cert));
    }
    catch (InvalidNameException | CertificateParsingException e)
    {
        return false;
    }
}
 
Example #26
Source File: ResolveResult.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
      * Constructs a new instance of ResolveResult consisting of
      * the resolved object and the remaining unresolved component.
      *
      * @param robj The non-null object resolved to.
      * @param rcomp The single remaining name component that has yet to be
      *                 resolved. Cannot be null (but can be empty).
      */
    public ResolveResult(Object robj, String rcomp) {
        resolvedObj = robj;
        try {
        remainingName = new CompositeName(rcomp);
//          remainingName.appendComponent(rcomp);
        } catch (InvalidNameException e) {
            // ignore; shouldn't happen
        }
    }
 
Example #27
Source File: DefaultPrincipalExtractor.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
@Override
public String extractPrincipal(final X509Certificate x509Certificate, final Type type) {
    if (x509Certificate == null) {
        return null;
    }

    final SecurityManager sm = System.getSecurityManager();

    if (sm != null) {
        sm.checkPermission(new SpecialPermission());
    }

    String dnString = AccessController.doPrivileged(new PrivilegedAction<String>() {
        @Override
        public String run() {          
            final X500Principal principal = x509Certificate.getSubjectX500Principal();
            return principal.toString();
        }
    });

    //remove whitespaces
    try {
        final LdapName ln = new LdapName(dnString);
        final List<Rdn> rdns = new ArrayList<>(ln.getRdns());
        Collections.reverse(rdns);
        dnString = String.join(",", rdns.stream().map(r->r.toString()).collect(Collectors.toList()));
    } catch (InvalidNameException e) {
        log.error("Unable to parse: {}",dnString, e);
    }
    
    
    if(log.isTraceEnabled()) {
        log.trace("principal: {}", dnString);
    }
    
    return dnString;
}
 
Example #28
Source File: right_LmiInitialContext_1.6.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
public void unbind(String name) throws NamingException {
    if (TraceCarol.isDebugJndiCarol()) {
        TraceCarol.debugJndiCarol("LmiInitialContext.unbind(\"" + name + "\")");
    }
    if (name.equals("")) {
        throw new InvalidNameException("Cannot unbind empty name");
    }
    bindings.remove(name);
}
 
Example #29
Source File: PersonRepositoryIntegrationTests.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Find a {@link Person} by its Id that is a full DN.
 *
 * @throws InvalidNameException
 */
@Test
public void findOneByName() throws InvalidNameException {

	Optional<Person> person = personRepository.findById(new LdapName("uid=bob,ou=people,dc=springframework,dc=org"));

	assertThat(person).hasValueSatisfying(it -> {
		assertThat(it.getFullName()).isEqualTo("Bob Hamilton");
		assertThat(it.getLastname()).isEqualTo("Hamilton");
		assertThat(it.getUid()).isEqualTo("bob");
	});
}
 
Example #30
Source File: TContext.java    From oodt with Apache License 2.0 5 votes vote down vote up
public void rename(String oldName, String newName) throws NamingException {
	if (!bindings.containsKey(oldName))
		throw new NameNotFoundException(oldName);
	if (bindings.containsKey(newName))
		throw new NameAlreadyBoundException(newName);
	if (!newName.startsWith(prefix))
		throw new InvalidNameException("Name doesn't start with " + prefix);
	bindings.put(newName, bindings.remove(oldName));
}