org.springframework.beans.factory.BeanNotOfRequiredTypeException#javax.naming.NameNotFoundException源码实例Demo

下面列出了org.springframework.beans.factory.BeanNotOfRequiredTypeException#javax.naming.NameNotFoundException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: activemq-artemis   文件: InVMNamingContext.java
@Override
public void unbind(String name) throws NamingException {
   name = trimSlashes(name);
   int i = name.indexOf("/");
   boolean terminal = i == -1;
   if (terminal) {
      map.remove(name);
   } else {
      String tok = name.substring(0, i);
      InVMNamingContext c = (InVMNamingContext) map.get(tok);
      if (c == null) {
         throw new NameNotFoundException("Context not found: " + tok);
      }
      c.unbind(name.substring(i));
   }
}
 
源代码2 项目: spring-analysis-note   文件: JndiTemplateTests.java
@Test
public void testLookupFails() throws Exception {
	NameNotFoundException ne = new NameNotFoundException();
	String name = "foo";
	final Context context = mock(Context.class);
	given(context.lookup(name)).willThrow(ne);

	JndiTemplate jt = new JndiTemplate() {
		@Override
		protected Context createInitialContext() {
			return context;
		}
	};

	try {
		jt.lookup(name);
		fail("Should have thrown NamingException");
	}
	catch (NameNotFoundException ex) {
		// Ok
	}
	verify(context).close();
}
 
/**
 * Look up the object with the given name.
 * <p>Note: Not intended for direct use by applications.
 * Will be used by any standard InitialContext JNDI lookups.
 * @throws javax.naming.NameNotFoundException if the object could not be found
 */
@Override
public Object lookup(String lookupName) throws NameNotFoundException {
	String name = this.root + lookupName;
	if (logger.isDebugEnabled()) {
		logger.debug("Static JNDI lookup: [" + name + "]");
	}
	if ("".equals(name)) {
		return new SimpleNamingContext(this.root, this.boundObjects, this.environment);
	}
	Object found = this.boundObjects.get(name);
	if (found == null) {
		if (!name.endsWith("/")) {
			name = name + "/";
		}
		for (String boundName : this.boundObjects.keySet()) {
			if (boundName.startsWith(name)) {
				return new SimpleNamingContext(name, this.boundObjects, this.environment);
			}
		}
		throw new NameNotFoundException(
				"Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" +
				StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]");
	}
	return found;
}
 
源代码4 项目: activemq-artemis   文件: InVMContext.java
@Override
public void unbind(String name) throws NamingException {
   name = trimSlashes(name);
   int i = name.indexOf("/");
   boolean terminal = i == -1;
   if (terminal) {
      map.remove(name);
   } else {
      String tok = name.substring(0, i);
      InVMContext c = (InVMContext) map.get(tok);
      if (c == null) {
         throw new NameNotFoundException("Context not found: " + tok);
      }
      c.unbind(name.substring(i));
   }
}
 
源代码5 项目: pentaho-kettle   文件: LDAPConnection.java
public int add( String dn, String[] attributes, String[] values, String multValuedSeparator, boolean checkEntry ) throws KettleException {
  try {
    Attributes attrs = buildAttributes( dn, attributes, values, multValuedSeparator );
    // We had all attributes
    getInitialContext().modifyAttributes( dn, DirContext.ADD_ATTRIBUTE, attrs );
    return STATUS_ADDED;
  } catch ( NameNotFoundException n ) {
    // The entry is not found
    if ( checkEntry ) {
      throw new KettleException(
        BaseMessages.getString( PKG, "LDAPConnection.Error.Deleting.NameNotFound", dn ), n );
    }
    return STATUS_SKIPPED;
  } catch ( Exception e ) {
    throw new KettleException( BaseMessages.getString( PKG, "LDAPConnection.Error.Add", dn ), e );
  }
}
 
源代码6 项目: hop   文件: LdapConnection.java
public int delete( String dn, boolean checkEntry ) throws HopException {
  try {

    if ( checkEntry ) {
      // First Check entry
      getInitialContext().lookup( dn );
    }
    // The entry exists
    getInitialContext().destroySubcontext( dn );
    if ( log.isDebug() ) {
      log.logDebug( BaseMessages.getString( PKG, "LDAPinput.Exception.Deleted", dn ) );
    }
    return STATUS_DELETED;
  } catch ( NameNotFoundException n ) {
    // The entry is not found
    if ( checkEntry ) {
      throw new HopException(
        BaseMessages.getString( PKG, "LdapConnection.Error.Deleting.NameNotFound", dn ), n );
    }
    return STATUS_SKIPPED;
  } catch ( Exception e ) {
    throw new HopException( BaseMessages.getString( PKG, "LdapConnection.Error.Delete", dn ), e );
  }
}
 
