Search in sources :

Example 56 with InvalidNameException

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

the class TownyDatabaseHandler method renameTown.

@Override
public void renameTown(Town town, 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 (hasTown(filteredName))
            throw new AlreadyRegisteredException("The town " + filteredName + " is already in use.");
        // TODO: Delete/rename any invites.
        List<Resident> toSave = new ArrayList<Resident>(town.getResidents());
        Boolean isCapital = false;
        Nation nation = null;
        Double townBalance = 0.0;
        oldName = town.getName();
        // Clear accounts
        if (TownySettings.isUsingEconomy())
            try {
                townBalance = town.getHoldingBalance();
                town.removeAccount();
            } catch (EconomyException e) {
            }
        // Store the nation in case we have to update the capitol
        if (town.hasNation()) {
            nation = town.getNation();
            isCapital = town.isCapital();
        }
        /*
			 * Tidy up old files.
			 * Has to be done here else the town no longer exists
			 * and the file move command may fail.
			 */
        deleteTown(town);
        /*
			 * Remove the old town from the townsMap
			 * and rename to the new name
			 */
        universe.getTownsMap().remove(town.getName().toLowerCase());
        town.setName(filteredName);
        universe.getTownsMap().put(filteredName.toLowerCase(), town);
        // If this was a nation capitol
        if (isCapital) {
            nation.setCapital(town);
        }
        if (TownySettings.isUsingEconomy()) {
            // TODO
            try {
                town.setBalance(townBalance, "Rename Town - Transfer to new account");
            } catch (EconomyException e) {
                e.printStackTrace();
            }
        }
        for (Resident resident : toSave) {
            saveResident(resident);
        }
        for (TownBlock townBlock : town.getTownBlocks()) {
            // townBlock.setTown(town);
            saveTownBlock(townBlock);
        }
        saveTown(town);
        saveTownList();
        saveWorld(town.getWorld());
        if (nation != null) {
            saveNation(nation);
        }
    } finally {
        lock.unlock();
    }
    BukkitTools.getPluginManager().callEvent(new RenameTownEvent(oldName, town));
    universe.setChangedNotify(RENAME_TOWN);
}
Also used : ArrayList(java.util.ArrayList) InvalidNameException(javax.naming.InvalidNameException) RenameTownEvent(com.palmergames.bukkit.towny.event.RenameTownEvent)

Example 57 with InvalidNameException

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

the class TownyFlatFileSource method saveResidentList.

@Override
public boolean saveResidentList() {
    List<String> list = new ArrayList<String>();
    for (Resident resident : getResidents()) {
        try {
            list.add(NameValidation.checkAndFilterPlayerName(resident.getName()));
        } catch (InvalidNameException e) {
            TownyMessaging.sendErrorMsg("Saving Error: Exception while saving town list file:" + resident.getName());
        }
    }
    /*
		 *  Make sure we only save in async
		 */
    this.queryQueue.add(new FlatFile_Task(list, rootFolder + dataFolder + FileMgmt.fileSeparator() + "residents.txt"));
    return true;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident)

Example 58 with InvalidNameException

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

the class CertUtil method getSubjectAttr.

private String getSubjectAttr(String needAttrName, String needAttrOid) {
    String subjectDN = getSubjectDN();
    try {
        LdapName dn = new LdapName(subjectDN);
        List<Rdn> rdns = dn.getRdns();
        for (Rdn rdn : rdns) {
            String type = rdn.getType();
            boolean isOid = type.contains(".");
            boolean matched = (isOid ? type.equals(needAttrOid) : type.equals(needAttrName));
            if (matched) {
                Object value = rdn.getValue();
                if (value == null) {
                    continue;
                }
                if (isOid) {
                    byte[] bytes = (byte[]) value;
                    ASN1InputStream decoder = null;
                    try {
                        decoder = new ASN1InputStream(bytes);
                        ASN1Encodable encoded = decoder.readObject();
                        DERIA5String str = DERIA5String.getInstance(encoded);
                        return str.getString();
                    } catch (IOException e) {
                        ZimbraLog.account.warn(LOG_PREFIX + "unable to decode " + type, e);
                    } finally {
                        ByteUtil.closeStream(decoder);
                    }
                } else {
                    return value.toString();
                }
            }
        }
    } catch (InvalidNameException e) {
        ZimbraLog.account.warn(LOG_PREFIX + "Invalid subject dn value" + subjectDN, e);
    }
    return null;
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) DERIA5String(org.bouncycastle.asn1.DERIA5String) InvalidNameException(javax.naming.InvalidNameException) ASN1TaggedObject(org.bouncycastle.asn1.ASN1TaggedObject) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) IOException(java.io.IOException) Rdn(javax.naming.ldap.Rdn) LdapName(javax.naming.ldap.LdapName)

