Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user roles management #669

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
94a60bb
feat(rbac): init user at OAuth2 login
omar-chahbouni-decathlon Oct 28, 2022
7bdf23c
feat(rbac): manage user resources access
omar-chahbouni-decathlon Nov 29, 2022
8638dc1
feat(web-ui): Added front part for admin rights and some user access …
Vincent59 Dec 12, 2022
b6952fa
feat(web-ui): The demo project is not displayed in projects list anym…
Vincent59 Dec 13, 2022
7dbd4a6
fix(rbac): enable github login
omar-chahbouni-decathlon Dec 15, 2022
8789a67
fix(rbac): enable the demo project access for authenticated users
omar-chahbouni-decathlon Dec 21, 2022
22e47b5
feat(rbac): display project creation and update details (date and user)
omar-chahbouni-decathlon Dec 25, 2022
6fa60a2
feat(rbac): link default project to each user
omar-chahbouni-decathlon Dec 27, 2022
e1d9b2c
feat(rbac): fetch user accounts
omar-chahbouni-decathlon Jan 4, 2023
7ab805d
feat(rbac): manage other users scopes
omar-chahbouni-decathlon Jan 13, 2023
50b0477
feat(web-ui): Add member projects part and fix multiple feedback
Vincent59 Jan 18, 2023
29e2e60
feat(web-ui): Add user project service to front and fix some issues
Vincent59 Jan 19, 2023
a1d1494
refactor(rbac): fetch current user details from session
omar-chahbouni-decathlon Jan 19, 2023
c8a3212
feat(rbac): update users profile
omar-chahbouni-decathlon Jan 20, 2023
260627e
feat(web-ui): Add clear default project button and projects filter
Vincent59 Jan 26, 2023
e509437
fix(web-ui): Add warn message if the user need an admin and rework pr…
Vincent59 Jan 30, 2023
ef24893
feat(rbac): add description field to projects
omar-chahbouni-decathlon Jan 28, 2023
8d079e1
fix(web-ui): Rework top menu navigation
Vincent59 Jan 31, 2023
5a16a04
refactor(rbac): change local oauth2 user profile pictures
omar-chahbouni-decathlon Jan 31, 2023
0a3a1a5
fix(web-ui): hide CTA if the user is a member
Vincent59 Feb 1, 2023
2e7a090
refactor(rbac): rename user entity related classes
omar-chahbouni-decathlon Feb 2, 2023
a783142
feat(rbac): create, read, update and read user groups
omar-chahbouni-decathlon Feb 19, 2023
1c0188e
fix(web-ui): rework UX and fix some front issues
Vincent59 Feb 17, 2023
8815645
fix(web-ui): Affect user to a project depending of the profile and is…
Vincent59 Feb 22, 2023
bc0fa67
fix(web-ui): Buttons not showing correctly
Vincent59 Feb 22, 2023
4959603
feat(rbac): manage group members and managers
omar-chahbouni-decathlon Feb 22, 2023
6b737b4
fix(rbac): return updated user account after updating its scope or pr…
omar-chahbouni-decathlon Feb 23, 2023
479e82f
feat(rbac): manage user group scopes
omar-chahbouni-decathlon Mar 1, 2023
8c6848d
feat(web-ui): group management and fix some issues
Vincent59 Mar 1, 2023
5037445
feat: add a dynamic breadcrumb on each pages, personal user page, use…
Vincent59 Mar 7, 2023
0e6e9c2
fix(web-ui): code improvment, fix breadcrumb on refresh, add elements…
Vincent59 Mar 14, 2023
6b0504e
fix(web-ui): rework group management code
Vincent59 Mar 17, 2023
e0cf0ca
feat(rbac): get the actually applied scopes from user and groups
omar-chahbouni-decathlon Mar 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(rbac): init user at OAuth2 login
  • Loading branch information
omar-chahbouni-decathlon committed Oct 28, 2022
commit 94a60bbde6cb827ce039a2b4f559524cb0e66a12
17 changes: 10 additions & 7 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ A sample `values.yaml` could be like this one:
api:
authentication: oauth2-github # Put a friendly value to disable default authentication
customConfig:
# Active providers
# provider-type has to be one of custom / github / google
# code refers to the provider key ( spring.security.oauth2.client.registration.<code>)
oauth2providers:
conf:
- display-name: Github
provider-type: github
code: github
setup:
-
# Used for front login:
provider:
# Value displayed on the login front page button.
display-value: Github
# Value below can only be one of the following: custom, github or google
type: github
# Refers to the registration code (i.e. spring.security.oauth2.client.registration.<code>)
registration: github

# Oauth
spring:
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.decathlon.ara.security.configuration;

import com.decathlon.ara.security.service.AuthenticationService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest;
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserService;
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService;
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.security.web.SecurityFilterChain;

import java.util.Set;

@Configuration
public class SecurityConfiguration {

@Value("${ara.clientBaseUrl}")
private String clientBaseUrl;

@Value("${ara.loginStartingUrl}")
private String loginStartingUrl;

@Value("${ara.loginProcessingUrl}")
private String loginProcessingUrl;

@Value("${ara.logoutProcessingUrl}")
private String logoutProcessingUrl;

@Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri:}")
private String resourceIssuerUri;

