繁体   English   中英

jasig CAS:在AuthHandler类中对RegistredService的引用

[英]jasig CAS: reference to RegistredService in AuthHandler Class

我正在为我们的公司开发自定义AuthHandler。 这个想法是允许基于用户和服务的访问。 但是我找不到访问RegistredService的方法。

有没有办法将RegistredService传递给我的AuthHandler?

/**
 *  Mbox Auth Handler
 */

package lu.ion.cas.adaptors.mbox;

import org.jasig.cas.authentication.handler.support.AbstractPreAndPostProcessingAuthenticationHandler;
import org.jasig.cas.authentication.handler.AuthenticationException;
import org.jasig.cas.authentication.principal.Credentials;
import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;

import lu.ion.cas.MboxAuthHelper;

import javax.validation.constraints.NotNull;

public class AuthHandler
    extends AbstractPreAndPostProcessingAuthenticationHandler {

    private MboxAuthHelper mboxAuthHelper;
    private RequestContext context;

    protected boolean doAuthentication(final Credentials credentials)
        throws AuthenticationException {

        return authenticateUsernamePasswordInternal((UsernamePasswordCredentials) credentials);
    }

    protected boolean authenticateUsernamePasswordInternal(
        final UsernamePasswordCredentials credentials)
        throws AuthenticationException {

        return mboxAuthHelper.load(credentials.getUsername(), credentials.getPassword(), "/auth/check") != null;
    }

    public boolean supports(Credentials credentials) {
        return true;
    }

    public final void setMboxAuthHelper(final MboxAuthHelper mboxAuthHelper) {
        this.mboxAuthHelper = mboxAuthHelper;
    }

}

我正在使用CAS 3.5.2。

我已经使用CAS几年了,发现有很多方法可以完成所有事情。 我不知道如何(或是否)可以将RegisteredService传递给AuthHandler。 我通过使用自定义AuthenticationFilter解决了相同的问题。

(后端)在您的CAS项目中/附近创建AuthenticationFilter.java,如下所示:

public class AuthenticationFilter implements Filter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        HttpSession session = request.getSession();

        String loginName = request.getRemoteUser();
        String contextPath = request.getContextPath();

        System.err.println("loginName is: " + loginName);
        System.err.println("contextPath is: " + contextPath);

        boolean isAuthorized = false;

        // do work/query to find out if they are authorized

        if (isAuthorized) {
            chain.doFilter(request, response);
        } else {
            session.invalidate();
            // print error page
        }

    }

    @Override
    public void init(FilterConfig config) throws ServletException {
    }

    @Override
    public void destroy() {
    }
}

(前端),然后添加到您的过滤器链中。 如果您的web.xml具有现有的CAS过滤器,则很简单。

...
<filter>
    <filter-name>Custom Filter</filter-name>
    <filter-class>
        com.yoursite.filter.AuthenticationFilter
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>Custom Filter</filter-name>
    <url-pattern>/index.jsp</url-pattern>
</filter-mapping>
...

没有,没有办法做到这一点。 如果要实现CAS 3.5.2的授权规则,则应查看cas-addons: https : //github.com/Unicon/cas-addons/wiki

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM