Skip to content

Commit 027afe1

Browse files
authored
Fix duplicate key error on case-insensitive info_key (#1136)
Change collation compatible with both mysql and mariadb
1 parent 0aa7281 commit 027afe1

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

iam-login-service/src/main/java/it/infn/mw/iam/core/IamAuthenticationHolderEntityService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.mitre.oauth2.model.AuthenticationHolderEntity;
2323
import org.mitre.oauth2.repository.AuthenticationHolderRepository;
2424
import org.mitre.oauth2.service.AuthenticationHolderEntityService;
25-
import org.springframework.beans.factory.annotation.Autowired;
2625
import org.springframework.context.annotation.Primary;
2726
import org.springframework.security.oauth2.provider.OAuth2Authentication;
2827
import org.springframework.stereotype.Service;
@@ -39,7 +38,6 @@ public class IamAuthenticationHolderEntityService implements AuthenticationHolde
3938
final AuthenticationHolderRepository repo;
4039
final ExternalAuthenticationInfoBuilder mapBuilder;
4140

42-
@Autowired
4341
public IamAuthenticationHolderEntityService(AuthenticationHolderRepository repo,
4442
ExternalAuthenticationInfoBuilder mapBuilder) {
4543
this.repo = repo;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2021
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package it.infn.mw.iam.test.ext_authn;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
20+
21+
import java.util.Map;
22+
23+
import org.junit.jupiter.api.Test;
24+
import org.mitre.oauth2.model.AuthenticationHolderEntity;
25+
import org.mitre.oauth2.model.SavedUserAuthentication;
26+
import org.mitre.oauth2.repository.AuthenticationHolderRepository;
27+
import org.springframework.beans.factory.annotation.Autowired;
28+
import org.springframework.boot.test.context.SpringBootTest;
29+
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
30+
31+
@SpringBootTest
32+
class SavedUserAuthenticationTests {
33+
34+
@Autowired
35+
private AuthenticationHolderRepository authHolderRepo;
36+
37+
@Test
38+
void testMultipleCaseSensitiveAdditionalInfoAreInserted() {
39+
SavedUserAuthentication userAuth =
40+
new SavedUserAuthentication(new UsernamePasswordAuthenticationToken("test", "password"));
41+
userAuth.setAdditionalInfo(Map.of("MAIL", "mail@example.com", "mail", "another@example.com"));
42+
AuthenticationHolderEntity authHolder = new AuthenticationHolderEntity();
43+
authHolder.setUserAuth(userAuth);
44+
assertTrue(authHolder.getUserAuth().getAdditionalInfo().containsKey("MAIL"));
45+
assertTrue(authHolder.getUserAuth().getAdditionalInfo().containsKey("mail"));
46+
assertEquals("mail@example.com", authHolder.getUserAuth().getAdditionalInfo().get("MAIL"));
47+
assertEquals("another@example.com", authHolder.getUserAuth().getAdditionalInfo().get("mail"));
48+
AuthenticationHolderEntity saved = authHolderRepo.save(authHolder);
49+
assertEquals("mail@example.com", saved.getUserAuth().getAdditionalInfo().get("MAIL"));
50+
assertEquals("another@example.com", saved.getUserAuth().getAdditionalInfo().get("mail"));
51+
}
52+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- Nothing to do: in H2, info_key is already case-sensitive
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE saved_user_auth_info MODIFY info_key varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

0 commit comments

Comments
 (0)