Skip to content

Commit 7d89e23

Browse files
committed
Filter blank remoteAddress values in extractRemoteAddress
1 parent f5b6cd0 commit 7d89e23

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

server/src/main/java/org/cloudfoundry/identity/uaa/audit/event/AbstractUaaEvent.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.security.core.GrantedAuthority;
3232
import org.springframework.security.core.context.SecurityContextHolder;
3333
import org.springframework.security.web.authentication.WebAuthenticationDetails;
34+
import org.springframework.util.StringUtils;
3435
import tools.jackson.core.type.TypeReference;
3536

3637
import java.io.Serial;
@@ -41,7 +42,6 @@
4142
import java.util.Optional;
4243

4344
import 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

Comments
 (0)