Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the authenticator on service modifications #173

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException;
import org.wso2.carbon.identity.application.authentication.framework.exception.LogoutFailedException;
import org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException;
import org.wso2.carbon.identity.application.authentication.framework.model.AdditionalData;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatorData;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatorParamMetadata;
Expand Down Expand Up @@ -83,6 +82,7 @@
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.LogConstants.ActionIDs.PROCESS_AUTHENTICATION_RESPONSE;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.LogConstants.ActionIDs.INITIATE_TOTP_REQUEST;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.LogConstants.TOTP_AUTH_SERVICE;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.TOKEN;
import static org.wso2.carbon.identity.application.authenticator.totp.util.TOTPUtil.getMultiOptionURIQueryParam;
import static org.wso2.carbon.identity.application.authenticator.totp.util.TOTPUtil.getTOTPErrorPage;
import static org.wso2.carbon.identity.application.authenticator.totp.util.TOTPUtil.getTOTPLoginPage;
Expand Down Expand Up @@ -735,17 +735,19 @@ public Optional<AuthenticatorData> getAuthInitiationData(AuthenticationContext c
authenticatorData.setDisplayName(getFriendlyName());
String idpName = context.getExternalIdP().getIdPName();
authenticatorData.setIdp(idpName);

AdditionalData additionalData = new AdditionalData();
additionalData.setPromptType(TOTPAuthenticatorConstants.USER_PROMPT);
authenticatorData.setAdditionalData(additionalData);
authenticatorData.setPromptType(FrameworkConstants.AuthenticatorPromptType.USER_PROMPT);

List<AuthenticatorParamMetadata> authenticatorParamMetadataList = new ArrayList<>();
AuthenticatorParamMetadata tokenMetadata = new AuthenticatorParamMetadata(
TOTPAuthenticatorConstants.TOKEN, FrameworkConstants.AuthenticatorParamType.STRING, 0);
TOTPAuthenticatorConstants.TOKEN, FrameworkConstants.AuthenticatorParamType.STRING,
0, Boolean.FALSE, TOTPAuthenticatorConstants.TOTP_AUTHENTICATOR);
authenticatorParamMetadataList.add(tokenMetadata);
authenticatorData.setAuthParams(authenticatorParamMetadataList);

List<String> requiredParams = new ArrayList<>();
requiredParams.add(TOKEN);
authenticatorData.setRequiredParams(requiredParams);

return Optional.of(authenticatorData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/
public abstract class TOTPAuthenticatorConstants {

public static final String TOTP_AUTHENTICATOR = "totp.authenticator";

/*
* Private Constructor will prevent the instantiation of this class directly.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,14 +763,15 @@ public void testGetAuthInitiationData() {

List<AuthenticatorParamMetadata> authenticatorParamMetadataList = new ArrayList<>();
AuthenticatorParamMetadata tokenMetadata = new AuthenticatorParamMetadata(
TOTPAuthenticatorConstants.TOKEN, FrameworkConstants.AuthenticatorParamType.STRING, 0);
TOTPAuthenticatorConstants.TOKEN, FrameworkConstants.AuthenticatorParamType.STRING,
0, Boolean.FALSE, TOTPAuthenticatorConstants.TOTP_AUTHENTICATOR);
authenticatorParamMetadataList.add(tokenMetadata);

Assert.assertEquals(authenticatorDataObj.getName(), TOTPAuthenticatorConstants.AUTHENTICATOR_NAME);
Assert.assertEquals(authenticatorDataObj.getAuthParams().size(), authenticatorParamMetadataList.size(),
"Size of lists should be equal.");
Assert.assertEquals(authenticatorDataObj.getAdditionalDataObj().getPromptType(), TOTPAuthenticatorConstants.
USER_PROMPT, "Prompt Type should match.");
Assert.assertEquals(authenticatorDataObj.getPromptType(), FrameworkConstants.AuthenticatorPromptType.
USER_PROMPT, "Prompt Type should match.");
for (int i = 0; i < authenticatorParamMetadataList.size(); i++) {
AuthenticatorParamMetadata expectedParam = authenticatorParamMetadataList.get(i);
AuthenticatorParamMetadata actualParam = authenticatorDataObj.getAuthParams().get(i);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<carbon.commons.version>4.8.7</carbon.commons.version>
<carbon.commons.imp.pkg.version>[4.4.0, 5.0.0)</carbon.commons.imp.pkg.version>
<!--Carbon identity version-->
<carbon.identity.framework.version>5.25.394</carbon.identity.framework.version>
<carbon.identity.framework.version>5.25.428</carbon.identity.framework.version>

<org.wso2.carbon.identity.organization.management.core.version>1.0.0
</org.wso2.carbon.identity.organization.management.core.version>
Expand Down
Loading