@Value("${spring.security.oauth2.resourceserver.jwt.jwk-set-uri:}")
private String resourceJwkSetUri;

private final AuthenticationService authenticationService;

public SecurityConfiguration(AuthenticationService authenticationService) {
this.authenticationService = authenticationService;
}

@Bean
public SecurityFilterChain configure(HttpSecurity http) throws Exception {
// Whatever is the authentication method, we need to authorize /actguatorgw
String redirectUrl = String.format("%s?spring_redirect=true", this.clientBaseUrl);
http
.csrf().disable() //NOSONAR
.authorizeRequests() //NOSONAR
.antMatchers("/oauth/**", "/actuator/**").permitAll()
.anyRequest().authenticated()
.and()
.logout()
.logoutUrl(this.logoutProcessingUrl) // logout entrypoint
.invalidateHttpSession(true)
.clearAuthentication(true).logoutSuccessUrl(redirectUrl).deleteCookies("JSESSIONID").permitAll()
.and()
.oauth2Login(oauth2 -> oauth2
.userInfoEndpoint(userInfo -> userInfo.oidcUserService(this.oidcUserService()))
.loginProcessingUrl(this.loginProcessingUrl + "/*") // path to redirect to from auth server
.loginPage(String.format("%s/%s", this.clientBaseUrl, "login")) // standard spring redirection for protected resources
.defaultSuccessUrl(redirectUrl, true) // once logged in, redirect to
.authorizationEndpoint().baseUri(this.loginStartingUrl) // entrypoint to initialize oauth processing
);

if (isResourceServerConfiguration()) {
http.oauth2ResourceServer().jwt();
}
return http.build();
}

private OAuth2UserService<OidcUserRequest, OidcUser> oidcUserService() {
final OidcUserService delegate = new OidcUserService();

return userRequest -> {
var providerName = userRequest.getClientRegistration().getRegistrationId();
OidcUser oidcUser = delegate.loadUser(userRequest);
Set<GrantedAuthority> mappedAuthorities = authenticationService.manageUserAtLogin(oidcUser, providerName);
oidcUser = new DefaultOidcUser(mappedAuthorities, oidcUser.getIdToken(), oidcUser.getUserInfo());
return oidcUser;
};
}

private boolean isResourceServerConfiguration() {
return Strings.isNotBlank(resourceIssuerUri) || Strings.isNotBlank(resourceJwkSetUri);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.decathlon.ara.security.configuration.data.providers;

import com.decathlon.ara.domain.security.member.user.entity.UserEntity;
import com.decathlon.ara.repository.ProjectRepository;
import com.decathlon.ara.security.configuration.data.providers.setup.ProviderSetupConfiguration;
import com.decathlon.ara.security.configuration.data.providers.setup.users.UsersConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;

import java.util.*;

@Configuration
@ConfigurationProperties("oauth2providers")
public class OAuth2ProvidersConfiguration {

private List<ProviderSetupConfiguration> setup;

public List<ProviderSetupConfiguration> getSetup() {
return setup;
}

public void setSetup(List<ProviderSetupConfiguration> setup) {
this.setup = setup;
}

/**
* Search for a configuration matching an OAuth2 provider name and a user login.
* If found, a matching user entity is returned
* @param providerName the provider name
* @param login the user login
* @param projectRepository the project repository
* @return the matching user entity, when found
*/
public Optional<UserEntity> getMatchingUserEntityFromProviderNameAndLogin(String providerName, String login, ProjectRepository projectRepository) {
if (StringUtils.isBlank(providerName)) {
return Optional.empty();
}

if (StringUtils.isBlank(login)) {
return Optional.empty();
}

return CollectionUtils.isEmpty(setup) ?
Optional.empty() :
setup.stream()
.filter(configuration -> Objects.nonNull(configuration.getProvider()))
.filter(configuration -> providerName.equalsIgnoreCase(configuration.getProvider().getRegistration()))
.map(configuration -> configuration.getMatchingUserEntityFromLogin(login, projectRepository))
.filter(Optional::isPresent)
.findFirst()
.orElse(Optional.empty());
}

/**
* Get all non-standard attributes for a given provider
* @param providerName the provider name
* @return the map matching the standard attributes to non-standard ones
*/
public Map<String, String> getUsersCustomAttributesFromProviderName(String providerName) {
if (StringUtils.isBlank(providerName)) {
return new HashMap<>();
}

if (CollectionUtils.isEmpty(setup)) {
return new HashMap<>();
}

return setup.stream()
.filter(configuration -> Objects.nonNull(configuration.getProvider()))
.filter(configuration -> providerName.equalsIgnoreCase(configuration.getProvider().getRegistration()))
.map(ProviderSetupConfiguration::getUsers)
.filter(Objects::nonNull)
.map(UsersConfiguration::getCustomAttributes)
.filter(Objects::nonNull)
.findFirst()
.orElse(new HashMap<>());
}
}
Loading