116 RealmModel realm = session.getContext().getRealm();
117 UriInfo uriInfo = session.getContext().getUri();
118 AuthenticationSessionModel authSession = context.getAuthenticationSession();
120 int validityInSecs = realm.getActionTokenGeneratedByUserLifespan(IdpVerifyAccountLinkActionToken.TOKEN_TYPE);
121 int absoluteExpirationInSecs = Time.currentTime() + validityInSecs;
123 EventBuilder
event = context.getEvent().clone().event(EventType.SEND_IDENTITY_PROVIDER_LINK)
125 .detail(Details.USERNAME, existingUser.getUsername())
126 .detail(Details.EMAIL, existingUser.getEmail())
127 .detail(Details.CODE_ID, authSession.getParentSession().getId())
128 .removeDetail(Details.AUTH_METHOD)
129 .removeDetail(Details.AUTH_TYPE);
131 String authSessionEncodedId = AuthenticationSessionCompoundId.fromAuthSession(authSession).getEncodedId();
132 IdpVerifyAccountLinkActionToken token =
new IdpVerifyAccountLinkActionToken(
133 existingUser.getId(), absoluteExpirationInSecs, authSessionEncodedId,
134 brokerContext.getUsername(), brokerContext.getIdpConfig().getAlias(), authSession.getClient().getClientId()
136 UriBuilder builder = Urls.actionTokenBuilder(uriInfo.getBaseUri(), token.serialize(session, realm, uriInfo),
137 authSession.getClient().getClientId(), authSession.getTabId());
138 String link = builder
139 .queryParam(Constants.EXECUTION, context.getExecution().getId())
140 .build(realm.getName()).toString();
141 long expirationInMinutes = TimeUnit.SECONDS.toMinutes(validityInSecs);
144 context.getSession().getProvider(EmailTemplateProvider.class)
146 .setAuthenticationSession(authSession)
147 .setUser(existingUser)
148 .setAttribute(EmailTemplateProvider.IDENTITY_PROVIDER_BROKER_CONTEXT, brokerContext)
149 .sendConfirmIdentityBrokerLink(link, expirationInMinutes);
152 }
catch (EmailException e) {
153 event.error(Errors.EMAIL_SEND_FAILED);
155 ServicesLogger.LOGGER.confirmBrokerEmailFailed(e);
156 Response challenge = context.form()
157 .setError(Messages.EMAIL_SENT_ERROR)
158 .createErrorPage(Response.Status.INTERNAL_SERVER_ERROR);
159 context.failure(AuthenticationFlowError.INTERNAL_ERROR, challenge);
void showEmailSentPage(AuthenticationFlowContext context, BrokeredIdentityContext brokerContext)
Definition: IdpEmailVerificationAuthenticator.java:167