use of org.eclipse.jetty.jaas.callback.RequestParameterCallback in project jetty.project by eclipse.
the class JAASLoginService method login.
/* ------------------------------------------------------------ */
@Override
public UserIdentity login(final String username, final Object credentials, final ServletRequest request) {
try {
CallbackHandler callbackHandler = null;
if (_callbackHandlerClass == null) {
callbackHandler = new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(username);
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword((char[]) credentials.toString().toCharArray());
} else if (callback instanceof ObjectCallback) {
((ObjectCallback) callback).setObject(credentials);
} else if (callback instanceof RequestParameterCallback) {
RequestParameterCallback rpc = (RequestParameterCallback) callback;
if (request != null)
rpc.setParameterValues(Arrays.asList(request.getParameterValues(rpc.getParameterName())));
} else
throw new UnsupportedCallbackException(callback);
}
}
};
} else {
Class<?> clazz = Loader.loadClass(_callbackHandlerClass);
callbackHandler = (CallbackHandler) clazz.newInstance();
}
//set up the login context
//TODO jaspi requires we provide the Configuration parameter
Subject subject = new Subject();
LoginContext loginContext = new LoginContext(_loginModuleName, subject, callbackHandler);
loginContext.login();
//login success
JAASUserPrincipal userPrincipal = new JAASUserPrincipal(getUserName(callbackHandler), subject, loginContext);
subject.getPrincipals().add(userPrincipal);
return _identityService.newUserIdentity(subject, userPrincipal, getGroups(subject));
} catch (LoginException e) {
LOG.warn(e);
} catch (IOException e) {
LOG.warn(e);
} catch (UnsupportedCallbackException e) {
LOG.warn(e);
} catch (InstantiationException e) {
LOG.warn(e);
} catch (IllegalAccessException e) {
LOG.warn(e);
} catch (ClassNotFoundException e) {
LOG.warn(e);
}
return null;
}
Aggregations