<%

var log = new Log();

var util = require("../../util/utility.jag");
var serverUrl = util.getServerUrl() + "/UserProfileMgtService";
var userProfileMgtStub = Packages.org.wso2.carbon.identity.user.profile.stub.UserProfileMgtServiceStub;
var HTTPConstants = Packages.org.apache.axis2.transport.http.HTTPConstants;


function associateID(idPId, username) {
    try {
        var serviceStub = new userProfileMgtStub(serverUrl);
        var serviceClient = serviceStub._getServiceClient();
        var option = serviceClient.getOptions();
        option.setManageSession(true);
        var cookie = session.get("auth-cookie");
        option.setProperty(HTTPConstants.COOKIE_STRING, cookie);
        serviceStub.associateID(idPId, username);
    } catch (e) {
        throw e;
    }
}

function getAssociatedIDs() {
    try {
        var serviceStub = new userProfileMgtStub(serverUrl);
        var serviceClient = serviceStub._getServiceClient();
        var option = serviceClient.getOptions();
        option.setManageSession(true);
        var cookie = session.get("auth-cookie");
        option.setProperty(HTTPConstants.COOKIE_STRING, cookie);
        return serviceStub.getAssociatedIDs();
    } catch (e) {
        throw e;
    }
}

function removeAssociateID(idPId, username) {
    try {
        var serviceStub = new userProfileMgtStub(serverUrl);
        var serviceClient = serviceStub._getServiceClient();
        var option = serviceClient.getOptions();
        option.setManageSession(true);
        var cookie = session.get("auth-cookie");
        option.setProperty(HTTPConstants.COOKIE_STRING, cookie);
        serviceStub.removeAssociateID(idPId, username);
    } catch (e) {
        throw e;
    }
}

%>