AnsweredAssumed Answered

API : Multiple administrators attempting to update data at the same time

Question asked by Eugene Alekseev on Oct 17, 2018
Latest reply on Oct 22, 2018 by Eugene Alekseev

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];
}
/* omitted */

public
PrincipalDTO lookupUser(String userId) throws Exception {
SearchPrincipalsCommand cmd = new SearchPrincipalsCommand();
cmd.setFilter(Filter.equal(PrincipalDTO.LOGINUID, userId));
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];
}
/* omitted */
public void setSecurityDomain(PrincipalDTO user, String sd) throws Exception {
    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.

Outcomes