源代码7 项目: java-technology-stack   文件: JndiTemplateTests.java
@Test
public void testLookupFails() throws Exception {
	NameNotFoundException ne = new NameNotFoundException();
	String name = "foo";
	final Context context = mock(Context.class);
	given(context.lookup(name)).willThrow(ne);

	JndiTemplate jt = new JndiTemplate() {
		@Override
		protected Context createInitialContext() {
			return context;
		}
	};

	try {
		jt.lookup(name);
		fail("Should have thrown NamingException");
	}
	catch (NameNotFoundException ex) {
		// Ok
	}
	verify(context).close();
}
 
源代码8 项目: tomcatsrc   文件: NamingContext.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>
 * 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(Name name)
    throws NamingException {
    // Removing empty parts
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty()) {
        return new NamingContextEnumeration(bindings.values().iterator());
    }
    
    NamingEntry entry = bindings.get(name.get(0));
    
    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }
    
    if (entry.type != NamingEntry.CONTEXT) {
        throw new NamingException
            (sm.getString("namingContext.contextExpected"));
    }
    return ((Context) entry.value).list(name.getSuffix(1));
}
 
/**
 * Look up the object with the given name.
 * <p>Note: Not intended for direct use by applications.
 * Will be used by any standard InitialContext JNDI lookups.
 * @throws javax.naming.NameNotFoundException if the object could not be found
 */
@Override
public Object lookup(String lookupName) throws NameNotFoundException {
	String name = this.root + lookupName;
	if (logger.isDebugEnabled()) {
		logger.debug("Static JNDI lookup: [" + name + "]");
	}
	if ("".equals(name)) {
		return new SimpleNamingContext(this.root, this.boundObjects, this.environment);
	}
	Object found = this.boundObjects.get(name);
	if (found == null) {
		if (!name.endsWith("/")) {
			name = name + "/";
		}
		for (String boundName : this.boundObjects.keySet()) {
			if (boundName.startsWith(name)) {
				return new SimpleNamingContext(name, this.boundObjects, this.environment);
			}
		}
		throw new NameNotFoundException(
				"Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" +
				StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]");
	}
	return found;
}
 
源代码10 项目: tomcatsrc   文件: NamingContext.java
/**
 * Enumerates the names bound in the named context, along with the 
 * objects bound to them. The contents of any subcontexts are not 
 * included.
 * <p>
 * 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 bindings in this context. 
 * Each element of the enumeration is of type Binding.
 * @exception NamingException if a naming exception is encountered
 */
@Override
public NamingEnumeration<Binding> listBindings(Name name)
    throws NamingException {
    // Removing empty parts
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty()) {
        return new NamingContextBindingsEnumeration(bindings.values().iterator(), this);
    }
    
    NamingEntry entry = bindings.get(name.get(0));
    
    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }
    
    if (entry.type != NamingEntry.CONTEXT) {
        throw new NamingException
            (sm.getString("namingContext.contextExpected"));
    }
    return ((Context) entry.value).listBindings(name.getSuffix(1));
}
 
/**
 * Look up the object with the given name.
 * <p>Note: Not intended for direct use by applications.
 * Will be used by any standard InitialContext JNDI lookups.
 * @throws javax.naming.NameNotFoundException if the object could not be found
 */
@Override
public Object lookup(String lookupName) throws NameNotFoundException {
	String name = this.root + lookupName;
	if (logger.isDebugEnabled()) {
		logger.debug("Static JNDI lookup: [" + name + "]");
	}
	if ("".equals(name)) {
		return new SimpleNamingContext(this.root, this.boundObjects, this.environment);
	}
	Object found = this.boundObjects.get(name);
	if (found == null) {
		if (!name.endsWith("/")) {
			name = name + "/";
		}
		for (String boundName : this.boundObjects.keySet()) {
			if (boundName.startsWith(name)) {
				return new SimpleNamingContext(name, this.boundObjects, this.environment);
			}
		}
		throw new NameNotFoundException(
				"Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" +
				StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]");
	}
	return found;
}
 
