Skip to content

Commit

Permalink
Merge pull request #44 from DMHP/api
Browse files Browse the repository at this point in the history
set message in authenticatorData
  • Loading branch information
DMHP authored Nov 17, 2023
2 parents ef0b9fb + e830954 commit c2bdcea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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.AuthenticatorMessage;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatorParamMetadata;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
Expand Down Expand Up @@ -89,6 +90,8 @@ public class MagicLinkAuthenticator extends AbstractApplicationAuthenticator imp
private static final Log log = LogFactory.getLog(MagicLinkAuthenticator.class);
private static final String REDIRECT_URL = "REDIRECT_URL";
private static final String IS_API_BASED = "IS_API_BASED";
private static final String AUTHENTICATOR_MESSAGE = "authenticatorMessage";
private static final String EMAIL_SENDING_FAILED = "emailSendingFailed";
private AuthenticationContext authenticationContext;

/**
Expand Down Expand Up @@ -405,6 +408,10 @@ protected void triggerEvent(User user, AuthenticationContext context, String mag
String errorMsg = String.format(
"Email notification sending failed for the user: %s in the tenant: %s", user.getUsername(),
user.getTenantDomain());
AuthenticatorMessage authenticatorMessage = new AuthenticatorMessage(FrameworkConstants.
AuthenticatorMessageType.ERROR, EMAIL_SENDING_FAILED, errorMsg, null);
context.setProperty(AUTHENTICATOR_MESSAGE, authenticatorMessage);

log.error(errorMsg);
if (LoggerUtils.isDiagnosticLogsEnabled() && diagnosticLogBuilder != null) {
diagnosticLogBuilder.resultMessage("Failed to send magic link notification.")
Expand Down Expand Up @@ -476,11 +483,15 @@ private List<String> getBlockedUserStoreDomainsList() {
return blockedUserStoreDomainsList;
}

private String validateIdentifierFromRequest(HttpServletRequest request)
private String validateIdentifierFromRequest(HttpServletRequest request, AuthenticationContext context)
throws AuthenticationFailedException {

String identifierFromRequest = request.getParameter(USER_NAME);
if (StringUtils.isBlank(identifierFromRequest)) {
AuthenticatorMessage authenticatorMessage = new AuthenticatorMessage(FrameworkConstants.
AuthenticatorMessageType.ERROR, MagicLinkAuthErrorConstants.ErrorMessages.EMPTY_USERNAME.getCode(),
MagicLinkAuthErrorConstants.ErrorMessages.EMPTY_USERNAME.getCode(), null);
context.setProperty(AUTHENTICATOR_MESSAGE, authenticatorMessage);
throw new InvalidCredentialsException(MagicLinkAuthErrorConstants.ErrorMessages.EMPTY_USERNAME.getCode(),
MagicLinkAuthErrorConstants.ErrorMessages.EMPTY_USERNAME.getMessage());
}
Expand All @@ -498,7 +509,7 @@ private String validateIdentifierFromRequest(HttpServletRequest request)
private User resolveUser(HttpServletRequest request, AuthenticationContext context)
throws AuthenticationFailedException {

String username = validateIdentifierFromRequest(request);
String username = validateIdentifierFromRequest(request, context);
validateEmailUsername(username, context);
username = FrameworkUtils.preprocessUsername(username, context);
User user = new User();
Expand Down Expand Up @@ -633,7 +644,9 @@ public Optional<AuthenticatorData> getAuthInitiationData(AuthenticationContext c
authenticatorData.setIdp(idpName);
authenticatorData.setDisplayName(getFriendlyName());
authenticatorData.setPromptType(FrameworkConstants.AuthenticatorPromptType.USER_PROMPT);

if (context.getProperty(AUTHENTICATOR_MESSAGE) != null) {
authenticatorData.setMessage((AuthenticatorMessage) context.getProperty(AUTHENTICATOR_MESSAGE));
}
if (isIdfInitiatedFromMagicLink()) {
List<String> requiredParams = new ArrayList<>();
requiredParams.add(USER_NAME);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<identity.application.authenticator.magiclink.exp.pkg.version>${project.version}
</identity.application.authenticator.magiclink.exp.pkg.version>
<carbon.kernel.version>4.9.10</carbon.kernel.version>
<carbon.identity.framework.version>5.25.491</carbon.identity.framework.version>
<carbon.identity.framework.version>5.25.509</carbon.identity.framework.version>
<apache.felix.scr.ds.annotations.version>1.2.10</apache.felix.scr.ds.annotations.version>
<identity.event.handler.notification.version>1.3.14</identity.event.handler.notification.version>
<identity.inbound.auth.oauth.version>6.11.172</identity.inbound.auth.oauth.version>
Expand Down

0 comments on commit c2bdcea

Please sign in to comment.