@Test public void testUpdateExternal() throws SQLException { facade.update(ObjectClass.ACCOUNT, uid, Collections.singleton(AttributeBuilder.build( OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_EXTERNAL)), null); UserRecord record = userReader.readUserRecord(uid.getUidValue()); assertNotNull(record); assertEquals(OracleAuthentication.EXTERNAL, OracleUserReader.resolveAuthentication(record)); facade.update(ObjectClass.ACCOUNT, uid, CollectionUtil.newSet( AttributeBuilder.build(OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_LOCAL), AttributeBuilder .buildPassword("password".toCharArray())), null); record = userReader.readUserRecord(uid.getUidValue()); assertNotNull(record); assertEquals(OracleAuthentication.LOCAL, OracleUserReader.resolveAuthentication(record)); }
public Uid update(ObjectClass objclass, Uid uid, Set<Attribute> attrs, OperationOptions options) { Map<String, Attribute> map = AttributeUtil.toMap(attrs); checkUpdateAttributes(map); checkUserExist(uid.getUidValue()); LOG.info("Update user : [{0}]", uid.getUidValue()); OracleUserAttributes.Builder builder = new OracleUserAttributes.Builder(); builder.setUserName(uid.getUidValue()); new OracleAttributesReader(cfg.getConnectorMessages()).readAlterAttributes(map, builder); OracleUserAttributes caAttributes = builder.build(); try { UserRecord userRecord = new OracleUserReader(adminConn, cfg.getConnectorMessages()) .readUserRecord(caAttributes.getUserName()); String alterSQL = new OracleCreateOrAlterStBuilder(cfg) .buildAlterUserSt(caAttributes, userRecord); List<String> grantRevokeSQL = new ArrayList<String>(); Attribute aRoles = AttributeUtil.find(OracleConstants.ORACLE_ROLES_ATTR_NAME, attrs); if (aRoles != null) { List<String> roles = OracleConnectorHelper.castList(aRoles, String.class); if (!roles.isEmpty()) { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); List<String> revokeRoles = new ArrayList<String>(currentRoles); revokeRoles.removeAll(roles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), revokeRoles)); roles.removeAll(currentRoles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantRoles(caAttributes.getUserName(), roles)); } else { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), currentRoles)); } } Attribute aPrivileges = AttributeUtil.find(OracleConstants.ORACLE_PRIVS_ATTR_NAME, attrs); if (aPrivileges != null) { List<String> privileges = OracleConnectorHelper.castList(aPrivileges, String.class); if (!privileges.isEmpty()) { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); List<String> revokePrivileges = new ArrayList<String>(currentPrivileges); revokePrivileges.removeAll(privileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), revokePrivileges)); privileges.removeAll(currentPrivileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantPrivileges(caAttributes.getUserName(), privileges)); } else { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), currentPrivileges)); } } if (alterSQL == null && grantRevokeSQL.isEmpty()) { } if (alterSQL != null) { SQLUtil.executeUpdateStatement(adminConn, alterSQL); } OracleSpecifics.execStatemts(adminConn, grantRevokeSQL); adminConn.commit(); LOG.info("User updated : [{0}]", uid.getUidValue()); return uid; } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); throw new ConnectorException(cfg.getConnectorMessages().format( MSG_UPDATE_OF_USER_FAILED, null, uid.getUidValue()), e); } }
OracleOperationUpdate extends AbstractOracleOperation implements UpdateOp,
        UpdateAttributeValuesOp { public Uid update(ObjectClass objclass, Uid uid, Set<Attribute> attrs, OperationOptions options) { Map<String, Attribute> map = AttributeUtil.toMap(attrs); checkUpdateAttributes(map); checkUserExist(uid.getUidValue()); LOG.info("Update user : [{0}]", uid.getUidValue()); OracleUserAttributes.Builder builder = new OracleUserAttributes.Builder(); builder.setUserName(uid.getUidValue()); new OracleAttributesReader(cfg.getConnectorMessages()).readAlterAttributes(map, builder); OracleUserAttributes caAttributes = builder.build(); try { UserRecord userRecord = new OracleUserReader(adminConn, cfg.getConnectorMessages()) .readUserRecord(caAttributes.getUserName()); String alterSQL = new OracleCreateOrAlterStBuilder(cfg) .buildAlterUserSt(caAttributes, userRecord); List<String> grantRevokeSQL = new ArrayList<String>(); Attribute aRoles = AttributeUtil.find(OracleConstants.ORACLE_ROLES_ATTR_NAME, attrs); if (aRoles != null) { List<String> roles = OracleConnectorHelper.castList(aRoles, String.class); if (!roles.isEmpty()) { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); List<String> revokeRoles = new ArrayList<String>(currentRoles); revokeRoles.removeAll(roles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), revokeRoles)); roles.removeAll(currentRoles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantRoles(caAttributes.getUserName(), roles)); } else { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), currentRoles)); } } Attribute aPrivileges = AttributeUtil.find(OracleConstants.ORACLE_PRIVS_ATTR_NAME, attrs); if (aPrivileges != null) { List<String> privileges = OracleConnectorHelper.castList(aPrivileges, String.class); if (!privileges.isEmpty()) { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); List<String> revokePrivileges = new ArrayList<String>(currentPrivileges); revokePrivileges.removeAll(privileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), revokePrivileges)); privileges.removeAll(currentPrivileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantPrivileges(caAttributes.getUserName(), privileges)); } else { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), currentPrivileges)); } } if (alterSQL == null && grantRevokeSQL.isEmpty()) { } if (alterSQL != null) { SQLUtil.executeUpdateStatement(adminConn, alterSQL); } OracleSpecifics.execStatemts(adminConn, grantRevokeSQL); adminConn.commit(); LOG.info("User updated : [{0}]", uid.getUidValue()); return uid; } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); throw new ConnectorException(cfg.getConnectorMessages().format( MSG_UPDATE_OF_USER_FAILED, null, uid.getUidValue()), e); } } }
