Hello everyone!
I have a problem with updating user Security Domain using API with Java. I always get exception
com.rsa.command.exception.ConcurrentUpdateException: Multiple administrators attempting to update data at the same time.
What I'm trying to do:
ClientSession sess = RSAAPI.startSession(username, password);
RSAAPI api = new RSAAPI();
PrincipalDTO user = api.lookupUser(USERNAME);
api.setSecurityDomain(user, SECURITY_DOMAIN);
/* omitted */
public static ClientSession startSession(String username, String password) throws Exception {
ClientSession sess;
Connection conn = ConnectionFactory.getConnection();
sess = conn.connect(username, password);
CommandTargetPolicy.setDefaultCommandTarget(sess);
return sess;
}
/* omitted */
public RSAAPI() throws Exception {
SearchRealmsCommand searchRealmCmd = new SearchRealmsCommand();
searchRealmCmd.execute();
RealmDTO[] realms = searchRealmCmd.getRealms();
if (realms.length == 0) {
throw new Exception("ERROR: Could not find realm SystemDomain");
}
domain = realms[0].getTopLevelSecurityDomain();
idSource = realms[0].getIdentitySources()[0];
}
public void setSecurityDomain(PrincipalDTO user, String sd) throws Exception {/* omitted */cmd.setFilter(Filter.equal(PrincipalDTO.LOGINUID, userId));/* omitted */
public PrincipalDTO lookupUser(String userId) throws Exception {
SearchPrincipalsCommand cmd = new SearchPrincipalsCommand();
cmd.setSystemFilter(Filter.empty());
cmd.setLimit(1);
cmd.setIdentitySourceGuid(idSource.getGuid());
cmd.setSecurityDomainGuid(domain.getGuid());
cmd.setGroupGuid(null);
cmd.setSearchSubDomains(true);
cmd.execute();
if (cmd.getPrincipals().length < 1) {
throw new Exception("ERROR: Unable to find user " + userId + ".");
}
return cmd.getPrincipals()[0];
}
UpdatePrincipalCommand cmd = new UpdatePrincipalCommand();
cmd.setIdentitySourceGuid(user.getIdentitySourceGuid());
SecurityDomainDTO secDomain = lookupSecurityDomain(sd);
UpdatePrincipalDTO updateDTO = new UpdatePrincipalDTO();
updateDTO.setGuid(user.getGuid());
updateDTO.setRowVersion(user.getRowVersion());
List<ModificationDTO> mods = new ArrayList<ModificationDTO>();
ModificationDTO mod;
mod = new ModificationDTO();
mod.setOperation(ModificationDTO.REPLACE_ATTRIBUTE);
mod.setName(PrincipalDTO.SECURITY_DOMAIN);
mod.setValues(new Object[] { secDomain.getGuid() });
mods.add(mod);
updateDTO.setModifications(mods.toArray(new ModificationDTO[mods.size()]));
cmd.setPrincipalModification(updateDTO);
cmd.execute();
}
I have already got working my code working for user lookup/delete, but this part always throws exception mentioned above.
I've figured out that the problem is in Row Version - so if I increase it for 1 - it works
But the problem appears again when I try to change Security Domain for one user multiple times - so every time I have to increase this Row Version, but user.getRowVersion() always returns 0, so I have to store information about user changes and every time I have to add an increased value - that's a bit inconvenient.