当前位置: 首页>>代码示例>>Java>>正文


Java DirContext.addToEnvironment方法代码示例

本文整理汇总了Java中javax.naming.directory.DirContext.addToEnvironment方法的典型用法代码示例。如果您正苦于以下问题:Java DirContext.addToEnvironment方法的具体用法?Java DirContext.addToEnvironment怎么用?Java DirContext.addToEnvironment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.naming.directory.DirContext的用法示例。


在下文中一共展示了DirContext.addToEnvironment方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: userCredentialsRemove

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
/**
 * Configure the context to use {@link #connectionName} and
 * {@link #connectionPassword} if specified or an anonymous connection if
 * those attributes are not specified.
 * 
  * @param context      DirContext to configure
 */
private void userCredentialsRemove(DirContext context)
        throws NamingException {
    // Restore the original security environment
    if (connectionName != null) {
        context.addToEnvironment(Context.SECURITY_PRINCIPAL,
                                 connectionName);
    } else {
        context.removeFromEnvironment(Context.SECURITY_PRINCIPAL);
    }

    if (connectionPassword != null) {
        context.addToEnvironment(Context.SECURITY_CREDENTIALS,
                                 connectionPassword);
    }
    else {
        context.removeFromEnvironment(Context.SECURITY_CREDENTIALS);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:26,代码来源:JNDIRealm.java

示例2: restoreEnvironmentParameter

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
private void restoreEnvironmentParameter(DirContext context, String parameterName,
		Hashtable<?, ?> preservedEnvironment) {
	try {
		context.removeFromEnvironment(parameterName);
		if (preservedEnvironment != null && preservedEnvironment.containsKey(parameterName)) {
			context.addToEnvironment(parameterName, preservedEnvironment.get(parameterName));
		}
	} catch (NamingException e) {
		// Ignore
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:12,代码来源:JNDIRealm.java

示例3: restoreEnvironmentParameter

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
private void restoreEnvironmentParameter(DirContext context,
        String parameterName, Hashtable<?, ?> preservedEnvironment) {
    try {
        context.removeFromEnvironment(parameterName);
        if (preservedEnvironment != null && preservedEnvironment.containsKey(parameterName)) {
            context.addToEnvironment(parameterName,
                    preservedEnvironment.get(parameterName));
        }
    } catch (NamingException e) {
        // Ignore
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:13,代码来源:JNDIRealm.java

示例4: userCredentialsRemove

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
/**
 * Configure the context to use {@link #connectionName} and
 * {@link #connectionPassword} if specified or an anonymous connection if
 * those attributes are not specified.
 *
 * @param context
 *            DirContext to configure
 */
private void userCredentialsRemove(DirContext context) throws NamingException {
	// Restore the original security environment
	if (connectionName != null) {
		context.addToEnvironment(Context.SECURITY_PRINCIPAL, connectionName);
	} else {
		context.removeFromEnvironment(Context.SECURITY_PRINCIPAL);
	}

	if (connectionPassword != null) {
		context.addToEnvironment(Context.SECURITY_CREDENTIALS, connectionPassword);
	} else {
		context.removeFromEnvironment(Context.SECURITY_CREDENTIALS);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:23,代码来源:JNDIRealm.java

示例5: getPrincipal

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
/**
 * Return the Principal associated with the given user name.
 */
protected synchronized Principal getPrincipal(DirContext context, String username, GSSCredential gssCredential)
		throws NamingException {

	User user = null;
	List<String> roles = null;
	Hashtable<?, ?> preservedEnvironment = null;

	try {
		if (gssCredential != null && isUseDelegatedCredential()) {
			// Preserve the current context environment parameters
			preservedEnvironment = context.getEnvironment();
			// Set up context
			context.addToEnvironment(Context.SECURITY_AUTHENTICATION, "GSSAPI");
			context.addToEnvironment("javax.security.sasl.server.authentication", "true");
			context.addToEnvironment("javax.security.sasl.qop", spnegoDelegationQop);
			// Note: Subject already set in SPNEGO authenticator so no need
			// for Subject.doAs() here
		}
		user = getUser(context, username);
		if (user != null) {
			roles = getRoles(context, user);
		}
	} finally {
		restoreEnvironmentParameter(context, Context.SECURITY_AUTHENTICATION, preservedEnvironment);
		restoreEnvironmentParameter(context, "javax.security.sasl.server.authentication", preservedEnvironment);
		restoreEnvironmentParameter(context, "javax.security.sasl.qop", preservedEnvironment);
	}

	if (user != null) {
		return new GenericPrincipal(user.getUserName(), user.getPassword(), roles, null, null, gssCredential);
	}

	return null;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:38,代码来源:JNDIRealm.java

示例6: getPrincipal

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
/**
 * Return the Principal associated with the given user name.
 */
protected synchronized Principal getPrincipal(DirContext context,
        String username, GSSCredential gssCredential)
    throws NamingException {

    User user = null;
    List<String> roles = null;
    Hashtable<?, ?> preservedEnvironment = null;

    try {
        if (gssCredential != null && isUseDelegatedCredential()) {
            // Preserve the current context environment parameters
            preservedEnvironment = context.getEnvironment();
            // Set up context
            context.addToEnvironment(
                    Context.SECURITY_AUTHENTICATION, "GSSAPI");
            context.addToEnvironment(
                    "javax.security.sasl.server.authentication", "true");
            context.addToEnvironment(
                    "javax.security.sasl.qop", spnegoDelegationQop);
            // Note: Subject already set in SPNEGO authenticator so no need
            //       for Subject.doAs() here
        }
        user = getUser(context, username);
        if (user != null) {
            roles = getRoles(context, user);
        }
    } finally {
        restoreEnvironmentParameter(context,
                Context.SECURITY_AUTHENTICATION, preservedEnvironment);
        restoreEnvironmentParameter(context,
                "javax.security.sasl.server.authentication", preservedEnvironment);
        restoreEnvironmentParameter(context, "javax.security.sasl.qop",
                preservedEnvironment);
    }

    if (user != null) {
        return new GenericPrincipal(user.getUserName(), user.getPassword(),
                roles, null, null, gssCredential);
    }
    
    return null;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:46,代码来源:JNDIRealm.java

示例7: bindAsUser

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
/**
* Check credentials by binding to the directory as the user
*
* @param context The directory context
* @param user The User to be authenticated
* @param credentials Authentication credentials
*
* @exception NamingException if a directory server error occurs
*/
protected boolean bindAsUser(DirContext context,
                             User user,
                             String credentials)
    throws NamingException {

    if (credentials == null || user == null)
        return (false);

    String dn = user.dn;
    if (dn == null)
        return (false);

    // Validate the credentials specified by the user
    if (containerLog.isTraceEnabled()) {
        containerLog.trace("  validating credentials by binding as the user");
   }

   // Set up security environment to bind as the user
   context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn);
   context.addToEnvironment(Context.SECURITY_CREDENTIALS, credentials);

   // Elicit an LDAP bind operation
   boolean validated = false;
   try {
       if (containerLog.isTraceEnabled()) {
           containerLog.trace("  binding as "  + dn);
       }
       context.getAttributes("", null);
       validated = true;
   }
   catch (AuthenticationException e) {
       if (containerLog.isTraceEnabled()) {
           containerLog.trace("  bind attempt failed");
       }
   }

   // Restore the original security environment
   if (connectionName != null) {
       context.addToEnvironment(Context.SECURITY_PRINCIPAL,
                                connectionName);
   } else {
       context.removeFromEnvironment(Context.SECURITY_PRINCIPAL);
   }

   if (connectionPassword != null) {
       context.addToEnvironment(Context.SECURITY_CREDENTIALS,
                                connectionPassword);
   }
   else {
       context.removeFromEnvironment(Context.SECURITY_CREDENTIALS);
   }

   return (validated);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:64,代码来源:JNDIRealm.java

示例8: bindAsUser

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
/**
* Check credentials by binding to the directory as the user
*
* @param context The directory context
* @param user The User to be authenticated
* @param credentials Authentication credentials
*
* @exception NamingException if a directory server error occurs
*/
protected boolean bindAsUser(DirContext context,
                             User user,
                             String credentials)
    throws NamingException {
    Attributes attr;

    if (credentials == null || user == null)
        return (false);
    
    String dn = user.dn;
    if (dn == null)
        return (false);
 
    // Validate the credentials specified by the user
    if (debug >= 3) {
        log("  validating credentials by binding as the user");
   }
 
   // Set up security environment to bind as the user
   context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn);
   context.addToEnvironment(Context.SECURITY_CREDENTIALS, credentials);
 
   // Elicit an LDAP bind operation
   boolean validated = false;
   try {
       if (debug > 2) {
           log("  binding as "  + dn);
       }
       attr = context.getAttributes("", null);
       validated = true;
   }
   catch (AuthenticationException e) {
       if (debug > 2) {
           log("  bind attempt failed");
       }
   }
 
   // Restore the original security environment
   if (connectionName != null) {
       context.addToEnvironment(Context.SECURITY_PRINCIPAL,                                     connectionName);
   } else {
       context.removeFromEnvironment(Context.SECURITY_PRINCIPAL);
   }

   if (connectionPassword != null) {           
       context.addToEnvironment(Context.SECURITY_CREDENTIALS,
                                connectionPassword);
   }
   else {
       context.removeFromEnvironment(Context.SECURITY_CREDENTIALS);
   }
 
   return (validated);
}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:64,代码来源:JNDIRealm.java

示例9: bindAsUser

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
/**
 * Check credentials by binding to the directory as the user
 *
 * @param context     The directory context
 * @param user        The User to be authenticated
 * @param credentials Authentication credentials
 * @throws NamingException if a directory server error occurs
 */
private boolean bindAsUser(final DirContext context, final JNDIUser user, final String credentials)
        throws NamingException {

  if (credentials == null || user == null) {
    return false;
  }

  // Validate the credentials specified by the user
  final String dn = user.getDn();
  if (log.isDebugEnabled()) {
    log.debug("validating credentials by binding as: " + dn);
  }
  if (dn == null) {
    return false;
  }

  // Set up security environment to bind as the user
  context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn);
  context.addToEnvironment(Context.SECURITY_CREDENTIALS, credentials);

  // Elicit an LDAP bind operation
  boolean validated = false;
  try {
    //noinspection UNUSED_SYMBOL,UnusedDeclaration
    context.getAttributes("", null);
    validated = true;
  } catch (AuthenticationException e) {
    if (log.isDebugEnabled()) {
      log.debug("bind attempt failed: " + e, e);
    }
  }

  // Restore the original security environment
  if (connectionPrincipal != null) {
    context.addToEnvironment(Context.SECURITY_PRINCIPAL, connectionPrincipal);
  } else {
    context.removeFromEnvironment(Context.SECURITY_PRINCIPAL);
  }

  if (connectionCredentials != null) {
    context.addToEnvironment(Context.SECURITY_CREDENTIALS, connectionCredentials);
  } else {
    context.removeFromEnvironment(Context.SECURITY_CREDENTIALS);
  }

  return validated;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:56,代码来源:JNDIAuthenticator.java

示例10: userCredentialsAdd

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
/**
  * Configure the context to use the provided credentials for
  * authentication.
  *
  * @param context      DirContext to configure
  * @param dn           Distinguished name of user
  * @param credentials  Credentials of user
  */
private void userCredentialsAdd(DirContext context, String dn,
        String credentials) throws NamingException {
    // Set up security environment to bind as the user
    context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn);
    context.addToEnvironment(Context.SECURITY_CREDENTIALS, credentials);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:15,代码来源:JNDIRealm.java

示例11: userCredentialsAdd

import javax.naming.directory.DirContext; //导入方法依赖的package包/类
/**
 * Configure the context to use the provided credentials for authentication.
 *
 * @param context
 *            DirContext to configure
 * @param dn
 *            Distinguished name of user
 * @param credentials
 *            Credentials of user
 */
private void userCredentialsAdd(DirContext context, String dn, String credentials) throws NamingException {
	// Set up security environment to bind as the user
	context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn);
	context.addToEnvironment(Context.SECURITY_CREDENTIALS, credentials);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:16,代码来源:JNDIRealm.java


注:本文中的javax.naming.directory.DirContext.addToEnvironment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。