如何使用cognos SDK更新Cognos Data Source的密码?

时间:2016-02-09 17:54:09

标签: cognos

我如何在How do I update the password for a Cognos Data Source?中执行相同的操作,但是以编程方式使用Cognos SDK v10.2?

2 个答案:

答案 0 :(得分:0)

我从未发现如何只更新密码,但我可以重新创建包含我的密码的DataSourceSignon,这足以满足我的需求。请注意,可能会重置DataSourceSignon中的其他内容。

他们展示了如何在http://www-01.ibm.com/support/docview.wss?uid=swg21370529

中创建这些DataSourceSignon

要重新创建DataSourceSignon,您可以再次创建它,它将覆盖第一个。

答案 1 :(得分:0)

这是我解决此问题的方法。 this.getCMService()在哪里返回 ContentManagerService_PortType

的对象
public boolean updateSignOn(final String dataSourceName, final String connectionName,
        final String signOnName, final String user, final String password) {

    final String connectionSearchPath = "CAMID(\":\")/dataSource[@name='" + dataSourceName
            + "']/dataSourceConnection[@name='" + connectionName + "']";
    final PropEnum props[] = {PropEnum.defaultName, PropEnum.user, PropEnum.credentials,
            PropEnum.searchPath, PropEnum.version, PropEnum.consumers};

    try {
        // Create a new signon
        final DataSourceSignon newdsSignon = new DataSourceSignon();
        final BaseClassArrayProp cons = new BaseClassArrayProp();
        final BaseClass[] oConsumers = new BaseClass[1];
        final Nil c1 = new Nil();
        final StringProp sp = new StringProp();
        // If you want a specific user/group to have access to the signon,
        // change the search path to that user/group search path
        sp.setValue("CAMID(\"::Everyone\")");
        c1.setSearchPath(sp);
        oConsumers[0] = c1;
        cons.setValue(oConsumers);
        // Set everyone to have access to the signon
        newdsSignon.setConsumers(cons);

        // Add credentials to the signon
        final AnyTypeProp credentials = new AnyTypeProp();
        final String credString = "<credential><username>" + user + "</username><password>"
                + password + "</password></credential>";
        credentials.setValue(credString);
        // Replace previous 3 lines with the next commented line,
        // if you want to use the same credentials as another existing signon
        // credentials.setValue(dts);
        newdsSignon.setCredentials(credentials);

        final TokenProp tp = new TokenProp();
        tp.setValue(signOnName);
        newdsSignon.setDefaultName(tp);

        final SearchPathMultipleObject dsConnSearchPobj = new SearchPathMultipleObject(
                connectionSearchPath);

        final BaseClass bc[] = this.getCMService().query(dsConnSearchPobj, props, new Sort[] {},
                new QueryOptions());
        final BaseClassArrayProp bcap = new BaseClassArrayProp();
        bcap.setValue(bc);
        newdsSignon.setParent(bcap);

        final AddOptions ao = new AddOptions();
        ao.setUpdateAction(UpdateActionEnum.replace);

        final SearchPathSingleObject newObject = new SearchPathSingleObject();
        newObject.set_value((bc[0]).getSearchPath().getValue());

        this.getCMService().add(newObject, new BaseClass[] {newdsSignon}, ao);
        System.out.println("DataSource: " + dataSourceName + "\nConnection: " + connectionName
                + "\nSignOn: " + signOnName + " was updated");
    } catch (final Exception e) {
        System.out.println(e);
        return false;
    }

    return true;
}