protected String determinePrincipalId ( final RequestContext requestContext , final Credential credential ) { if ( StringUtils . isBlank ( properties . getJdbc ( ) . getPrincipalIdAttribute ( ) ) ) { return credential . getId ( ) ; } val principal = WebUtils . getAuthentication ( requestContext ) . getPrincipal ( ) ; val pIdAttribName = properties . getJdbc ( ) . getPrincipalIdAttribute ( ) ; if ( ! principal . getAttributes ( ) . containsKey ( pIdAttribName ) ) { throw new IllegalStateException ( "Principal attribute [" + pIdAttribName + "] cannot be found" ) ; } val pIdAttributeValue = principal . getAttributes ( ) . get ( pIdAttribName ) ; val pIdAttributeValues = CollectionUtils . toCollection ( pIdAttributeValue ) ; var principalId = StringUtils . EMPTY ; if ( ! pIdAttributeValues . isEmpty ( ) ) { principalId = pIdAttributeValues . iterator ( ) . next ( ) . toString ( ) . trim ( ) ; } if ( pIdAttributeValues . size ( ) > 1 ) { LOGGER . warn ( "Principal attribute [{}] was found, but its value [{}] is multi-valued. " + "Proceeding with the first element [{}]" , pIdAttribName , pIdAttributeValue , principalId ) ; } if ( principalId . isEmpty ( ) ) { throw new IllegalStateException ( "Principal attribute [" + pIdAttribName + "] was found, but it is either empty" + " or multi-valued with an empty element" ) ; } return principalId ; }
Extracts principal ID from a principal attribute or the provided credentials .