3131import org .springframework .security .core .GrantedAuthority ;
3232import org .springframework .security .core .context .SecurityContextHolder ;
3333import org .springframework .security .web .authentication .WebAuthenticationDetails ;
34+ import org .springframework .util .StringUtils ;
3435import tools .jackson .core .type .TypeReference ;
3536
3637import java .io .Serial ;
4142import java .util .Optional ;
4243
4344import static org .cloudfoundry .identity .uaa .util .UaaTokenUtils .isJwtToken ;
44- import static org .springframework .util .StringUtils .hasText ;
4545
4646/**
4747 * Base class for UAA events that want to publish audit records.
@@ -137,10 +137,10 @@ private String getAuthenticationString(Authentication caller) {
137137
138138 private Optional <String > extractRemoteAddress (Object details ) {
139139 return switch (details ) {
140- case UaaAuthenticationDetails d -> Optional .ofNullable (d .getOrigin ());
141- case OAuth2AuthenticationDetails d -> Optional .ofNullable (d .getRemoteAddress ());
142- case WebAuthenticationDetails d -> Optional .of (d .getRemoteAddress ());
143- case Map <?, ?> map -> Optional .ofNullable (map .get ("remoteAddress" )).map (Object ::toString );
140+ case UaaAuthenticationDetails d -> Optional .ofNullable (d .getOrigin ()). filter ( StringUtils :: hasText ) ;
141+ case OAuth2AuthenticationDetails d -> Optional .ofNullable (d .getRemoteAddress ()). filter ( StringUtils :: hasText ) ;
142+ case WebAuthenticationDetails d -> Optional .ofNullable (d .getRemoteAddress ()). filter ( StringUtils :: hasText );
143+ case Map <?, ?> map -> Optional .ofNullable (map .get ("remoteAddress" )).map (Object ::toString ). filter ( StringUtils :: hasText ) ;
144144 case String jsonBlob -> extractRemoteAddressFromJson (jsonBlob );
145145 default -> {
146146 logger .warn ("Unhandled Authentication.details type in audit origin: {}" , details .getClass ().getName ());
@@ -166,7 +166,7 @@ private void appendTokenDetails(Authentication caller, StringBuilder builder) {
166166 } else if (caller .getDetails () instanceof OAuth2AuthenticationDetails oAuth2AuthenticationDetails ) {
167167 tokenValue = oAuth2AuthenticationDetails .getTokenValue ();
168168 }
169- if (hasText (tokenValue )) {
169+ if (StringUtils . hasText (tokenValue )) {
170170 if (isJwtToken (tokenValue )) {
171171 try {
172172 Jwt token = JwtHelper .decode (tokenValue );
0 commit comments