//Session session = currentUser.getSession();
if ( !currentUser.isAuthenticated() ) {
//collect user principals and credentials in a gui specific manner
//such as username/password html form, X509 certificate, OpenID, etc.
//We'll use the username/password example here since it is the most common.
UsernamePasswordToken token = new UsernamePasswordToken("testuserdynamic", "doesthiswork");
//this is all you have to do to support 'remember me' (no config - built in!):
//token.setRememberMe(false);
try {
currentUser.login(token);
//if no exception, that's it, we're done!
log.info("username logged in is: " + token.getUsername());
} catch ( UnknownAccountException uae ) {
//username wasn't in the system, show them an error message?
log.info("Username wasn't in the system");
} catch ( IncorrectCredentialsException ice ) {
//password didn't match, try again?