{
// get the set of groups from the resolver
String[] groupNames = groupManager.getGroupsForUser(userId);
// create a principal with the user and the groups they belong to
Principal p = new UserGroupPrincipal(userId, groupNames);
// use a callback to set the principal and groups for this user
handler.handle(new Callback[] {
new CallerPrincipalCallback(s, p),
new GroupPrincipalCallback(s, groupNames) });