@ Override public ReqContext populateContext ( ReqContext context , HttpServletRequest req ) { String userName = getUserName ( req ) ; String doAsUser = req . getHeader ( "doAsUser" ) ; if ( doAsUser == null ) { doAsUser = req . getParameter ( "doAsUser" ) ; } if ( doAsUser != null ) { context . setRealPrincipal ( new SingleUserPrincipal ( userName ) ) ; userName = doAsUser ; } Set < Principal > principals = new HashSet < Principal > ( ) ; if ( userName != null ) { Principal p = new SingleUserPrincipal ( userName ) ; principals . add ( p ) ; } Subject s = new Subject ( true , principals , new HashSet ( ) , new HashSet ( ) ) ; context . setSubject ( s ) ; return context ; }
Populates a given context with a new Subject derived from the credentials in a servlet request .