OracleOperationUpdate extends AbstractOracleOperation implements UpdateOp,
        UpdateAttributeValuesOp { public Uid update(ObjectClass objclass, Uid uid, Set<Attribute> attrs, OperationOptions options) { Map<String, Attribute> map = AttributeUtil.toMap(attrs); checkUpdateAttributes(map); checkUserExist(uid.getUidValue()); LOG.info("Update user : [{0}]", uid.getUidValue()); OracleUserAttributes.Builder builder = new OracleUserAttributes.Builder(); builder.setUserName(uid.getUidValue()); new OracleAttributesReader(cfg.getConnectorMessages()).readAlterAttributes(map, builder); OracleUserAttributes caAttributes = builder.build(); try { UserRecord userRecord = new OracleUserReader(adminConn, cfg.getConnectorMessages()) .readUserRecord(caAttributes.getUserName()); String alterSQL = new OracleCreateOrAlterStBuilder(cfg) .buildAlterUserSt(caAttributes, userRecord); List<String> grantRevokeSQL = new ArrayList<String>(); Attribute aRoles = AttributeUtil.find(OracleConstants.ORACLE_ROLES_ATTR_NAME, attrs); if (aRoles != null) { List<String> roles = OracleConnectorHelper.castList(aRoles, String.class); if (!roles.isEmpty()) { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); List<String> revokeRoles = new ArrayList<String>(currentRoles); revokeRoles.removeAll(roles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), revokeRoles)); roles.removeAll(currentRoles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantRoles(caAttributes.getUserName(), roles)); } else { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), currentRoles)); } } Attribute aPrivileges = AttributeUtil.find(OracleConstants.ORACLE_PRIVS_ATTR_NAME, attrs); if (aPrivileges != null) { List<String> privileges = OracleConnectorHelper.castList(aPrivileges, String.class); if (!privileges.isEmpty()) { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); List<String> revokePrivileges = new ArrayList<String>(currentPrivileges); revokePrivileges.removeAll(privileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), revokePrivileges)); privileges.removeAll(currentPrivileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantPrivileges(caAttributes.getUserName(), privileges)); } else { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), currentPrivileges)); } } if (alterSQL == null && grantRevokeSQL.isEmpty()) { } if (alterSQL != null) { SQLUtil.executeUpdateStatement(adminConn, alterSQL); } OracleSpecifics.execStatemts(adminConn, grantRevokeSQL); adminConn.commit(); LOG.info("User updated : [{0}]", uid.getUidValue()); return uid; } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); throw new ConnectorException(cfg.getConnectorMessages().format( MSG_UPDATE_OF_USER_FAILED, null, uid.getUidValue()), e); } } OracleOperationUpdate(OracleConfiguration cfg, Connection adminConn); }