源代码12 项目: tomcatsrc   文件: FileDirContext.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>
 * 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 {

    File file = file(name);

    if (file == null)
        throw new NameNotFoundException(
                sm.getString("resources.notFound", name));

    if (!file.delete())
        throw new NamingException
            (sm.getString("resources.unbindFailed", name));

}
 
源代码13 项目: piranha   文件: DefaultInitialContext.java
/**
 * Bind the object to the given name.
 *
 * @param name the name.
 * @param object the object.
 * @throws NamingException when an naming error occurs.
 */
@Override
public void bind(String name, Object object) throws NamingException {
    checkClosed();
    if (name.contains("/")) {
        String[] names = name.split("/");
        DefaultInitialContext contextMap = this;
        for (int i = 0; i < names.length - 1; i++) {
            try {
                contextMap = (DefaultInitialContext) contextMap.lookup(names[i]);
            } catch (NameNotFoundException ne) {
                contextMap = (DefaultInitialContext) contextMap.createSubcontext(names[i]);
            }
        }
        contextMap.bind(names[names.length - 1], object);
    } else if (!bindings.containsKey(name)) {
        bindings.put(name, object);
    } else {
        throw new NameAlreadyBoundException("Name '" + name + "' already bound");
    }
}
 
源代码14 项目: gemfirexd-oss   文件: ContextImpl.java
/**
 * 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);
  // scenerio unbind a
  // 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));
    }
  }
}
 
源代码15 项目: activemq-artemis   文件: InVMNamingContext.java
@Override
public Object lookup(String name) throws NamingException {
   name = trimSlashes(name);
   int i = name.indexOf("/");
   String tok = i == -1 ? name : name.substring(0, i);
   Object value = map.get(tok);
   if (value == null) {
      throw new NameNotFoundException("Name not found: " + tok);
   }
   if (value instanceof InVMNamingContext && i != -1) {
      return ((InVMNamingContext) value).lookup(name.substring(i));
   }
   if (value instanceof Reference) {
      Reference ref = (Reference) value;
      RefAddr refAddr = ref.get("nns");

      // we only deal with references create by NonSerializableFactory
      String key = (String) refAddr.getContent();
      return NonSerializableFactory.lookup(key);
   } else {
      return value;
   }
}
 
源代码16 项目: Tomcat7.0.67   文件: FileDirContext.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.
 *
 * @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 {

    File file = file(oldName);

    if (file == null)
        throw new NameNotFoundException
            (sm.getString("resources.notFound", oldName));

    File newFile = new File(base, newName);

    if (!file.renameTo(newFile)) {
        throw new NamingException(sm.getString("resources.renameFail",
                oldName, newName));
    }

}
 
源代码17 项目: spring-ldap   文件: DirContextAdapter.java
/**
    * {@inheritDoc}
    */
   @Override
public Attributes getAttributes(String name, String[] attrIds)
		throws NamingException {
	if (StringUtils.hasLength(name)) {
		throw new NameNotFoundException();
	}

	Attributes a = new NameAwareAttributes();
	Attribute target;
       for (String attrId : attrIds) {
           target = originalAttrs.get(attrId);
           if (target != null) {
               a.put(target);
           }
       }

	return a;
}
 
源代码18 项目: tomee   文件: LookupFactory.java
@Override
public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception {
    if (!(object instanceof Reference)) {
        return null;
    }

    final Reference reference = ((Reference) object);

    final String jndiName = NamingUtil.getProperty(reference, NamingUtil.JNDI_NAME);

    if (jndiName == null) {
        return null;
    }

    try {
        return context.lookup(jndiName.replaceFirst("^java:", ""));
    } catch (final NameNotFoundException e) {
        return new InitialContext().lookup(jndiName);
    }
}
 
源代码19 项目: pentaho-kettle   文件: LDAPConnection.java
public int delete( String dn, boolean checkEntry ) throws KettleException {
  try {

    if ( checkEntry ) {
      // First Check entry
      getInitialContext().lookup( dn );
    }
    // The entry exists
    getInitialContext().destroySubcontext( dn );
    if ( log.isDebug() ) {
      log.logDebug( BaseMessages.getString( PKG, "LDAPinput.Exception.Deleted", dn ) );
    }
    return STATUS_DELETED;
  } catch ( NameNotFoundException n ) {
    // The entry is not found
    if ( checkEntry ) {
      throw new KettleException(
        BaseMessages.getString( PKG, "LDAPConnection.Error.Deleting.NameNotFound", dn ), n );
    }
    return STATUS_SKIPPED;
  } catch ( Exception e ) {
    throw new KettleException( BaseMessages.getString( PKG, "LDAPConnection.Error.Delete", dn ), e );
  }
}
 
