Skip to content

Commit

Permalink
Fix serialization error at authentication context cloning.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Feb 9, 2025
1 parent 5e1dcbe commit 0a6345c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator;
import org.wso2.carbon.identity.application.authentication.framework.AuthenticatorStateInfo;
import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.IdentityProvider;
import org.wso2.carbon.identity.application.common.model.UserDefinedFederatedAuthenticatorConfig;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down Expand Up @@ -127,6 +129,21 @@ public Map<String, IdentityProvider> getIdps() {

public void setIdPs(Map<String, IdentityProvider> idPs) {


if (idPs != null) {
/* Remove non-serializable UserDefinedAuthenticatorEndpointConfig objects from the
UserDefinedFederatedAuthenticatorConfig in the context. The UserDefinedAuthenticatorEndpointConfig contains
the endpoint URI and the authentication type of the corresponding action. However, this information is not
used in the authentication flow. Instead, the action ID in the authenticator property is used to resolve
the corresponding action. */
for (IdentityProvider idp : idPs.values()) {
for (FederatedAuthenticatorConfig authConfig : idp.getFederatedAuthenticatorConfigs()) {
if (authConfig instanceof UserDefinedFederatedAuthenticatorConfig) {
((UserDefinedFederatedAuthenticatorConfig) authConfig).setEndpointConfig(null);
}
}
}
}
this.idps = idPs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.SerializationUtils;
import org.wso2.carbon.identity.application.authentication.framework.AuthenticatorStateInfo;
import org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig;
import org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedIdPData;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationRequest;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.IdentityProvider;
import org.wso2.carbon.identity.application.common.model.UserDefinedFederatedAuthenticatorConfig;
import org.wso2.carbon.identity.base.IdentityRuntimeException;
import org.wso2.carbon.identity.core.bean.context.MessageContext;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
Expand Down Expand Up @@ -860,43 +855,6 @@ public void setExpiryTime(long expiryTimeNano) {
*/
public Object clone () {

removeNonSerializableObjects();
return SerializationUtils.clone(this);
}

private void removeNonSerializableObjects() {

/* Remove non-serializable UserDefinedAuthenticatorEndpointConfig objects from the
UserDefinedFederatedAuthenticatorConfig in the context. The UserDefinedAuthenticatorEndpointConfig contains
the endpoint URI and the authentication type of the corresponding action. However, this information is not
used in the authentication flow. Instead, the action ID in the authenticator property is used to resolve the
corresponding action. */
if (sequenceConfig == null || sequenceConfig.getStepMap() == null) {
return;
}

for (StepConfig stepConfig : sequenceConfig.getStepMap().values()) {
if (stepConfig == null || stepConfig.getAuthenticatorList() == null) {
continue;
}

for (AuthenticatorConfig authenticatorConfig : stepConfig.getAuthenticatorList()) {
if (stepConfig.getAuthenticatorList() == null) {
continue;
}

for (IdentityProvider idp : authenticatorConfig.getIdps().values()) {
if (idp == null || idp.getFederatedAuthenticatorConfigs() == null) {
continue;
}

for (FederatedAuthenticatorConfig authConfig : idp.getFederatedAuthenticatorConfigs()) {
if (authConfig instanceof UserDefinedFederatedAuthenticatorConfig) {
((UserDefinedFederatedAuthenticatorConfig) authConfig).setEndpointConfig(null);
}
}
}
}
}
}
}

0 comments on commit 0a6345c

Please sign in to comment.