主要讲述,cas5.2添加一个自定义的action处理,写了一个处理微信逻辑的。主要过程就是请求进来之后,会按照flow的流程进行处理,自定义action处理之后,生成了AbstractCredential类,然后通过不同类型的认证处理类(AbstractAuthenticationHandler子类)处理,并创建返回结果。
在flow里面添加一个新的action
- 新建一个action类,继承AbstractNonInteractiveCredentialsAction类,重写constructCredentialsFromRequest方法,处理微信授权逻辑。
- 继承AbstractCasWebflowConfigurer类,重写doInitialize()方法,将新写的action添加到flow流中。
- 将新的类写到同一个configue类中,然后添加到resources\META-INF\spring.factories中。
- 继承AbstractAuthenticationHandler类,处理微信认证返回结果。
WeChatAuthenticationAction类
import org.apereo.cas.authentication.Credential;
import org.apereo.cas.authentication.adaptive.AdaptiveAuthenticationPolicy;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.web.flow.actions.AbstractNonInteractiveCredentialsAction;
import org.apereo.cas.web.flow.resolver.CasDelegatingWebflowEventResolver;
import org.apereo.cas.web.flow.resolver.CasWebflowEventResolver;
import org.apereo.cas.web.support.WebUtils;
@ConfigurationProperties(value = "wechat")
@EnableConfigurationProperties(CasConfigurationProperties.class)
public class WeChatAuthenticationAction extends AbstractNonInteractiveCredentialsAction {
public WeChatAuthenticationAction(final CasDelegatingWebflowEventResolver initialAuthenticationAttemptWebflowEventResolver,
final CasWebflowEventResolver serviceTicketRequestWebflowEventResolver,
final AdaptiveAuthenticationPolicy adaptiveAuthenticationPolicy) {
super(initialAuthenticationAttemptWebflowEventResolver, serviceTicketRequestWebflowEventResolver, adaptiveAuthenticationPolicy);
}
@Override
protected Credential constructCredentialsFromRequest(final RequestContext requestContext) {
final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
final HttpServletResponse response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
...
}
}