Skip to content

Commit

Permalink
ugly fix just to see if it works
Browse files Browse the repository at this point in the history
  • Loading branch information
emmdurin committed Nov 23, 2023
1 parent 95ee6ec commit 972790c
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
*/
package org.georchestra.gateway.accounts.admin;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Objects;
import java.util.stream.Collectors;

import org.georchestra.gateway.security.GeorchestraUserCustomizerExtension;
import org.georchestra.security.model.GeorchestraUser;
import org.springframework.core.Ordered;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;

import lombok.NonNull;
Expand Down Expand Up @@ -62,6 +69,18 @@ public class CreateAccountUserCustomizer implements GeorchestraUserCustomizerExt
final boolean isPreAuth = auth instanceof PreAuthenticatedAuthenticationToken;
if (isOauth2) {
Objects.requireNonNull(mappedUser.getOAuth2ProviderId(), "GeorchestraUser.oAuth2ProviderId is null");
GeorchestraUser user = accounts.getOrCreate(mappedUser);

try {
// ((OAuth2AuthenticationToken) auth).setDetails();
Field field = AbstractAuthenticationToken.class.getDeclaredField("authorities");
field.setAccessible(true);
field.set(auth,
user.getRoles().stream().map(r -> new SimpleGrantedAuthority(r)).collect(Collectors.toList()));
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
}

}
if (isPreAuth) {
Objects.requireNonNull(mappedUser.getUsername(), "GeorchestraUser.username is null");
Expand Down

0 comments on commit 972790c

Please sign in to comment.