Example 59 with InvalidNameException

use of javax.naming.InvalidNameException in project wildfly by wildfly.

the class ExceptionMapper method mapException.

public static NamingException mapException(Exception e, CNCtx ctx, NameComponent[] inputName) throws NamingException {
    if (e instanceof NamingException) {
        return (NamingException) e;
    }
    if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
    }
    NamingException ne;
    if (e instanceof NotFound) {
        if (ctx.federation) {
            return tryFed((NotFound) e, ctx, inputName);
        } else {
            ne = new NameNotFoundException();
        }
    } else if (e instanceof CannotProceed) {
        ne = new CannotProceedException();
        NamingContext nc = ((CannotProceed) e).cxt;
        NameComponent[] rest = ((CannotProceed) e).rest_of_name;
        // NotFound doesn't set rest as expected. -RL
        if (inputName != null && (inputName.length > rest.length)) {
            NameComponent[] resolvedName = new NameComponent[inputName.length - rest.length];
            System.arraycopy(inputName, 0, resolvedName, 0, resolvedName.length);
            // Wrap resolved NamingContext inside a CNCtx
            // Guess that its name (which is relative to ctx)
            // is the part of inputName minus rest_of_name
            ne.setResolvedObj(new CNCtx(ctx._orb, nc, ctx._env, ctx.makeFullName(resolvedName)));
        } else {
            ne.setResolvedObj(ctx);
        }
        ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
    } else if (e instanceof InvalidName) {
        ne = new InvalidNameException();
    } else if (e instanceof AlreadyBound) {
        ne = new NameAlreadyBoundException();
    } else if (e instanceof NotEmpty) {
        ne = new ContextNotEmptyException();
    } else {
        ne = new NamingException();
    }
    ne.setRootCause(e);
    return ne;
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) CannotProceed(org.omg.CosNaming.NamingContextPackage.CannotProceed) NamingContext(org.omg.CosNaming.NamingContext) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) InvalidName(org.omg.CosNaming.NamingContextPackage.InvalidName) InvalidNameException(javax.naming.InvalidNameException) CannotProceedException(javax.naming.CannotProceedException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) NamingException(javax.naming.NamingException) AlreadyBound(org.omg.CosNaming.NamingContextPackage.AlreadyBound) NotEmpty(org.omg.CosNaming.NamingContextPackage.NotEmpty) NotFound(org.omg.CosNaming.NamingContextPackage.NotFound)

Example 60 with InvalidNameException

use of javax.naming.InvalidNameException in project wildfly by wildfly.

the class ServiceBasedNamingStore method suffix.

private Name suffix(ServiceName parent, ServiceName child) {
    String[] p = parent.toArray();
    String[] c = child.toArray();
    CompositeName name = new CompositeName();
    for (int i = p.length; i < c.length; i++) {
        try {
            name.add(c[i]);
        } catch (InvalidNameException e) {
            throw new IllegalStateException(e);
        }
    }
    return name;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName)

Aggregations

InvalidNameException (javax.naming.InvalidNameException)68 LdapName (javax.naming.ldap.LdapName)30 Rdn (javax.naming.ldap.Rdn)24 CompositeName (javax.naming.CompositeName)12 NamingException (javax.naming.NamingException)11 ArrayList (java.util.ArrayList)9 Name (javax.naming.Name)8 NameNotFoundException (javax.naming.NameNotFoundException)8 Context (javax.naming.Context)7 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)6 NotContextException (javax.naming.NotContextException)6 Attribute (javax.naming.directory.Attribute)6 X509Certificate (java.security.cert.X509Certificate)5 NoSuchElementException (java.util.NoSuchElementException)5 OperationNotSupportedException (javax.naming.OperationNotSupportedException)5 Attributes (javax.naming.directory.Attributes)5 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 SSLException (javax.net.ssl.SSLException)4 HashMap (java.util.HashMap)3