本文整理匯總了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);
}
}
示例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
}
}
示例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
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}