源代码20 项目: Tomcat7.0.67   文件: NamingContext.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>
 * 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(Name name)
    throws NamingException {
    // Removing empty parts
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty()) {
        return new NamingContextEnumeration(bindings.values().iterator());
    }
    
    NamingEntry entry = bindings.get(name.get(0));
    
    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }
    
    if (entry.type != NamingEntry.CONTEXT) {
        throw new NamingException
            (sm.getString("namingContext.contextExpected"));
    }
    return ((Context) entry.value).list(name.getSuffix(1));
}
 
源代码21 项目: gemfirexd-oss   文件: ContextImpl.java
/**
 * 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);
  // scenerio unbind a
  // 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));
    }
  }
}
 
源代码22 项目: hadoop   文件: TestDNS.java
/**
 * TestCase: get our local address and reverse look it up
 */
@Test
public void testRDNS() throws Exception {
  InetAddress localhost = getLocalIPAddr();
  try {
    String s = DNS.reverseDns(localhost, null);
    LOG.info("Local revers DNS hostname is " + s);
  } catch (NameNotFoundException e) {
    if (!localhost.isLinkLocalAddress() || localhost.isLoopbackAddress()) {
      //these addresses probably won't work with rDNS anyway, unless someone
      //has unusual entries in their DNS server mapping 1.0.0.127 to localhost
      LOG.info("Reverse DNS failing as due to incomplete networking", e);
      LOG.info("Address is " + localhost
              + " Loopback=" + localhost.isLoopbackAddress()
              + " Linklocal=" + localhost.isLinkLocalAddress());
    }

  }
}
 
源代码23 项目: spring4-understanding   文件: JndiTemplateTests.java
@Test
public void testLookupFails() throws Exception {
	NameNotFoundException ne = new NameNotFoundException();
	String name = "foo";
	final Context context = mock(Context.class);
	given(context.lookup(name)).willThrow(ne);

	JndiTemplate jt = new JndiTemplate() {
		@Override
		protected Context createInitialContext() {
			return context;
		}
	};

	try {
		jt.lookup(name);
		fail("Should have thrown NamingException");
	}
	catch (NameNotFoundException ex) {
		// Ok
	}
	verify(context).close();
}
 
/**
 * Look up the object with the given name.
 * <p>Note: Not intended for direct use by applications.
 * Will be used by any standard InitialContext JNDI lookups.
 * @throws javax.naming.NameNotFoundException if the object could not be found
 */
@Override
public Object lookup(String lookupName) throws NameNotFoundException {
	String name = this.root + lookupName;
	if (logger.isDebugEnabled()) {
		logger.debug("Static JNDI lookup: [" + name + "]");
	}
	if ("".equals(name)) {
		return new SimpleNamingContext(this.root, this.boundObjects, this.environment);
	}
	Object found = this.boundObjects.get(name);
	if (found == null) {
		if (!name.endsWith("/")) {
			name = name + "/";
		}
		for (String boundName : this.boundObjects.keySet()) {
			if (boundName.startsWith(name)) {
				return new SimpleNamingContext(name, this.boundObjects, this.environment);
			}
		}
		throw new NameNotFoundException(
				"Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" +
				StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]");
	}
	return found;
}
 
源代码25 项目: activemq-artemis   文件: InVMContext.java
@Override
public Object lookup(String name) throws NamingException {
   name = trimSlashes(name);
   int i = name.indexOf("/");
   String tok = i == -1 ? name : name.substring(0, i);
   Object value = map.get(tok);
   if (value == null) {
      throw new NameNotFoundException("Name not found: " + tok);
   }
   if (value instanceof InVMContext && i != -1) {
      return ((InVMContext) value).lookup(name.substring(i));
   }
   if (value instanceof Reference) {
      Reference ref = (Reference) value;
      RefAddr refAddr = ref.get("nns");

      // we only deal with references create by NonSerializableFactory
      String key = (String) refAddr.getContent();
      return NonSerializableFactory.lookup(key);
   } else {
      return value;
   }
}
 
源代码26 项目: Tomcat8-Source-Read   文件: JNDIRealm.java
/**
 * Use the distinguished name to locate the directory
 * entry for the user with the specified username and
 * return a User object; otherwise return <code>null</code>.
 *
 * @param context The directory context
 * @param username The username
 * @param attrIds String[]containing names of attributes to
 * @param dn Distinguished name of the user
 * retrieve.
 * @return the User object
 * @exception NamingException if a directory server error occurs
 */
