This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 465cec3d authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

GitLab Gruppen werden jetzt auch im JWT gespeichert.

parent e1bd276b
2 merge requests!17Initial Merge to Prepare Release 1.0.0,!1Resolve "Metadaten konsolideren"
...@@ -2,7 +2,9 @@ package at.ac.uibk.gitsearch.security.oauth2; ...@@ -2,7 +2,9 @@ package at.ac.uibk.gitsearch.security.oauth2;
import java.io.IOException; import java.io.IOException;
import java.security.Principal; import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
...@@ -11,6 +13,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -11,6 +13,7 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority; 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.authentication.OAuth2AuthenticationToken;
import org.springframework.security.oauth2.core.oidc.user.OidcUser; import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
...@@ -41,8 +44,14 @@ public class SavedRequestAwareAuthenticationSuccessHandlerWithJWTSupport extends ...@@ -41,8 +44,14 @@ public class SavedRequestAwareAuthenticationSuccessHandlerWithJWTSupport extends
if (authentication instanceof OAuth2AuthenticationToken) { if (authentication instanceof OAuth2AuthenticationToken) {
OAuth2AuthenticationToken oAuthA = (OAuth2AuthenticationToken) authentication; OAuth2AuthenticationToken oAuthA = (OAuth2AuthenticationToken) authentication;
String mail = ((OidcUser) ((OAuth2AuthenticationToken) authentication).getPrincipal()).getEmail(); String mail = ((OidcUser) ((OAuth2AuthenticationToken) authentication).getPrincipal()).getEmail();
List<String> gitLabGroups = (List<String>) ((OidcUser) ((OAuth2AuthenticationToken) authentication).getPrincipal()).getClaims().get("groups");
String idToken = oAuthA.getPrincipal().getAttribute("idToken"); String idToken = oAuthA.getPrincipal().getAttribute("idToken");
authenticationForToken = new SimpleAuthentication(new SimplePrincipal(mail), authentication.getAuthorities()); List<GrantedAuthority> roles = new ArrayList<>();
roles.addAll(authentication.getAuthorities());
for(String gitLabGroup: gitLabGroups) {
roles.add(new SimpleGrantedAuthority(gitLabGroup));
}
authenticationForToken = new SimpleAuthentication(new SimplePrincipal(mail), roles);
authenticationForToken.setAuthenticated(authentication.isAuthenticated()); authenticationForToken.setAuthenticated(authentication.isAuthenticated());
} }
String token = tokenProvider.createToken(authenticationForToken, REQUEST_TOKEN_LIVETIME *1000L); // 200 secs (for Debugging) String token = tokenProvider.createToken(authenticationForToken, REQUEST_TOKEN_LIVETIME *1000L); // 200 secs (for Debugging)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment