WSO2 Identity Server 5.1.0 - 从IdentityProviderMgtService更新驻留IDP

时间:2016-05-20 03:45:36

标签: wso2 wso2is

我正在使用IdentityProviderMgtServiceStub.updateResidentIdp()来更新会话超时。这是我的代码。

IdentityProviderMgtServiceStub stub = new IdentityProviderMgtServiceStub("https://localhost:9443/services/IdentityProviderMgtService");
IdentityProvider idp = stub.getResidentIdP();
IdentityProviderProperty [] properties = idp.getIdpProperties();
for(IdentityProviderProperty property: properties){
    if(property.getName().equals(SESSION_IDLE_TIMEOUT) && sessionTimeOut!= 0L) {
        property.setValue(String.valueOf(sessionTimeOut));
    }else if(property.getName().equals(REMEMBER_ME_TIMEOUT) && rememberMeTimeOut!= 0L){
        property.setValue(String.valueOf(rememberMeTimeOut));
    }       
}
idp.setIdpProperties(properties);
stub.updateResidentIdP(idp);

然而,这引发了一个例外:

org.wso2.carbon.idp.mgt.IdentityProviderManagementException: Cannot find authenticator : openidconnect
at org.wso2.carbon.idp.mgt.dao.IdPManagementDAO.getAuthenticatorIdentifier(IdPManagementDAO.java:2571)
at org.wso2.carbon.idp.mgt.dao.IdPManagementDAO.updateFederatedAuthenticatorConfig(IdPManagementDAO.java:385)
at org.wso2.carbon.idp.mgt.dao.IdPManagementDAO.updateFederatedAuthenticatorConfigs(IdPManagementDAO.java:348)
at org.wso2.carbon.idp.mgt.dao.IdPManagementDAO.updateIdP(IdPManagementDAO.java:1716)
at org.wso2.carbon.idp.mgt.dao.CacheBackedIdPMgtDAO.updateIdP(CacheBackedIdPMgtDAO.java:297)
at org.wso2.carbon.idp.mgt.IdentityProviderManager.updateResidentIdP(IdentityProviderManager.java:636)
at org.wso2.carbon.idp.mgt.IdentityProviderManagementService.updateResidentIdP(IdentityProviderManagementService.java:74)

如果我手动拨打idp.setFederatedAuthenticatorConfigs(null);,此例外就会消失。但这没有意义,因为我不需要触摸任何我没有更新的区域。我的问题是

(1)在我的用例中调用idp.setFederatedAuthenticatorConfigs(null);是否安全?

(2)这是WSO2中的错误吗?

1 个答案:

答案 0 :(得分:1)

请使用以下代码更新常驻身份提供商。不要直接使用取自" stub.getResidentIdP()"的值。因为有一些不必要的值不需要发送。

        IdentityProvider identityProvider = new IdentityProvider();

        identityProvider.setEnable(true);
        identityProvider.setPrimary(true);
        identityProvider.setIdentityProviderName("LOCAL");
        identityProvider.setHomeRealmId("localhost");

        IdentityProviderProperty propertySessionIdelTimeout = new IdentityProviderProperty();
        propertySessionIdelTimeout.setName(SESSION_IDLE_TIMEOUT);
        propertySessionIdelTimeout.setValue(sessionTimeOut);

        IdentityProviderProperty propertyRememberMeTimeout = new IdentityProviderProperty();
        propertyRememberMeTimeout.setName(REMEMBER_ME_TIMEOUT);
        propertyRememberMeTimeout.setValue(rememberMeTimeOut);

        IdentityProviderProperty[] idpProperties = new IdentityProviderProperty[2];
        idpProperties[0] = propertySessionIdelTimeout;
        idpProperties[1] = propertyRememberMeTimeout;

        identityProvider.setIdpProperties(idpProperties);

        stub.updateResidentIdP(identityProvider);

对于HomeRealmId,如果需要,您可以从stub.getResidentIdP()的结果中检索值