[英]jasig CAS: reference to RegistredService in AuthHandler Class
I'm developing a custom AuthHandler for our company. 我正在为我们的公司开发自定义AuthHandler。 The idea is to allow access based on user and service.
这个想法是允许基于用户和服务的访问。 But i can't find a way to access the RegistredService.
但是我找不到访问RegistredService的方法。
Is there a way to pass the RegistredService to my AuthHandler ? 有没有办法将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;
}
}
I'm using CAS 3.5.2. 我正在使用CAS 3.5.2。
I have used CAS for a few years and found that there are many ways to do everything. 我已经使用CAS几年了,发现有很多方法可以完成所有事情。 I don't know how (or if) you can pass the RegisteredService to your AuthHandler.
我不知道如何(或是否)可以将RegisteredService传递给AuthHandler。 I solved the same problem by using a custom AuthenticationFilter.
我通过使用自定义AuthenticationFilter解决了相同的问题。
(backend) Create AuthenticationFilter.java in/near your CAS project like this: (后端)在您的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() {
}
}
(frontend) Then add to your filter chain. (前端),然后添加到您的过滤器链中。 If you have a web.xml with existing CAS filters, it is easy.
如果您的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>
...
No there is no way to do this. 没有,没有办法做到这一点。 If you want to implement authorization rules for CAS 3.5.2, you should review cas-addons: https://github.com/Unicon/cas-addons/wiki
如果要实现CAS 3.5.2的授权规则,则应查看cas-addons: https : //github.com/Unicon/cas-addons/wiki
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.