@Test public void testCreate() { String username = getTestRequiredProperty("testUser"); Map<String, Object> emptyMap = Collections.emptyMap(); Set<Attribute> attributes = new HashSet<Attribute>(); attributes.add(new Name(username)); attributes .add(AttributeBuilder.build(DB2Connector.USER_AUTH_GRANTS, "CONNECT ON DATABASE")); Uid uid = null; try { uid = facade.create(ObjectClass.ACCOUNT, attributes, new OperationOptions(emptyMap)); assertNotNull(uid); } catch (AlreadyExistsException e) { facade.delete(ObjectClass.ACCOUNT, new Uid(username), new OperationOptions(emptyMap)); uid = facade.create(ObjectClass.ACCOUNT, attributes, new OperationOptions(emptyMap)); assertNotNull(uid); } uid = findUser(username); assertNotNull("Cannot find new created user", uid); }
public Uid create(ObjectClass oclass, Set<Attribute> attrs, OperationOptions options) { checkObjectClass(oclass); checkCreateAttributes(attrs); Name user = AttributeUtil.getNameFromAttributes(attrs); if (user == null || StringUtil.isBlank(user.getNameValue())) { throw new IllegalArgumentException(cfg.getConnectorMessages().format( DB2Messages.NAME_IS_NULL_OR_EMPTY, null)); } final String userName = user.getNameValue(); LOG.info("Creating user : {0}", userName); checkUserNotExist(userName); checkDB2Validity(userName); try { updateAuthority(userName, attrs, UpdateType.ADD); adminConn.commit(); LOG.info("User created : {0}", userName); } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); String detailMsg = new SQLMsgRetriever().retrieveMsg(e); throw new ConnectorException(cfg.getConnectorMessages().format( DB2Messages.CREATE_OF_USER_FAILED, null, userName, detailMsg), e); } return new Uid(userName); }
DB2Connector implements AuthenticateOp, SchemaOp, CreateOp,
        SearchOp<FilterWhereBuilder>, DeleteOp, UpdateAttributeValuesOp, TestOp, PoolableConnector,
        AttributeNormalizer { public Uid create(ObjectClass oclass, Set<Attribute> attrs, OperationOptions options) { checkObjectClass(oclass); checkCreateAttributes(attrs); Name user = AttributeUtil.getNameFromAttributes(attrs); if (user == null || StringUtil.isBlank(user.getNameValue())) { throw new IllegalArgumentException(cfg.getConnectorMessages().format( DB2Messages.NAME_IS_NULL_OR_EMPTY, null)); } final String userName = user.getNameValue(); LOG.info("Creating user : {0}", userName); checkUserNotExist(userName); checkDB2Validity(userName); try { updateAuthority(userName, attrs, UpdateType.ADD); adminConn.commit(); LOG.info("User created : {0}", userName); } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); String detailMsg = new SQLMsgRetriever().retrieveMsg(e); throw new ConnectorException(cfg.getConnectorMessages().format( DB2Messages.CREATE_OF_USER_FAILED, null, userName, detailMsg), e); } return new Uid(userName); } }
DB2Connector implements AuthenticateOp, SchemaOp, CreateOp,
        SearchOp<FilterWhereBuilder>, DeleteOp, UpdateAttributeValuesOp, TestOp, PoolableConnector,
        AttributeNormalizer { public Uid create(ObjectClass oclass, Set<Attribute> attrs, OperationOptions options) { checkObjectClass(oclass); checkCreateAttributes(attrs); Name user = AttributeUtil.getNameFromAttributes(attrs); if (user == null || StringUtil.isBlank(user.getNameValue())) { throw new IllegalArgumentException(cfg.getConnectorMessages().format( DB2Messages.NAME_IS_NULL_OR_EMPTY, null)); } final String userName = user.getNameValue(); LOG.info("Creating user : {0}", userName); checkUserNotExist(userName); checkDB2Validity(userName); try { updateAuthority(userName, attrs, UpdateType.ADD); adminConn.commit(); LOG.info("User created : {0}", userName); } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); String detailMsg = new SQLMsgRetriever().retrieveMsg(e); throw new ConnectorException(cfg.getConnectorMessages().format( DB2Messages.CREATE_OF_USER_FAILED, null, userName, detailMsg), e); } return new Uid(userName); } DB2Connector(); }
