use of org.eclipse.jetty.plus.jaas.callback.RequestParameterCallback in project cdap by caskdata.
the class JAASLoginService method login.
/* ------------------------------------------------------------ */
public UserIdentity login(final String username, final Object credentials) {
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(credentials.toString().toCharArray());
} else if (callback instanceof ObjectCallback) {
((ObjectCallback) callback).setObject(credentials);
} else if (callback instanceof RequestParameterCallback) {
AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
Request request = (connection == null ? null : connection.getRequest());
if (request != null) {
RequestParameterCallback rpc = (RequestParameterCallback) callback;
rpc.setParameterValues(Arrays.asList(request.getParameterValues(rpc.getParameterName())));
}
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
};
} else {
Class clazz = Loader.loadClass(getClass(), 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, configuration);
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.debug(e);
} catch (IOException e) {
LOG.info(e.getMessage());
LOG.debug(e);
} catch (UnsupportedCallbackException e) {
LOG.info(e.getMessage());
LOG.debug(e);
} catch (InstantiationException e) {
LOG.info(e.getMessage());
LOG.debug(e);
} catch (IllegalAccessException e) {
LOG.info(e.getMessage());
LOG.debug(e);
} catch (ClassNotFoundException e) {
LOG.info(e.getMessage());
LOG.debug(e);
}
return null;
}
Aggregations