Buggy code:
} if ( ( mergedMetaData . getContextParams ( ) ) != null ) { for ( ParamValueMetaData param : mergedMetaData . getContextParams ( ) ) { d . addInitParameter ( param . getParamName ( ) , param . getParamValue ( ) ) ; } } if ( ( ( mergedMetaData . getWelcomeFileList ( ) ) != null ) && ( ( mergedMetaData . getWelcomeFileList ( ) . getWelcomeFiles ( ) ) != null ) ) { d . addWelcomePages ( mergedMetaData . getWelcomeFileList ( ) . getWelcomeFiles ( ) ) ; } else { d . addWelcomePages ( "index.html" , "index.htm" , "index.jsp" ) ; } if ( ( mergedMetaData . getErrorPages ( ) ) != null ) { for ( final ErrorPageMetaData page : mergedMetaData . getErrorPages ( ) ) { final ErrorPage errorPage ; if ( ( ( page . getExceptionType ( ) ) == null ) || ( page . getExceptionType ( ) . isEmpty ( ) ) ) { errorPage = new ErrorPage ( page . getLocation ( ) , Integer . parseInt ( page . getErrorCode ( ) ) ) ; } else { errorPage = new ErrorPage ( page . getLocation ( ) , ( ( Class < ? extends Throwable > ) ( classReflectionIndex . classIndex ( page . getExceptionType ( ) ) . getModuleClass ( ) ) ) ) ; } d . addErrorPages ( errorPage ) ; } } if ( ( mergedMetaData . getMimeMappings ( ) ) != null ) { for ( final MimeMappingMetaData mapping : mergedMetaData . getMimeMappings ( ) ) { d . addMimeMapping ( new io . undertow . servlet . api . MimeMapping ( mapping . getExtension ( ) , mapping . getMimeType ( ) ) ) ; } } Set < String > securityRoleNames = mergedMetaData . getSecurityRoleNames ( ) ; if ( ( mergedMetaData . getSecurityConstraints ( ) ) != null ) { for ( SecurityConstraintMetaData constraint : mergedMetaData . getSecurityConstraints ( ) ) { SecurityConstraint securityConstraint = new SecurityConstraint ( ) . setTransportGuaranteeType ( UndertowDeploymentInfoService . transportGuaranteeType ( constraint . getTransportGuarantee ( ) ) ) ; List < String > roleNames = constraint . getRoleNames ( ) ; if ( ( constraint . getAuthConstraint ( ) ) == null ) { securityConstraint . setEmptyRoleSemantic ( EmptyRoleSemantic . PERMIT ) ; } else if ( ( ( ( roleNames . size ( ) ) == 1 ) && ( roleNames . contains ( "*" ) ) ) && ( securityRoleNames . contains ( "*" ) ) ) { securityConstraint . setEmptyRoleSemantic ( EmptyRoleSemantic . AUTHENTICATE ) ; } else { securityConstraint . addRolesAllowed ( roleNames ) ; } if ( ( constraint . getResourceCollections ( ) ) != null ) { for ( final WebResourceCollectionMetaData resourceCollection : constraint . getResourceCollections ( ) ) { securityConstraint . addWebResourceCollection ( new WebResourceCollection ( ) . addHttpMethods ( resourceCollection . getHttpMethods ( ) ) . addHttpMethodOmissions ( resourceCollection . getHttpMethodOmissions ( ) ) . addUrlPatterns ( resourceCollection . getUrlPatterns ( ) ) ) ; } } d . addSecurityConstraint ( securityConstraint ) ; } } final LoginConfigMetaData loginConfig = mergedMetaData . getLoginConfig ( ) ; if ( loginConfig != null ) { String authMethod = UndertowDeploymentInfoService . authMethod ( loginConfig . getAuthMethod ( ) ) ; if ( ( loginConfig . getFormLoginConfig ( ) ) != null ) { d . setLoginConfig ( new io . undertow . servlet . api . LoginConfig ( authMethod , loginConfig . getRealmName ( ) , loginConfig . getFormLoginConfig ( ) . getLoginPage ( ) , loginConfig . getFormLoginConfig ( ) . getErrorPage ( ) ) ) ; } else { d . setLoginConfig ( new io . undertow . servlet . api . LoginConfig ( authMethod , loginConfig . getRealmName ( ) ) ) ; } } d . addSecurityRoles ( mergedMetaData . getSecurityRoleNames ( ) ) ; if ( ( mergedMetaData . getSecurityDomain ( ) ) != null ) { d . addOuterHandlerChainWrapper ( SecurityContextCreationHandler . wrapper ( mergedMetaData . getSecurityDomain ( ) ) ) ; <START_BUG> d . addDispatchedHandlerChainWrapper ( SecurityContextAssociationHandler . wrapper ( mergedMetaData . getPrincipalVersusRolesMap ( ) , securityContextId ) ) ; <END_BUG> } for ( ServletContextAttribute attribute : attributes ) { d . addServletContextAttribute ( attribute . getName ( ) , attribute . getValue ( ) ) ; } if ( ( ( mergedMetaData . getLocalEncodings ( ) ) != null ) && ( ( mergedMetaData . getLocalEncodings ( ) . getMappings ( ) ) != null ) ) { for ( LocaleEncodingMetaData locale : mergedMetaData . getLocalEncodings ( ) . getMappings ( ) ) { d . addLocaleCharsetMapping ( locale . getLocale ( ) , locale . getEncoding ( ) ) ; } } return d ; } catch ( ClassNotFoundException e ) { throw new StartException ( e ) ; } } private static String authMethod ( String configuredMethod ) { } private static TransportGuaranteeType transportGuaranteeType ( final TransportGuaranteeType type ) { } private static HashMap < String , JspPropertyGroup > createJspConfig ( JBossWebMetaData metaData ) { } private static HashMap < String , TagLibraryInfo > createTldsInfo ( final TldsMetaData tldsMetaData , List < TldMetaData > sharedTlds , final DeploymentClassIndex classReflectionIndex , final ComponentRegistry components , final DeploymentInfo d ) throws ClassNotFoundException { } private static TagLibraryInfo createTldInfo ( final String location , final TldMetaData tldMetaData , final HashMap < String , TagLibraryInfo > ret , final DeploymentClassIndex classReflectionIndex , final ComponentRegistry components , final DeploymentInfo d ) throws ClassNotFoundException { } private static void addListener ( final DeploymentClassIndex classReflectionIndex , final ComponentRegistry components , final DeploymentInfo d , final ListenerMetaData listener ) throws ClassNotFoundException { } private static < T > InstanceFactory < T > createInstanceFactory ( final ComponentRegistry . ComponentManagedReferenceFactory creator ) { } public InjectedValue < ServletContainerService > getContainer ( ) { } public InjectedValue < SecurityDomainContext > getSecurityDomainContextValue ( ) { } public InjectedValue < DistributedCacheManagerFactory > getDistributedCacheManagerFactoryInjectedValue ( ) { }

Fix:
d . addDispatchedHandlerChainWrapper ( SecurityContextAssociationHandler . wrapper ( mergedMetaData . getPrincipalVersusRolesMap ( ) , mergedMetaData . getRunAsIdentity ( ) , securityContextId ) ) ;