public UserSession createSession(UserSession src,User user){
  List<Role> roles=new ArrayList<>();
  for (  UserRole userRole : user.getUserRoles()) {
    if (userRole.getRole() != null) {
      roles.add(userRole.getRole());
    }
  }
  UserSession session=new UserSession(src,user,roles,src.getLocale());
  compilePermissions(session,roles);
  if (user.getGroup() == null)   throw new IllegalStateException("User is not in a Group");
  compileConstraints(session,user.getGroup());
  compileSessionAttributes(session,user.getGroup());
  return session;
}

public UserSession createSession ( UserSession src , User user ) { List < Role > roles = new ArrayList < > ( ) ; for ( UserRole userRole : user . getUserRoles ( ) ) { if ( userRole . getRole ( ) != null ) { roles . add ( userRole . getRole ( ) ) ; } } UserSession session = new UserSession ( src , user , roles , src . getLocale ( ) ) ; compilePermissions ( session , roles ) ; if ( user . getGroup ( ) == null ) throw new IllegalStateException ( "User is not in a Group" ) ; compileConstraints ( session , user . getGroup ( ) ) ; compileSessionAttributes ( session , user . getGroup ( ) ) ; return session ; }
create a new session from existing for another user and fill it with security data for that new user . must be called inside a transaction .
