Fix encoding issues of Shibboleth attributes #7

Manually merged
ansv7779 merged 1 commits from shibboleth-attributes-encoding into main 2025-05-12 10:48:27 +02:00

View File

@ -4,6 +4,7 @@ import jakarta.servlet.http.HttpServletRequest;
import org.springframework.security.authentication.AuthenticationDetailsSource;
import org.springframework.security.core.GrantedAuthority;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
@ -28,7 +29,13 @@ public class ShibbolethAuthenticationDetailsSource implements
}
private static String getString(final HttpServletRequest context, final String mail) {
return context.getAttribute(mail) instanceof String s ? s : null;
if (context.getAttribute(mail) instanceof String s) {
// Somewhere in the Shibboleth pipeline, the encoding of the string mixed up.
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
return new String(bytes, StandardCharsets.UTF_8);
} else {
return null;
}
}
private static Collection<GrantedAuthority> getGrantedAuthorities(final HttpServletRequest context) {