Search in sources :

Example 6 with InvalidNameException

use of javax.naming.InvalidNameException in project midpoint by Evolveum.

the class BasicExpressionFunctions method composeDnWithSuffix.

/**
     * Creates a valid LDAP distinguished name from the wide range of components assuming that
     * the last component is a suffix. The method can be invoked in many ways, e.g.:
     * 
     * composeDn("cn","foo","o=bar")
     * composeDn(new Rdn("cn","foo"),"ou=baz,o=bar")
	 * composeDn(new Rdn("cn","foo"),new LdapName("ou=baz,o=bar"))
     * composeDn("cn","foo",new LdapName("ou=baz,o=bar"))
     * 
     * The last element is a complete suffix represented either as String or LdapName.
     * 
     * Note: the DN is not normalized. The case of the attribute names and white spaces are
     * preserved.
     */
public static String composeDnWithSuffix(Object... components) throws InvalidNameException {
    if (components == null) {
        return null;
    }
    if (components.length == 0) {
        return null;
    }
    if (components.length == 1) {
        if (components[0] == null) {
            return null;
        }
        if ((components[0] instanceof String)) {
            if (StringUtils.isBlank((String) (components[0]))) {
                return null;
            } else {
                return (new LdapName((String) (components[0]))).toString();
            }
        } else if ((components[0] instanceof LdapName)) {
            return ((LdapName) (components[0])).toString();
        } else {
            throw new InvalidNameException("Invalid input to composeDn() function: expected suffix (last element) to be String or LdapName, but it was " + components[0].getClass());
        }
    }
    Object suffix = components[components.length - 1];
    if (suffix instanceof String) {
        suffix = new LdapName((String) suffix);
    }
    if (!(suffix instanceof LdapName)) {
        throw new InvalidNameException("Invalid input to composeDn() function: expected suffix (last element) to be String or LdapName, but it was " + suffix.getClass());
    }
    components[components.length - 1] = suffix;
    return composeDn(components);
}
Also used : InvalidNameException(javax.naming.InvalidNameException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) LdapName(javax.naming.ldap.LdapName)

Example 7 with InvalidNameException

use of javax.naming.InvalidNameException in project Towny by ElgarL.

the class TownyDatabaseHandler method renameNation.

