diff --git a/pom.xml b/pom.xml index 19cf02beea8d2741e3ade1f0a32c83804f1d456e..537faf7fe3fe8120138cb54e73d8a630604439dc 100644 --- a/pom.xml +++ b/pom.xml @@ -312,6 +312,22 @@ <url>https://forgemia.inra.fr/api/v4/projects/${env.CI_PROJECT_ID}/packages/maven</url> </snapshotRepository> </distributionManagement> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <executions> + <execution> + <id>repackage</id> + <configuration> + <classifier>exec</classifier> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> <profile> diff --git a/src/main/java/fr/inra/oresing/persistence/AuthenticationService.java b/src/main/java/fr/inra/oresing/persistence/AuthenticationService.java index 86c820db4d022474d761ddf423178cac8ff2e386..9ef753af78691fb39e5e7cf2cafa745df6d9fb11 100644 --- a/src/main/java/fr/inra/oresing/persistence/AuthenticationService.java +++ b/src/main/java/fr/inra/oresing/persistence/AuthenticationService.java @@ -495,8 +495,9 @@ public class AuthenticationService { private OreSiUser updateAccount(OreSiUser user, CreateUserRequest createUserRequest) throws AuthenticationFailure, NoSuchAlgorithmException, InvalidKeySpecException, JsonProcessingException { String email = Optional.ofNullable(createUserRequest.getEmail()) .filter(mail -> !Strings.isNullOrEmpty(mail)) - .orElse(user.getEmail()); - boolean emailChanged = !user.getEmail().equals(email); + .orElse(user.getEmail()) + .toLowerCase(); + boolean emailChanged = !user.getEmail().toLowerCase().equals(email); if (createUserRequest.getNewPassword() != null) { Optional.of(createUserRequest.getNewPassword()) .filter(password -> !Strings.isNullOrEmpty(password)) @@ -507,7 +508,7 @@ public class AuthenticationService { } if (emailChanged) { user.setAccountstate(OreSiUser.OreSiUserStates.pending); - user.setEmail(createUserRequest.getEmail()); + user.setEmail(createUserRequest.getEmail().toLowerCase()); } setRoleAdmin(); OreSiUser updateUser = userRepository.update(user); diff --git a/src/main/java/fr/inra/oresing/persistence/UserRepository.java b/src/main/java/fr/inra/oresing/persistence/UserRepository.java index 80df53f5eb72609b15e3fd4488c9b2100fa7f1fc..949c1b298e633bb88b67ab8ca37e3c355bd7d569 100644 --- a/src/main/java/fr/inra/oresing/persistence/UserRepository.java +++ b/src/main/java/fr/inra/oresing/persistence/UserRepository.java @@ -27,9 +27,23 @@ public class UserRepository extends JsonTableRepositoryTemplate<OreSiUser> { @Override protected String getUpsertQuery() { - return "INSERT INTO " + getTable().getSqlIdentifier() + " (id, login, password, email, accountstate, authorizations, chartes) SELECT id, login, password, email, accountstate, authorizations, chartes FROM json_populate_recordset(NULL::" + getTable().getSqlIdentifier() + ", :json::json)" - + " ON CONFLICT (id) DO UPDATE SET updateDate=current_timestamp, login=EXCLUDED.login, password=EXCLUDED.password, email=EXCLUDED.email, accountstate=EXCLUDED.accountstate, authorizations=EXCLUDED.authorizations, chartes=EXCLUDED.chartes" - + " RETURNING id"; + return """ + INSERT INTO %1$s ( + id, login, password, email, accountstate, authorizations, chartes + ) + SELECT + id, lower(login), password, lower(email), accountstate, authorizations, chartes + FROM json_populate_recordset(NULL::%1$s, :json::json) + ON CONFLICT (id) + DO UPDATE SET + updateDate=current_timestamp, + login=lower(EXCLUDED.login), + password=EXCLUDED.password, + email=lower(EXCLUDED.email), + accountstate=EXCLUDED.accountstate, + authorizations=EXCLUDED.authorizations, + chartes=EXCLUDED.chartes RETURNING id""" + .formatted(getTable().getSqlIdentifier()); } @Override @@ -44,7 +58,7 @@ public class UserRepository extends JsonTableRepositoryTemplate<OreSiUser> { public Optional<OreSiUser> findByLogin(String login) { String query = "SELECT '" + getEntityClass().getName() + "' as \"@class\", to_jsonb(t) as json FROM " + getTable().getSqlIdentifier() + " t " + - "WHERE login = :login"; + "WHERE lower(login) = lower(:login)"; Optional<OreSiUser> result = getNamedParameterJdbcTemplate().query(query, new MapSqlParameterSource("login", login), getJsonRowMapper()).stream() @@ -54,7 +68,7 @@ public class UserRepository extends JsonTableRepositoryTemplate<OreSiUser> { public Optional<OreSiUser> findByEmail(String email) { String query = "SELECT '" + getEntityClass().getName() + "' as \"@class\", to_jsonb(t) as json FROM " + getTable().getSqlIdentifier() + " t " + - "WHERE email = :email"; + "WHERE lower(email) = lower(:email)"; Optional<OreSiUser> result = getNamedParameterJdbcTemplate().query(query, new MapSqlParameterSource("email", email), getJsonRowMapper()).stream() @@ -64,7 +78,7 @@ public class UserRepository extends JsonTableRepositoryTemplate<OreSiUser> { public Optional<OreSiUser> findByLoginAndEmail(String login, String email) { String query = "SELECT '" + getEntityClass().getName() + "' as \"@class\", to_jsonb(t) as json FROM " + getTable().getSqlIdentifier() + " t " + - "WHERE email = :email and login = :login"; + "WHERE lower(email) = lower(:email) and lower(login) = lower(:login)"; MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource("login", login); mapSqlParameterSource.addValue("email", email);