question: public UserSession createSession ( UUID sessionId , User user , Locale locale , boolean system ) { List < Role > roles = new ArrayList < > ( ) ; for ( UserRole userRole : user . getUserRoles ( ) ) { if ( userRole . getRole ( ) != null ) { roles . add ( userRole . getRole ( ) ) ; } } UserSession session = new UserSession ( sessionId , user , roles , locale , system ) ; 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 ; }
target:  Create a new session and fill it with security data. Must be called inside a transaction.