DB2Connector implements AuthenticateOp, SchemaOp, CreateOp,
        SearchOp<FilterWhereBuilder>, DeleteOp, UpdateAttributeValuesOp, TestOp, PoolableConnector,
        AttributeNormalizer { public Uid create(ObjectClass oclass, Set<Attribute> attrs, OperationOptions options) { checkObjectClass(oclass); checkCreateAttributes(attrs); Name user = AttributeUtil.getNameFromAttributes(attrs); if (user == null || StringUtil.isBlank(user.getNameValue())) { throw new IllegalArgumentException(cfg.getConnectorMessages().format( DB2Messages.NAME_IS_NULL_OR_EMPTY, null)); } final String userName = user.getNameValue(); LOG.info("Creating user : {0}", userName); checkUserNotExist(userName); checkDB2Validity(userName); try { updateAuthority(userName, attrs, UpdateType.ADD); adminConn.commit(); LOG.info("User created : {0}", userName); } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); String detailMsg = new SQLMsgRetriever().retrieveMsg(e); throw new ConnectorException(cfg.getConnectorMessages().format( DB2Messages.CREATE_OF_USER_FAILED, null, userName, detailMsg), e); } return new Uid(userName); } DB2Connector(); Uid authenticate(ObjectClass objectClass, String username, GuardedString password,
            OperationOptions options); Schema schema(); void checkAlive(); void dispose(); DB2Configuration getConfiguration(); void init(Configuration cfg); FilterTranslator<FilterWhereBuilder> createFilterTranslator(ObjectClass oclass,
            OperationOptions options); void executeQuery(ObjectClass oclass, FilterWhereBuilder where, ResultsHandler handler,
            OperationOptions options); Uid create(ObjectClass oclass, Set<Attribute> attrs, OperationOptions options); void delete(ObjectClass objClass, Uid uid, OperationOptions options); void test(); 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); Attribute normalizeAttribute(ObjectClass oclass, Attribute attribute); }
DB2Connector implements AuthenticateOp, SchemaOp, CreateOp,
        SearchOp<FilterWhereBuilder>, DeleteOp, UpdateAttributeValuesOp, TestOp, PoolableConnector,
        AttributeNormalizer { public Uid create(ObjectClass oclass, Set<Attribute> attrs, OperationOptions options) { checkObjectClass(oclass); checkCreateAttributes(attrs); Name user = AttributeUtil.getNameFromAttributes(attrs); if (user == null || StringUtil.isBlank(user.getNameValue())) { throw new IllegalArgumentException(cfg.getConnectorMessages().format( DB2Messages.NAME_IS_NULL_OR_EMPTY, null)); } final String userName = user.getNameValue(); LOG.info("Creating user : {0}", userName); checkUserNotExist(userName); checkDB2Validity(userName); try { updateAuthority(userName, attrs, UpdateType.ADD); adminConn.commit(); LOG.info("User created : {0}", userName); } catch (Exception e) { SQLUtil.rollbackQuietly(adminConn); String detailMsg = new SQLMsgRetriever().retrieveMsg(e); throw new ConnectorException(cfg.getConnectorMessages().format( DB2Messages.CREATE_OF_USER_FAILED, null, userName, detailMsg), e); } return new Uid(userName); } DB2Connector(); Uid authenticate(ObjectClass objectClass, String username, GuardedString password,
            OperationOptions options); Schema schema(); void checkAlive(); void dispose(); DB2Configuration getConfiguration(); void init(Configuration cfg); FilterTranslator<FilterWhereBuilder> createFilterTranslator(ObjectClass oclass,
            OperationOptions options); void executeQuery(ObjectClass oclass, FilterWhereBuilder where, ResultsHandler handler,
            OperationOptions options); Uid create(ObjectClass oclass, Set<Attribute> attrs, OperationOptions options); void delete(ObjectClass objClass, Uid uid, OperationOptions options); void test(); 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); Attribute normalizeAttribute(ObjectClass oclass, Attribute attribute);  }