put("username", inUsername);
tokens.put("password", inPassword);
List users = databaseWorker.executeQuery(SQL_LOG_USER_IN, tokens);
if (users.size() == 1) {
inRequest.getSession(true).setAttribute("username", inUsername);
Map m = (Map)users.get(0);
String groupsString = (String)m.get("GROUPS");
StringTokenizer st = new StringTokenizer(groupsString, ",");
List
groups = new ArrayList();
while (st.hasMoreTokens()) {
String nextGroup = st.nextToken();
groups.add(nextGroup);
}
inRequest.getSession(true).setAttribute("groups", groups);
return true;
} else {
return false;
}
CHAPTER 7 n ENTER THE ENTERPRISE: A DWR-BASED REPORT PORTAL 403
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
So, first a query is done that attempts to retrieve the user??™s record from the users table
based on username and password. If a single match is found, the user is logged in. The username
is added as a session attribute, which lets the app be reloaded, and the user won??™t have
to log in again because of that code we saw on the client with the username being passed in to
init(). Next, we get the list of groups the user belongs to, which is a comma-separated string.
Pages:
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698