本文整理汇总了Java中javax.security.auth.callback.NameCallback.setName方法的典型用法代码示例。如果您正苦于以下问题:Java NameCallback.setName方法的具体用法?Java NameCallback.setName怎么用?Java NameCallback.setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.security.auth.callback.NameCallback
的用法示例。
在下文中一共展示了NameCallback.setName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
System.out.println("Callback Handler - handle called");
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callbacks[i];
nameCallback.setName(name);
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];
passwordCallback.setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i],
"The submitted Callback is unsupported");
}
}
}
示例2: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback ncb = (NameCallback) callback;
ncb.setName(username);
} else if (callback instanceof PasswordCallback) {
PasswordCallback pwcb = (PasswordCallback) callback;
pwcb.setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(
callback,
"We got a "
+ callback.getClass().getCanonicalName()
+ ", but only NameCallback and PasswordCallback is supported");
}
}
}
示例3: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callback;
nameCallback.setName(nameCallback.getDefaultName());
} else if (callback instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
passwordCallback.setPassword(TestJaasConfig.PASSWORD.toCharArray());
} else if (callback instanceof RealmCallback) {
RealmCallback realmCallback = (RealmCallback) callback;
realmCallback.setText(realmCallback.getDefaultText());
} else if (callback instanceof AuthorizeCallback) {
AuthorizeCallback authCallback = (AuthorizeCallback) callback;
if (TestJaasConfig.USERNAME.equals(authCallback.getAuthenticationID())) {
authCallback.setAuthorized(true);
authCallback.setAuthorizedID(authCallback.getAuthenticationID());
}
}
}
}
示例4: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
@Override
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback nc = (NameCallback) callback;
nc.setName(userName);
} else if (callback instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) callback;
pc.setPassword(password);
} else {
throw new UnsupportedCallbackException(callback,
"Unrecognized Callback");
}
}
}
示例5: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
public void handle(
Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback ncb = (NameCallback) callbacks[i];
ncb.setName(username);
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback pcb = (PasswordCallback) callbacks[i];
pcb.setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(
callbacks[i],
"Unrecognized Callback");
}
}
}
示例6: getUserNamePasswordCallbackHandler
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
/**
* Create call back handler using given username and password
*
* @param username
* @param password
* @return CallbackHandler
*/
private static CallbackHandler getUserNamePasswordCallbackHandler(final String username, final char[] password) {
return new CallbackHandler() {
public void handle(final Callback[] callback) {
for (Callback currentCallBack : callback) {
if (currentCallBack instanceof NameCallback) {
final NameCallback nameCallback = (NameCallback) currentCallBack;
nameCallback.setName(username);
} else if (currentCallBack instanceof PasswordCallback) {
final PasswordCallback passCallback = (PasswordCallback) currentCallBack;
passCallback.setPassword(password);
} else {
log.error("Unsupported Callback class = " + currentCallBack.getClass().getName());
}
}
}
};
}
示例7: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[])
*/
@Override
public void handle ( Callback[] callbacks ) throws IOException, UnsupportedCallbackException {
for ( Callback cb : callbacks ) {
if ( log.isDebugEnabled() ) {
log.debug("Got callback " + cb.getClass().getName());
}
if ( cb instanceof NameCallback ) {
NameCallback nc = (NameCallback) cb;
String userDomain = this.getSpecifiedUserDomain();
if ( this.getUsername() != null && userDomain != null ) {
nc.setName(this.getUsername() + "@" + userDomain);
}
}
else if ( cb instanceof PasswordCallback ) {
PasswordCallback pc = (PasswordCallback) cb;
if ( this.getPassword() != null ) {
pc.setPassword(this.getPassword().toCharArray());
}
}
}
}
示例8: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback ncb = (NameCallback) callbacks[i];
ncb.setName(username);
}
else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback pcb = (PasswordCallback) callbacks[i];
pcb.setPassword(password.toCharArray());
}
else {
throw new UnsupportedCallbackException
(callbacks[i], "Unrecognized Callback");
}
}
}
示例9: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
/**
* Handles the callbacks, and sets the user/password detail.
* @param callbacks the callbacks to handle
* @throws IOException if an input or output error occurs.
*/
public void handle( Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for ( int i=0; i<callbacks.length; i++) {
if ( callbacks[i] instanceof NameCallback && username != null) {
NameCallback nc = (NameCallback) callbacks[i];
nc.setName( username);
}
else if ( callbacks[i] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) callbacks[i];
pc.setPassword( password.toCharArray());
}
else {
/*throw new UnsupportedCallbackException(
callbacks[i], "Unrecognized Callback");*/
}
}
}
示例10: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
@Override
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback ncb = (NameCallback) callback;
ncb.setName(username);
} else if (callback instanceof PasswordCallback) {
PasswordCallback pwcb = (PasswordCallback) callback;
pwcb.setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(
callback,
"We got a "
+ callback.getClass().getCanonicalName()
+ ", but only NameCallback and PasswordCallback is supported");
}
}
}
示例11: getUsernamePasswordHandler
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
/**
* Used by the BASIC Auth mechanism for establishing a LoginContext
* to authenticate a client/caller/request.
*
* @param username client username
* @param password client password
* @return CallbackHandler to be used for establishing a LoginContext
*/
public static CallbackHandler getUsernamePasswordHandler(
final String username, final String password) {
LOGGER.fine("username=" + username + "; password=" + password.hashCode());
final CallbackHandler handler = new CallbackHandler() {
public void handle(final Callback[] callback) {
for (int i=0; i<callback.length; i++) {
if (callback[i] instanceof NameCallback) {
final NameCallback nameCallback = (NameCallback) callback[i];
nameCallback.setName(username);
} else if (callback[i] instanceof PasswordCallback) {
final PasswordCallback passCallback = (PasswordCallback) callback[i];
passCallback.setPassword(password.toCharArray());
} else {
LOGGER.warning("Unsupported Callback i=" + i + "; class="
+ callback[i].getClass().getName());
}
}
}
};
return handler;
}
示例12: handleNameCallback
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
private void handleNameCallback(NameCallback nc) {
// check to see if this user is in the user password database.
if (credentials.get(nc.getDefaultName()) == null) {
LOG.warn("User '" + nc.getDefaultName() + "' not found in list of DIGEST-MD5 authenticateable users.");
return;
}
nc.setName(nc.getDefaultName());
userName = nc.getDefaultName();
}
示例13: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
public void handle(
Callback[] callbacks ) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback nc = (NameCallback) callbacks[i];
nc.setName(username);
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) callbacks[i];
pc.setPassword(password);
}
}
}
示例14: getUsernamePasswordHandler
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
private static CallbackHandler getUsernamePasswordHandler(final String username, final String password) {
return callbacks -> {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
final NameCallback nameCallback = (NameCallback) callback;
nameCallback.setName(username);
} else if (callback instanceof PasswordCallback) {
final PasswordCallback passCallback = (PasswordCallback) callback;
passCallback.setPassword(password.toCharArray());
} else {
System.err.println("Unsupported Callback: " + callback.getClass().getName());
}
}
};
}
示例15: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
iHandler.handle(callbacks);
if (iRealm != null)
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback nc = (NameCallback) callback;
if (nc.getName() != null && !nc.getName().contains("@"))
nc.setName(nc.getName() + "@" + iRealm);
}
}
}