use of javax.security.auth.callback.PasswordCallback in project felix by apache.
the class ConfigLoginModule method login.
@Override
public boolean login() throws LoginException {
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("Name");
callbacks[1] = new PasswordCallback("Name", false);
try {
handler.handle(callbacks);
} catch (IOException e) {
throw new LoginException(e.getMessage());
} catch (UnsupportedCallbackException e) {
throw new LoginException(e.getMessage());
}
String name = ((NameCallback) callbacks[0]).getName();
char[] password = ((PasswordCallback) callbacks[1]).getPassword();
boolean result = Arrays.equals(name.toCharArray(), password);
if (result) {
result = validateConfig();
}
succeeded = result;
this.name = name;
return result;
}
use of javax.security.auth.callback.PasswordCallback in project simba-os by cegeka.
the class ChainContextCallbackHandler method getFormCredentials.
private void getFormCredentials(Callback[] callbacks) throws UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callback;
String login = chainContext.getUserName();
nameCallback.setName(login);
} else if (callback instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
String password = chainContext.getRequestParameter(AuthenticationConstants.PASSWORD);
passwordCallback.setPassword(null);
if (password != null) {
passwordCallback.setPassword(password.toCharArray());
}
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
use of javax.security.auth.callback.PasswordCallback in project simba-os by cegeka.
the class WsPlainTextCallbackHandler method handle.
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callback;
nameCallback.setName(userName);
} else if (callback instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
passwordCallback.setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
use of javax.security.auth.callback.PasswordCallback in project simba-os by cegeka.
the class ChainContextCallbackHandlerTest method testHandleFormBasedLogin_testPassword.
@Test
public void testHandleFormBasedLogin_testPassword() throws Exception {
when(contextMock.getRequestParameter(AuthenticationConstants.PASSWORD)).thenReturn(PASSWORD);
Callback[] callbacks = new Callback[1];
PasswordCallback passwordCallback = new PasswordCallback(AuthenticationConstants.PASSWORD, false);
callbacks[0] = passwordCallback;
callbackHandler.handle(callbacks);
assertNotNull(passwordCallback.getPassword());
assertEquals(PASSWORD, new String(passwordCallback.getPassword()));
}
use of javax.security.auth.callback.PasswordCallback in project simba-os by cegeka.
the class ChainContextCallbackHandlerTest method testHandleFormBasedLogin_passwordNull.
@Test
public void testHandleFormBasedLogin_passwordNull() throws Exception {
when(contextMock.getRequestParameter(AuthenticationConstants.PASSWORD)).thenReturn(null);
Callback[] callbacks = new Callback[1];
PasswordCallback passwordCallback = new PasswordCallback(AuthenticationConstants.PASSWORD, false);
callbacks[0] = passwordCallback;
callbackHandler.handle(callbacks);
assertEquals(null, passwordCallback.getPassword());
}
Aggregations