简体   繁体   中英

How do I update the password for a Cognos Data Source with the cognos SDK?

How do I do the same thing as in How do I update the password for a Cognos Data Source? , but programmatically using the Cognos SDK v10.2?

I never found how to update just the password, but I could recreate the DataSourceSignon which contained my password, and that was enough for my needs. Just be warned that is may reset other things in the DataSourceSignon.

They show how to create these DataSourceSignon in http://www-01.ibm.com/support/docview.wss?uid=swg21370529

To recreate the DataSourceSignon, you can just create it a second time and it will overwrite the first one.

Here is how I resolved this issue. Where is this.getCMService() returns the object of 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM