我可以删除“info.ftl”页面显示,自定义“ExecuteActionsActionTokenHandler”,如下所述:
action-token-spi
你必须创建一个文件:
src/main/resources/META-INF/services/org.keycloak.authentication.actiontoken.ActionTokenHandlerFactory
包含您要使用的类的名称:
com.example.ExecuteActionTokenHandlerFactory
然后您使用以下代码创建该类 com.example.ExecuteActionTokenHandlerFactory:
public class ExecuteActionTokenHandlerFactory extends ExecuteActionsActionTokenHandler {
@Override
public Response handleToken(ExecuteActionsActionToken token, ActionTokenContext<ExecuteActionsActionToken> tokenContext) {
AuthenticationSessionModel authSession = tokenContext.getAuthenticationSession();
String redirectUri = RedirectUtils.verifyRedirectUri(tokenContext.getUriInfo(), token.getRedirectUri(),
tokenContext.getRealm(), authSession.getClient());
if (redirectUri != null) {
authSession.setAuthNote(AuthenticationManager.SET_REDIRECT_URI_AFTER_REQUIRED_ACTIONS, "true");
authSession.setRedirectUri(redirectUri);
authSession.setClientNote(OIDCLoginProtocol.REDIRECT_URI_PARAM, redirectUri);
}
token.getRequiredActions().stream().forEach(authSession::addRequiredAction);
UserModel user = tokenContext.getAuthenticationSession().getAuthenticatedUser();
// verify user email as we know it is valid as this entry point would never have gotten here.
user.setEmailVerified(true);
String nextAction = AuthenticationManager.nextRequiredAction(tokenContext.getSession(), authSession, tokenContext.getClientConnection(), tokenContext.getRequest(), tokenContext.getUriInfo(), tokenContext.getEvent());
return AuthenticationManager.redirectToRequiredActions(tokenContext.getSession(), tokenContext.getRealm(), authSession, tokenContext.getUriInfo(), nextAction);
}
}
其实和上层的实现是一样的,只是我们去掉了以下部分:
if (tokenContext.isAuthenticationSessionFresh()) {
...
}
这意味着如果用户没有会话,当用户重置他的密码时,他会被重定向到那个“info.ftl”页面。