fix charsets

This commit is contained in:
_Bastler 2022-12-04 20:20:50 +01:00
parent 7d5f08646e
commit c73c172abe
4 changed files with 20 additions and 10 deletions

View File

@ -307,7 +307,7 @@ public class SecurityConfig {
firewall.setAllowedHeaderValues((header) -> {
String parsed;
try {
parsed = new String(header.getBytes("ISO_8859_1"), "UTF_8");
parsed = new String(header.getBytes("ISO-8859-1"), "UTF-8");
return allowed.matcher(parsed).matches();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();

View File

@ -178,7 +178,7 @@ public class OidcTokenManager implements SmartInitializingSingleton {
token.setAccessToken(RandomStringUtils.random(ACCESS_TOKEN_LENGTH, true, true));
token.setExpiresIn(client.getTokenLifetime());
Builder claimsSetBuilder = createUserClaims(user);
Builder claimsSetBuilder = createUserClaims(client, user);
claimsSetBuilder.issuer(issuer);
claimsSetBuilder.audience(client.getClientId());
@ -215,23 +215,27 @@ public class OidcTokenManager implements SmartInitializingSingleton {
/**
* Creates the user claims.
*
* @param client the client
* @param user the user
* @return the builder
*/
public Builder createUserClaims(User user) {
public Builder createUserClaims(OidcClient client, User user) {
Builder claimsSetBuilder = new Builder();
claimsSetBuilder.subject(String.valueOf(user.getId()));
claimsSetBuilder.claim("name", user.getUsername());
claimsSetBuilder.claim("username", user.getUsername());
claimsSetBuilder.claim("preferred_username", user.getUsername());
String username = user.getUsername();
claimsSetBuilder.claim("name", username);
claimsSetBuilder.claim("username", username);
claimsSetBuilder.claim("preferred_username", username);
UserProfileField emailProfileField = userProfileFieldManager.get(user.getId(),
UserProfileFields.PROFILE_FIELD_EMAIL);
UserProfileField emailPrimaryProfileField = userProfileFieldManager.get(user.getId(),
UserProfileFields.PROFILE_FIELD_EMAIL_PRIMARY);
String email = userManager.getBstlyEmail(user.getUsername());
String email = userManager.getBstlyEmail(username);
if (emailProfileField != null && emailPrimaryProfileField != null
&& StringUtils.hasText(emailProfileField.getValue())
&& Boolean.getBoolean(emailPrimaryProfileField.getValue())) {

View File

@ -19,7 +19,9 @@ import de.bstly.we.businesslogic.UserManager;
import de.bstly.we.controller.BaseController;
import de.bstly.we.controller.support.EntityResponseStatusException;
import de.bstly.we.model.User;
import de.bstly.we.oidc.businesslogic.OidcClientManager;
import de.bstly.we.oidc.businesslogic.OidcTokenManager;
import de.bstly.we.oidc.model.OidcClient;
import de.bstly.we.oidc.model.OidcToken;
/**
@ -32,6 +34,8 @@ public class OidcUserInfoController extends BaseController {
@Autowired
private OidcTokenManager oidcTokenManager;
@Autowired
private OidcClientManager oidcClientManager;
@Autowired
private UserManager userManager;
/**
@ -46,6 +50,7 @@ public class OidcUserInfoController extends BaseController {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Long userId = getCurrentUserId();
OidcClient client = null;
if (!auth.isAuthenticated()) {
if (authorizationHeader == null) {
throw new EntityResponseStatusException(HttpStatus.UNAUTHORIZED);
@ -58,6 +63,7 @@ public class OidcUserInfoController extends BaseController {
throw new EntityResponseStatusException(HttpStatus.UNAUTHORIZED);
}
userId = token.getUserId();
client = oidcClientManager.get(token.getClient());
}
User user = userManager.get(userId);
@ -66,7 +72,7 @@ public class OidcUserInfoController extends BaseController {
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
}
Builder claimsSetBuilder = oidcTokenManager.createUserClaims(user);
Builder claimsSetBuilder = oidcTokenManager.createUserClaims(client, user);
throw new EntityResponseStatusException(claimsSetBuilder.build().toJSONObject(), HttpStatus.OK);

View File

@ -13,7 +13,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<log4j2.version>2.19.0</log4j2.version>
<revision>2.0.1-SNAPSHOT</revision>
<revision>2.0.2-SNAPSHOT</revision>
</properties>
<parent>