|
31 | 31 | import java.math.BigDecimal; |
32 | 32 | import java.security.SecureRandom; |
33 | 33 | import java.sql.*; |
34 | | -import java.util.ArrayList; |
| 34 | +import java.util.*; |
35 | 35 | import java.util.Date; |
36 | | -import java.util.List; |
37 | | -import java.util.Random; |
38 | 36 |
|
39 | 37 | /** |
40 | 38 | * This type was created in VisualAge. |
@@ -158,33 +156,32 @@ public List<UserIdentity> getUserIdentitiesFromSubjectAndIssuer(Connection con, |
158 | 156 | lg.trace(sql); |
159 | 157 | } |
160 | 158 | stmt = con.createStatement(); |
161 | | - ArrayList<UserIdentityBuilder> userIdentities = new ArrayList<>(); |
| 159 | + HashMap<BigDecimal, UserIdentityBuilder> userIdentities = new HashMap<>(); |
162 | 160 | try { |
163 | 161 | rset = stmt.executeQuery(sql); |
164 | 162 | while (rset.next()) { |
165 | 163 | BigDecimal userKey = rset.getBigDecimal(UserIdentityTable.userRef.getUnqualifiedColName()); |
166 | 164 | String claim = rset.getString(SpecialUsersTable.table.special.getUnqualifiedColName()); |
167 | | - |
168 | | - int lastUserAdded = userIdentities.size()-1; |
169 | | - boolean sameUser = !userIdentities.isEmpty() && userIdentities.get(lastUserAdded).getId().equals(userKey); |
170 | | - if (sameUser && claim != null){ |
171 | | - userIdentities.get(lastUserAdded).getUserBuilder().addSpecial(SpecialUser.SPECIAL_CLAIM.fromDatabase(claim)); |
172 | | - } else{ |
| 165 | + if (userIdentities.containsKey(userKey) && claim != null) { |
| 166 | + userIdentities.get(userKey).getUserBuilder().addSpecial(SpecialUser.SPECIAL_CLAIM.fromDatabase(claim)); |
| 167 | + } else if (userIdentities.containsKey(userKey)) { |
| 168 | + throw new SQLException("Duplicate VCell user identity found."); |
| 169 | + } else { |
173 | 170 | String userID = rset.getString(UserTable.table.userid.getUnqualifiedColName()); |
174 | 171 | SpecialUser.SpecialUserBuilder builder = new SpecialUser.SpecialUserBuilder(userID, new KeyValue(userKey)); |
175 | 172 | if (claim != null){ |
176 | 173 | builder.addSpecial(SpecialUser.SPECIAL_CLAIM.fromDatabase(claim)); |
177 | 174 | } |
178 | | - userIdentities.add(new UserIdentityBuilder(userKey, builder, |
179 | | - subject, issuer, UserIdentityTable.table.getUserIdentityDate(rset))); |
| 175 | + userIdentities.put(userKey, new UserIdentityBuilder(userKey, builder, subject, issuer, |
| 176 | + UserIdentityTable.table.getUserIdentityDate(rset))); |
180 | 177 | } |
181 | 178 | } |
182 | 179 | } finally { |
183 | 180 | stmt.close(); |
184 | 181 | } |
185 | 182 |
|
186 | 183 | ArrayList<UserIdentity> identities = new ArrayList<>(); |
187 | | - for (UserIdentityBuilder userIdentityBuilder : userIdentities) { |
| 184 | + for (UserIdentityBuilder userIdentityBuilder : userIdentities.values()) { |
188 | 185 | identities.add(userIdentityBuilder.build()); |
189 | 186 | } |
190 | 187 |
|
|
0 commit comments