List of usage examples for javax.naming NamingException NamingException
public NamingException(String explanation)
From source file:org.nuxeo.runtime.transaction.TransactionHelper.java
/** * Looks up the TransactionSynchronizationRegistry in JNDI. * * @return the TransactionSynchronizationRegistry * @throws NamingException if not found//from w w w . j a v a 2s . co m */ public static TransactionSynchronizationRegistry lookupSynchronizationRegistry() throws NamingException { TransactionSynchronizationRegistry synch = NuxeoContainer.getTransactionSynchronizationRegistry(); if (synch == null) { throw new NamingException("tx manager not installed"); } return synch; }
From source file:org.olat.core.util.servlets.VFSDirContext.java
/** * Retrieves the named object./*w w w. jav a 2 s . c o m*/ * * @param name the name of the object to look up * @return the object bound to name * @exception NamingException if a naming exception is encountered */ @Override public Object lookup(String name) throws NamingException { VFSItem item = resolveFile(name); if (item == null) throw new NamingException(smgr.getString("resources.notFound", name)); if (item instanceof VFSContainer) { VFSDirContext tempContext = new VFSDirContext(env); tempContext.setVirtualDocBase(item); return tempContext; } else { return new VFSResource(item); } }
From source file:org.olat.core.util.servlets.VFSDirContext.java
/** * Unbinds the named object. Removes the terminal atomic name in name from the target context--that named by all but the terminal atomic part of name. * <p>/*w w w . j a v a2 s . co m*/ * This method is idempotent. It succeeds even if the terminal atomic name is not bound in the target context, but throws NameNotFoundException if any of the * intermediate contexts do not exist. * * @param name the name to bind; may not be empty * @exception NameNotFoundException if an intermediate context does not exist * @exception NamingException if a naming exception is encountered */ @Override public void unbind(String name) throws NamingException { VFSItem file = resolveFile(name); if (file == null) throw new NamingException(smgr.getString("resources.notFound", name)); VFSStatus status = file.delete(); if (status == VFSConstants.NO) throw new NamingException(smgr.getString("resources.unbindFailed", name)); }
From source file:org.olat.core.util.servlets.VFSDirContext.java
/** * Binds a new name to the object bound to an old name, and unbinds the old name. Both names are relative to this context. Any attributes associated with the old name * become associated with the new name. Intermediate contexts of the old name are not changed. * // w ww. j a va2 s . co m * @param oldName the name of the existing binding; may not be empty * @param newName the name of the new binding; may not be empty * @exception NameAlreadyBoundException if newName is already bound * @exception NamingException if a naming exception is encountered */ @Override public void rename(String oldName, String newName) throws NamingException { VFSItem oldFile = resolveFile(oldName); if (oldFile == null) throw new NamingException(smgr.getString("resources.notFound", oldName)); VFSItem newFile = resolveFile(newName); if (newFile != null) throw new NameAlreadyBoundException(); VFSStatus status = oldFile.rename(newName); if (status == VFSConstants.NO) throw new NameAlreadyBoundException(); }
From source file:org.olat.core.util.servlets.VFSDirContext.java
/** * Enumerates the names bound in the named context, along with the class names of objects bound to them. The contents of any subcontexts are not included. * <p>/*from w ww .j av a 2 s . co m*/ * If a binding is added to or removed from this context, its effect on an enumeration previously returned is undefined. * * @param name the name of the context to list * @return an enumeration of the names and class names of the bindings in this context. Each element of the enumeration is of type NameClassPair. * @exception NamingException if a naming exception is encountered */ @Override public NamingEnumeration<NameClassPair> list(String name) throws NamingException { VFSItem file = resolveFile(name); if (file == null) throw new NamingException(smgr.getString("resources.notFound", name)); return new NamingContextEnumeration(list(file).iterator()); }
From source file:org.olat.core.util.servlets.VFSDirContext.java
/** * Retrieves selected attributes associated with a named object. See the class description regarding attribute models, attribute type names, and operational * attributes.//from w w w . j av a 2 s .c o m * * @return the requested attributes; never null * @param name the name of the object from which to retrieve attributes * @param attrIds the identifiers of the attributes to retrieve. null indicates that all attributes should be retrieved; an empty array indicates that none should be * retrieved * @exception NamingException if a naming exception is encountered */ @Override public Attributes getAttributes(String name, String[] attrIds) throws NamingException { // Building attribute list VFSItem file = resolveFile(name); if (file == null) throw new NamingException(smgr.getString("resources.notFound", name)); return new VFSResourceAttributes(file); }
From source file:org.olat.core.util.servlets.VFSDirContext.java
/** * Binds a name to an object, along with associated attributes, overwriting any existing binding. If attrs is null and obj is a DirContext, the attributes from obj * are used. If attrs is null and obj is not a DirContext, any existing attributes associated with the object already bound in the directory remain unchanged. If * attrs is non-null, any existing attributes associated with the object already bound in the directory are removed and attrs is associated with the named object. If * obj is a DirContext and attrs is non-null, the attributes of obj are ignored. * /*from www . j a va 2 s . co m*/ * @param name the name to bind; may not be empty * @param obj the object to bind; possibly null * @param attrs the attributes to associate with the binding * @exception InvalidAttributesException if some "mandatory" attributes of the binding are not supplied * @exception NamingException if a naming exception is encountered */ @Override public void rebind(String name, Object obj, Attributes attrs) throws NamingException { // Note: No custom attributes allowed // Check obj type VFSItem vfsItem = resolveFile(name); if (vfsItem == null || (!(vfsItem instanceof VFSLeaf))) throw new NamingException(smgr.getString("resources.bindFailed", name)); VFSLeaf file = (VFSLeaf) vfsItem; if (file instanceof Versionable && ((Versionable) file).getVersions().isVersioned()) { VersionsManager.getInstance().addToRevisions((Versionable) file, identity, ""); } copyVFS(file, name, obj, attrs); if (file instanceof MetaTagged) { MetaInfo infos = ((MetaTagged) file).getMetaInfo(); if (infos != null && infos.getAuthorIdentity() == null) { infos.setAuthor(userSession.getIdentity().getName()); infos.clearThumbnails(); infos.write(); } } // used by move operations if (obj instanceof VFSResource) { VFSResource vfsResource = (VFSResource) obj; if (vfsResource.vfsItem instanceof Versionable && ((Versionable) vfsResource.vfsItem).getVersions().isVersioned()) { Versionable currentVersion = (Versionable) vfsResource.vfsItem; VersionsManager.getInstance().move(currentVersion, file.getParentContainer()); } } }
From source file:org.olat.core.util.servlets.VFSDirContext.java
private void copyVFS(VFSLeaf file, String name, Object obj, Attributes attrs) throws NamingException { InputStream is = null;// ww w . ja v a2s . co m if (obj instanceof Resource) { try { is = ((Resource) obj).streamContent(); } catch (IOException e) { // ignore, check further } } else if (obj instanceof InputStream) { is = (InputStream) obj; } else if (obj instanceof DirContext) { createSubcontext(name, attrs); return; } if (is == null) throw new NamingException(smgr.getString("resources.bindFailed", name)); // Try to get Quota long quotaLeft = -1; boolean withQuotaCheck = false; VFSContainer parentContainer = file.getParentContainer(); if (parentContainer != null) { quotaLeft = VFSManager.getQuotaLeftKB(parentContainer); if (quotaLeft != Quota.UNLIMITED) { quotaLeft = quotaLeft * 1024; // convert from kB withQuotaCheck = true; } else { withQuotaCheck = false; } } // Open os OutputStream os = null; byte buffer[] = new byte[bufferSize]; int len = -1; try { os = file.getOutputStream(false); while (true) { len = is.read(buffer); if (len == -1) break; if (withQuotaCheck) { // re-calculate quota and check quotaLeft = quotaLeft - len; if (quotaLeft < 0) throw new NamingException("Quota exceeded."); } os.write(buffer, 0, len); } } catch (Exception e) { FileUtils.closeSafely(os); // close first, in order to be able to delete any reamins of the file file.delete(); if (e instanceof NamingException) throw (NamingException) e; throw new NamingException(smgr.getString("resources.bindFailed")); } finally { FileUtils.closeSafely(os); FileUtils.closeSafely(is); } }
From source file:org.openadaptor.auxil.connector.jndi.JNDISearch.java
/** * Execute this search against a DirContext. * <p>// w w w. j ava2 s. c om * The search will be run against each configured searchBase in turn, returning a NamingEnumeration will all of the * matching entries the search yields. * * @param context * a DirContext against which the search is to be executed. * @return NamingEnumeration This will contain all matching entries found. * @throws NamingException * If searchBases does not contain at least one search base, or if the search fails for any reason. */ public NamingEnumeration execute(DirContext context) throws NamingException { if (_searchBases == null || _searchBases.length <= 0) { String error = "Property searchBases may not be <null> and must have at least one value"; log.error(error); throw new NamingException(error); } int searchCount = _searchBases.length; // One search for each searchBase NamingEnumeration[] results = new NamingEnumeration[searchCount]; boolean useAttributes = _attributes != null; String[] origAttributes = searchControls.getReturningAttributes(); if (useAttributes) { searchControls.setReturningAttributes(_attributes); } for (int i = 0; i < searchCount; i++) { String base = _searchBases[i]; log.debug("Executing search against base: " + base + " using filter: " + _filter + " and constraints: " + searchControls + ""); try { results[i] = context.search(base, _filter, searchControls); } catch (NameNotFoundException e) { if (ignoreFailedLookup) { results = new NamingEnumeration[0]; // e.g. we do not care if enrichment lookup failed log.error("Ignoring NameNotFoundException from JNDI lookup", e); break; } else { throw e; } } } if (useAttributes) { // Put the old ones back. searchControls.setReturningAttributes(origAttributes); } return new MultiBaseJNDISearchResults(this, results); }
From source file:org.opentravel.schemacompiler.security.impl.JNDIAuthenticationProvider.java
/** * Uses the context provided to refresh the user information from the directory. * //from ww w.j a va2 s . co m * @param userInfo the user information to be refreshed * @param context the directory context to use for the refresh */ private void refreshUserInfo(UserInfo userInfo, DirContext context) throws NamingException { String userId = (userInfo == null) ? null : userInfo.getUserId(); String userDn; if (userId != null) { System.out.println("REFRESHING USER: " + userId); if (mode == AuthenticationMode.USER_LOOKUP) { userDn = userPattern.format(new String[] { userId }); } else { userDn = findUserDn(userId, context); } if (userDn == null) { throw new NamingException("User account does not exist in the directory: " + userId); } else { // Make sure the account profile fields are populated from the directory String contextDnSuffix = "," + context.getNameInNamespace(); if (userDn.endsWith(contextDnSuffix)) { userDn = userDn.replaceAll(contextDnSuffix, ""); } Attributes userAttrs = context.getAttributes(userDn, new String[] { userLastNameAttribute, userFirstNameAttribute, userEmailAttribute }); userInfo.setLastName(getAttributeValue(userAttrs, userLastNameAttribute)); userInfo.setFirstName(getAttributeValue(userAttrs, userFirstNameAttribute)); userInfo.setEmailAddress(getAttributeValue(userAttrs, userEmailAttribute)); } } }