protected User getUserByPattern(DirContext context,
                                String username,
                                String[] attrIds,
                                String dn)
    throws NamingException {

    // If no attributes are requested, no need to look for them
    if (attrIds == null || attrIds.length == 0) {
        return new User(username, dn, null, null,null);
    }

    // Get required attributes from user entry
    Attributes attrs = null;
    try {
        attrs = context.getAttributes(dn, attrIds);
    } catch (NameNotFoundException e) {
        return null;
    }
    if (attrs == null)
        return null;

    // Retrieve value of userPassword
    String password = null;
    if (userPassword != null)
        password = getAttributeValue(userPassword, attrs);

    String userRoleAttrValue = null;
    if (userRoleAttribute != null) {
        userRoleAttrValue = getAttributeValue(userRoleAttribute, attrs);
    }

    // Retrieve values of userRoleName attribute
    ArrayList<String> roles = null;
    if (userRoleName != null)
        roles = addAttributeValues(userRoleName, attrs, roles);

    return new User(username, dn, password, roles, userRoleAttrValue);
}
 
源代码27 项目: Tomcat8-Source-Read   文件: NamingContext.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>
 * 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(Name name) throws NamingException {

    if (!checkWritable()) {
        return;
    }

    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));

    NamingEntry entry = bindings.get(name.get(0));

    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }

    if (name.size() > 1) {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).unbind(name.getSuffix(1));
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        bindings.remove(name.get(0));
    }

}
 
源代码28 项目: jdk8u-jdk   文件: LDAPCertStore.java
/**
 * Get a map containing the values for this request. The first time
 * this method is called on an object, the LDAP request is sent,
 * the results parsed and added to a private map and also to the
 * cache of this LDAPCertStore. Subsequent calls return the private
 * map immediately.
 *
 * The map contains an entry for each requested attribute. The
 * attribute name is the key, values are byte[][]. If there are no
 * values for that attribute, values are byte[0][].
 *
 * @return                      the value Map
 * @throws NamingException      if a naming exception occurs
 */
private Map<String, byte[][]> getValueMap() throws NamingException {
    if (valueMap != null) {
        return valueMap;
    }
    if (DEBUG) {
        System.out.println("Request: " + name + ":" + requestedAttributes);
        requests++;
        if (requests % 5 == 0) {
            System.out.println("LDAP requests: " + requests);
        }
    }
    valueMap = new HashMap<>(8);
    String[] attrIds = requestedAttributes.toArray(STRING0);
    Attributes attrs;
    try {
        attrs = ctx.getAttributes(name, attrIds);
    } catch (NameNotFoundException e) {
        // name does not exist on this LDAP server
        // treat same as not attributes found
        attrs = EMPTY_ATTRIBUTES;
    }
    for (String attrId : requestedAttributes) {
        Attribute attr = attrs.get(attrId);
        byte[][] values = getAttributeValues(attr);
        cacheAttribute(attrId, values);
        valueMap.put(attrId, values);
    }
    return valueMap;
}
 
源代码29 项目: spring-analysis-note   文件: JndiTemplate.java
/**
 * Look up the object with the given name in the current JNDI context.
 * @param name the JNDI name of the object
 * @return object found (cannot be {@code null}; if a not so well-behaved
 * JNDI implementations returns null, a NamingException gets thrown)
 * @throws NamingException if there is no object with the given
 * name bound to JNDI
 */
public Object lookup(final String name) throws NamingException {
	if (logger.isDebugEnabled()) {
		logger.debug("Looking up JNDI object with name [" + name + "]");
	}
	Object result = execute(ctx -> ctx.lookup(name));
	if (result == null) {
		throw new NameNotFoundException(
				"JNDI object with [" + name + "] not found: JNDI implementation returned null");
	}
	return result;
}
 
public void rename(String oldName, String newName) throws NamingException {
    if (TraceCarol.isDebugJndiCarol()) {
        TraceCarol.debugJndiCarol("LmiInitialContext.rename(\"" + oldName + "\",\"" + newName + "\")");
    }
    if (oldName.equals("") || newName.equals("")) throw new InvalidNameException("Cannot rename empty name");
    if (bindings.get(newName) != null) throw new NameAlreadyBoundException(newName + " is already bound");

    Object oldb = bindings.remove(oldName);
    if (oldb == null) throw new NameNotFoundException(oldName + " not bound");
    bindings.put(newName, oldb);
}