@Override
public void renameNation(Nation nation, String newName) throws AlreadyRegisteredException, NotRegisteredException {
    lock.lock();
    String oldName;
    try {
        String filteredName;
        try {
            filteredName = NameValidation.checkAndFilterName(newName);
        } catch (InvalidNameException e) {
            throw new NotRegisteredException(e.getMessage());
        }
        if (hasNation(filteredName))
            throw new AlreadyRegisteredException("The nation " + filteredName + " is already in use.");
        // TODO: Delete/rename any invites.
        List<Town> toSave = new ArrayList<Town>(nation.getTowns());
        Double nationBalance = 0.0;
        // Clear accounts
        if (TownySettings.isUsingEconomy())
            try {
                nationBalance = nation.getHoldingBalance();
                nation.removeAccount();
            } catch (EconomyException e) {
            }
        //Tidy up old files
        deleteNation(nation);
        /*
			 * Remove the old nation from the nationsMap
			 * and rename to the new name
			 */
        oldName = nation.getName();
        universe.getNationsMap().remove(oldName.toLowerCase());
        nation.setName(filteredName);
        universe.getNationsMap().put(filteredName.toLowerCase(), nation);
        if (TownyEconomyHandler.isActive()) {
            //TODO
            try {
                nation.setBalance(nationBalance, "Rename Nation - Transfer to new account");
            } catch (EconomyException e) {
                e.printStackTrace();
            }
        }
        for (Town town : toSave) {
            saveTown(town);
        }
        saveNation(nation);
        saveNationList();
        //search and update all ally/enemy lists
        Nation oldNation = new Nation(oldName);
        List<Nation> toSaveNation = new ArrayList<Nation>(getNations());
        for (Nation toCheck : toSaveNation) if (toCheck.hasAlly(oldNation) || toCheck.hasEnemy(oldNation)) {
            try {
                if (toCheck.hasAlly(oldNation)) {
                    toCheck.removeAlly(oldNation);
                    toCheck.addAlly(nation);
                } else {
                    toCheck.removeEnemy(oldNation);
                    toCheck.addEnemy(nation);
                }
            } catch (NotRegisteredException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else
            toSave.remove(toCheck);
        for (Nation toCheck : toSaveNation) saveNation(toCheck);
    } finally {
        lock.unlock();
    }
    BukkitTools.getPluginManager().callEvent(new RenameNationEvent(oldName, nation));
    universe.setChangedNotify(RENAME_NATION);
}
Also used : InvalidNameException(javax.naming.InvalidNameException) RenameNationEvent(com.palmergames.bukkit.towny.event.RenameNationEvent) ArrayList(java.util.ArrayList)

Example 8 with InvalidNameException

use of javax.naming.InvalidNameException in project zm-mailbox by Zimbra.

the class ClientCertAuthenticator method getAccountByX509SubjectDN.

// Still called from nginx lookup servlet, TODO: retire
public static Account getAccountByX509SubjectDN(String x509SubjectDN) throws ServiceException {
    try {
        LdapName dn = new LdapName(x509SubjectDN);
        List<Rdn> rdns = dn.getRdns();
        for (Rdn rdn : rdns) {
            String type = rdn.getType();
            // recognize only email address for now
            if ("EMAILADDRESS".equals(type)) {
                Object value = rdn.getValue();
                if (value != null) {
                    String email = value.toString();
                    Account acct = Provisioning.getInstance().get(AccountBy.name, email);
                    if (acct != null) {
                        return acct;
                    } else {
                        ZimbraLog.account.debug(LOG_PREFIX + "account not found: " + email);
                    }
                }
            }
        }
    } catch (InvalidNameException e) {
        throw AuthFailedServiceException.AUTH_FAILED("ClientCertAuthenticator - invalid X509 subject: " + x509SubjectDN, e);
    }
    return null;
}
Also used : Account(com.zimbra.cs.account.Account) InvalidNameException(javax.naming.InvalidNameException) Rdn(javax.naming.ldap.Rdn) LdapName(javax.naming.ldap.LdapName)

Example 9 with InvalidNameException

use of javax.naming.InvalidNameException in project geode by apache.

the class ContextImpl method destroySubcontext.

/**
   * Destroys subcontext with name name. The subcontext must be empty otherwise
   * ContextNotEmptyException is thrown. Once a context is destroyed, the instance should not be
   * used.
   * 
   * @param name subcontext to destroy
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
   *         naming system.
   * @throws ContextNotEmptyException if Context name is not empty.
   * @throws NameNotFoundException if subcontext with name name can not be found.
   * @throws NotContextException if name is not bound to instance of ContextImpl.
   * 
   */
public void destroySubcontext(Name name) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
        throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
    }
    String subContextName = parsedName.get(0);
    Object boundObject = ctxMaps.get(subContextName);
    if (boundObject == null) {
        throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND_IN_THE_CONTEXT.toLocalizedString(subContextName));
    }
    if (!(boundObject instanceof ContextImpl)) {
        throw new NotContextException();
    }
    ContextImpl contextToDestroy = (ContextImpl) boundObject;
    if (parsedName.size() == 1) {
        // non-empty Context.
        if (contextToDestroy.ctxMaps.size() == 0) {
            ctxMaps.remove(subContextName);
            contextToDestroy.destroyInternal();
        } else {
            throw new ContextNotEmptyException(LocalizedStrings.ContextImpl_CAN_NOT_DESTROY_NONEMPTY_CONTEXT.toLocalizedString());
        }
    } else {
        // Let the subcontext destroy the context
        ((ContextImpl) boundObject).destroySubcontext(parsedName.getSuffix(1));
    }
}
Also used : NotContextException(javax.naming.NotContextException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 10 with InvalidNameException

use of javax.naming.InvalidNameException in project geode by apache.

the class ContextImpl method unbind.

/**
   * Removes name and its associated object from the context.
   * 
   * @param name name to remove
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
   *         naming system
   * @throws NameNotFoundException if intermediate context can not be found
   * @throws NotContextException if name has more than one atomic name and intermediate context is
   *         not found.
   * @throws NamingException if any other naming exception occurs
   * 
   */
public void unbind(Name name) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
        throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
    }
    String nameToRemove = parsedName.get(0);
    // remove a and its associated object
    if (parsedName.size() == 1) {
        ctxMaps.remove(nameToRemove);
    } else {
        // scenerio unbind a/b or a/b/c
        // remove b and its associated object
        Object boundObject = ctxMaps.get(nameToRemove);
        if (boundObject instanceof Context) {
            // remove b and its associated object
            ((Context) boundObject).unbind(parsedName.getSuffix(1));
        } else {
            // if the name is not found then throw exception
            if (!ctxMaps.containsKey(nameToRemove)) {
                throw new NameNotFoundException(LocalizedStrings.ContextImpl_CAN_NOT_FIND_0.toLocalizedString(name));
            }
            throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
        }
    }
}
Also used : Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Aggregations

InvalidNameException (javax.naming.InvalidNameException)27 CompositeName (javax.naming.CompositeName)10 LdapName (javax.naming.ldap.LdapName)8 Name (javax.naming.Name)6 NameNotFoundException (javax.naming.NameNotFoundException)5 Rdn (javax.naming.ldap.Rdn)5 ArrayList (java.util.ArrayList)4 NotContextException (javax.naming.NotContextException)4 URISyntaxException (java.net.URISyntaxException)3 Context (javax.naming.Context)3 NamingException (javax.naming.NamingException)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ConnectException (java.net.ConnectException)2 RemoteException (java.rmi.RemoteException)2 LinkedList (java.util.LinkedList)2 AuthenticationException (javax.naming.AuthenticationException)2 ConfigurationException (javax.naming.ConfigurationException)2 ContextNotEmptyException (javax.naming.ContextNotEmptyException)2 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)2