Skip to content

Commit

Permalink
Handle invalid configurations for resident idp.
Browse files Browse the repository at this point in the history
  • Loading branch information
RushanNanayakkara committed Jun 14, 2024
1 parent ffc0bb1 commit c321e99
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.governance;
Expand All @@ -27,9 +29,12 @@
import org.wso2.carbon.identity.event.IdentityEventConstants;
import org.wso2.carbon.identity.governance.bean.ConnectorConfig;
import org.wso2.carbon.identity.governance.common.IdentityConnectorConfig;
import org.wso2.carbon.identity.governance.exceptions.general.IdentityGovernanceClientException;
import org.wso2.carbon.identity.governance.internal.IdentityMgtServiceDataHolder;
import org.wso2.carbon.idp.mgt.IdentityProviderManagementClientException;
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
import org.wso2.carbon.idp.mgt.IdpManager;
import org.wso2.carbon.idp.mgt.util.IdPManagementUtil;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -60,6 +65,7 @@ public void updateConfiguration(String tenantDomain, Map<String, String> configu
IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties();
List<IdentityProviderProperty> newProperties = new ArrayList<>();
updateEmailOTPNumericPropertyValue(configurationDetails);
IdPManagementUtil.validatePasswordRecoveryPropertyValues(configurationDetails);
updatePasswordRecoveryPropertyValues(configurationDetails, identityMgtProperties);
for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) {
IdentityProviderProperty prop = new IdentityProviderProperty();
Expand Down Expand Up @@ -93,10 +99,12 @@ public void updateConfiguration(String tenantDomain, Map<String, String> configu
residentIdp.setFederatedAuthenticatorConfigs(configsToSave.toArray(new
FederatedAuthenticatorConfig[configsToSave.size()]));
identityProviderManager.updateResidentIdP(residentIdp, tenantDomain);
} catch (IdentityProviderManagementClientException e) {
log.debug("Client error while updating identityManagement Properties of Resident Idp.", e);
throw new IdentityGovernanceClientException(e.getMessage(), e);
} catch (IdentityProviderManagementException e) {
log.error("Error while updating identityManagement Properties of Resident Idp.", e);
}

}

@Override
Expand Down Expand Up @@ -328,6 +336,12 @@ private boolean isEmailOTPConnector(String connectorName, ConnectorConfig connec
return EMAIL_OTP_AUTHENTICATOR.equals(connectorName);
}

/**
* This method updates the password recovery property values based on the new configurations.
*
* @param configurationDetails Updating configuration details of the resident identity provider.
* @param identityMgtProperties Identity management properties of the resident identity provider.
*/
private void updatePasswordRecoveryPropertyValues(Map<String, String> configurationDetails,
IdentityProviderProperty[] identityMgtProperties) {

Expand All @@ -344,10 +358,10 @@ private void updatePasswordRecoveryPropertyValues(Map<String, String> configurat
if (recoveryNotificationPasswordProperty) {
configurationDetails.put(EMAIL_LINK_PASSWORD_RECOVERY_PROPERTY,
String.valueOf(emailLinkPasswordRecoveryProperty ||
StringUtils.isBlank(emailLinkPwRecProp)));
StringUtils.isBlank(emailLinkPwRecProp)));
configurationDetails.put(SMS_OTP_PASSWORD_RECOVERY_PROPERTY,
String.valueOf(smsOtpPasswordRecoveryProperty ||
StringUtils.isBlank(smsOtpPwRecProp)));
StringUtils.isBlank(smsOtpPwRecProp)));
} else if (StringUtils.isBlank(recNotPwProp)) {
// Connector is not explicitly enabled or disabled. The connector state is derived from new and existing
// configurations.
Expand Down Expand Up @@ -379,5 +393,4 @@ private void updatePasswordRecoveryPropertyValues(Map<String, String> configurat
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.governance.exceptions.general;

import org.wso2.carbon.identity.governance.IdentityGovernanceException;

/**
* Exception class for identity governance client exceptions.
*/
public class IdentityGovernanceClientException extends IdentityGovernanceException {

/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message the detail message.
* @param cause the cause.
*/
public IdentityGovernanceClientException(String message, Throwable cause) {
super(message, cause);
}
}

0 comments on commit c321e99

Please sign in to comment.