OracleOperationUpdate extends AbstractOracleOperation implements UpdateOp,
        UpdateAttributeValuesOp { public Uid update(ObjectClass objclass, Uid uid, Set<Attribute> attrs, OperationOptions options) { Map<String, Attribute> map = AttributeUtil.toMap(attrs); checkUpdateAttributes(map); checkUserExist(uid.getUidValue()); LOG.info("Update user : [{0}]", uid.getUidValue()); OracleUserAttributes.Builder builder = new OracleUserAttributes.Builder(); builder.setUserName(uid.getUidValue()); new OracleAttributesReader(cfg.getConnectorMessages()).readAlterAttributes(map, builder); OracleUserAttributes caAttributes = builder.build(); try { UserRecord userRecord = new OracleUserReader(adminConn, cfg.getConnectorMessages()) .readUserRecord(caAttributes.getUserName()); String alterSQL = new OracleCreateOrAlterStBuilder(cfg) .buildAlterUserSt(caAttributes, userRecord); List<String> grantRevokeSQL = new ArrayList<String>(); Attribute aRoles = AttributeUtil.find(OracleConstants.ORACLE_ROLES_ATTR_NAME, attrs); if (aRoles != null) { List<String> roles = OracleConnectorHelper.castList(aRoles, String.class); if (!roles.isEmpty()) { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); List<String> revokeRoles = new ArrayList<String>(currentRoles); revokeRoles.removeAll(roles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), revokeRoles)); roles.removeAll(currentRoles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantRoles(caAttributes.getUserName(), roles)); } else { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), currentRoles)); } } Attribute aPrivileges = AttributeUtil.find(OracleConstants.ORACLE_PRIVS_ATTR_NAME, attrs); if (aPrivileges != null) { List<String> privileges = OracleConnectorHelper.castList(aPrivileges, String.class); if (!privileges.isEmpty()) { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); List<String> revokePrivileges = new ArrayList<String>(currentPrivileges); revokePrivileges.removeAll(privileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), revokePrivileges)); privileges.removeAll(currentPrivileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantPrivileges(caAttributes.getUserName(), privileges)); } else { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), currentPrivileges)); } } if (alterSQL == null && grantRevokeSQL.isEmpty()) { } if (alterSQL != null) { SQLUtil.executeUpdateStatement(adminConn, alterSQL); } OracleSpecifics.execStatemts(adminConn, grantRevokeSQL); adminConn.commit(); LOG.info("User updated : [{0}]", uid.getUidValue()); return uid; } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); throw new ConnectorException(cfg.getConnectorMessages().format( MSG_UPDATE_OF_USER_FAILED, null, uid.getUidValue()), e); } } OracleOperationUpdate(OracleConfiguration cfg, Connection adminConn); Uid update(ObjectClass objclass, Uid uid, Set<Attribute> attrs, OperationOptions options); Uid addAttributeValues(ObjectClass objclass, Uid uid, Set<Attribute> valuesToAdd,
            OperationOptions options); Uid removeAttributeValues(ObjectClass objclass, Uid uid, Set<Attribute> valuesToRemove,
            OperationOptions options); }
OracleOperationUpdate extends AbstractOracleOperation implements UpdateOp,
        UpdateAttributeValuesOp { public Uid update(ObjectClass objclass, Uid uid, Set<Attribute> attrs, OperationOptions options) { Map<String, Attribute> map = AttributeUtil.toMap(attrs); checkUpdateAttributes(map); checkUserExist(uid.getUidValue()); LOG.info("Update user : [{0}]", uid.getUidValue()); OracleUserAttributes.Builder builder = new OracleUserAttributes.Builder(); builder.setUserName(uid.getUidValue()); new OracleAttributesReader(cfg.getConnectorMessages()).readAlterAttributes(map, builder); OracleUserAttributes caAttributes = builder.build(); try { UserRecord userRecord = new OracleUserReader(adminConn, cfg.getConnectorMessages()) .readUserRecord(caAttributes.getUserName()); String alterSQL = new OracleCreateOrAlterStBuilder(cfg) .buildAlterUserSt(caAttributes, userRecord); List<String> grantRevokeSQL = new ArrayList<String>(); Attribute aRoles = AttributeUtil.find(OracleConstants.ORACLE_ROLES_ATTR_NAME, attrs); if (aRoles != null) { List<String> roles = OracleConnectorHelper.castList(aRoles, String.class); if (!roles.isEmpty()) { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); List<String> revokeRoles = new ArrayList<String>(currentRoles); revokeRoles.removeAll(roles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), revokeRoles)); roles.removeAll(currentRoles); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantRoles(caAttributes.getUserName(), roles)); } else { List<String> currentRoles = new OracleRolePrivReader(adminConn).readRoles(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokeRoles(caAttributes.getUserName(), currentRoles)); } } Attribute aPrivileges = AttributeUtil.find(OracleConstants.ORACLE_PRIVS_ATTR_NAME, attrs); if (aPrivileges != null) { List<String> privileges = OracleConnectorHelper.castList(aPrivileges, String.class); if (!privileges.isEmpty()) { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); List<String> revokePrivileges = new ArrayList<String>(currentPrivileges); revokePrivileges.removeAll(privileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), revokePrivileges)); privileges.removeAll(currentPrivileges); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildGrantPrivileges(caAttributes.getUserName(), privileges)); } else { List<String> currentPrivileges = new OracleRolePrivReader(adminConn).readAllPrivileges(caAttributes .getUserName()); grantRevokeSQL.addAll(new OracleRolesAndPrivsBuilder(cfg.getCSSetup()) .buildRevokePrivileges(caAttributes.getUserName(), currentPrivileges)); } } if (alterSQL == null && grantRevokeSQL.isEmpty()) { } if (alterSQL != null) { SQLUtil.executeUpdateStatement(adminConn, alterSQL); } OracleSpecifics.execStatemts(adminConn, grantRevokeSQL); adminConn.commit(); LOG.info("User updated : [{0}]", uid.getUidValue()); return uid; } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); throw new ConnectorException(cfg.getConnectorMessages().format( MSG_UPDATE_OF_USER_FAILED, null, uid.getUidValue()), e); } } OracleOperationUpdate(OracleConfiguration cfg, Connection adminConn); Uid update(ObjectClass objclass, Uid uid, Set<Attribute> attrs, OperationOptions options); Uid addAttributeValues(ObjectClass objclass, Uid uid, Set<Attribute> valuesToAdd,
            OperationOptions options); Uid removeAttributeValues(ObjectClass objclass, Uid uid, Set<Attribute> valuesToRemove,
            OperationOptions options);  }