Authentication glassfish 3.1 web应用的CAS身份验证。授权呢?
我正在尝试建立一个基于GlassFish3.1+JSF2的web应用程序。使用CAS服务器在web应用程序中安装jasig CAS客户端来执行授权,如下所示: 当用户通过身份验证时,我能够捕获EJB中的主要对象。 CAS主体属性来自Active Directory上的LDAP。现在如何添加授权? 如何仅允许AD中定义的特定用户组访问某些网页 其目的只是让用户根据LDAP角色访问不同的网页。 我试着遵循JavaEE教程中的安全Web应用程序,我的Web.xml是Authentication glassfish 3.1 web应用的CAS身份验证。授权呢?,authentication,active-directory,glassfish,authorization,cas,Authentication,Active Directory,Glassfish,Authorization,Cas,我正在尝试建立一个基于GlassFish3.1+JSF2的web应用程序。使用CAS服务器在web应用程序中安装jasig CAS客户端来执行授权,如下所示: 当用户通过身份验证时,我能够捕获EJB中的主要对象。 CAS主体属性来自Active Directory上的LDAP。现在如何添加授权? 如何仅允许AD中定义的特定用户组访问某些网页 其目的只是让用户根据LDAP角色访问不同的网页。 我试着遵循JavaEE教程中的安全Web应用程序,我的Web.xml是 <filter>
<filter>
<filter-name>CAS Authentication Filter</filter-name>
<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
<init-param>
<param-name>casServerLoginUrl</param-name>
<param-value>https://casserver:8443/cas/login</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://localhost:8080</param-value>
</init-param>
</filter>
<filter>
<filter-name>CAS Validation Filter</filter-name>
<filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
<init-param>
<param-name>casServerUrlPrefix</param-name>
<param-value>https://casserver:8443/cas</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://localhost:8080</param-value>
</init-param>
</filter>
<filter>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
</filter>
<!--
<filter>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class>
</filter>
-->
<filter-mapping>
<filter-name>CAS Authentication Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CAS Validation Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<security-constraint>
<display-name>Pagina di user</display-name>
<web-resource-collection>
<web-resource-name>index1</web-resource-name>
<description>ristretto a user</description>
<url-pattern>/faces/index.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>user only</description>
<role-name>AMP-User</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<display-name>Pagina di profile</display-name>
<web-resource-collection>
<web-resource-name>index2</web-resource-name>
<description>risretto a profile</description>
<url-pattern>/faces/index_2.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>profile only</description>
<role-name>AMP-Profile</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<description>utente generico</description>
<role-name>AMP-User</role-name>
</security-role>
<security-role>
<description>Utente di alto profilo</description>
<role-name>AMP-Profile</role-name>
</security-role>
CAS认证过滤器
org.jasig.cas.client.authentication.AuthenticationFilter
卡塞尔洛基努尔酒店
https://casserver:8443/cas/login
服务器名
http://localhost:8080
CAS验证过滤器
org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter
casServerUrlPrefix
https://casserver:8443/cas
服务器名
http://localhost:8080
CAS HttpServletRequest包装筛选器
org.jasig.cas.client.util.HttpServletRequestWrapperFilter
CAS认证过滤器
/*
CAS验证过滤器
/*
CAS HttpServletRequest包装筛选器
/*
javax.faces.PROJECT_阶段
生产
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
/面孔/*
30
faces/index.xhtml
Pagina di用户
index1
ristretto用户
/faces/index.xhtml
用户专用
放大器用户
帕吉纳迪剖面图
index2
轮廓线
/faces/index_2.xhtml
仅配置文件
放大器配置文件
通用中尉
放大器用户
普罗菲洛中尉
放大器配置文件
然后,我在glassifh-web.xml中将角色分配给我的LDAP组
<glassfish-web-app error-url="">
<security-role-mapping>
<role-name>AMP-Profile</role-name>
<group-name>AMP-Profile</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>AMP-User</role-name>
<group-name>AMP-User</group-name>
</security-role-mapping>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
放大器配置文件
放大器配置文件
放大器用户
放大器用户
保留生成的servlet类的java代码的副本。
问题是,当我访问page index.xhtml时,一个表单要求我进行身份验证,但身份验证应该由CAS服务器完成。无论如何,我无法验证。
如何使用CAS身份验证并将LDAP组映射到角色?您可以使用安全注释(JSR 250,
javax.security.annotations
)来定义基于角色的访问控制:
@Stateless
@DeclareRoles({"admin", "users"})
public class HelloEJB implements Hello {
@PermitAll
public String hello(String msg) {
return "Hello, " + msg;
}
@RolesAllowed("admin")
public String bye(String msg) {
return "Bye, " + msg;
}
}
从下面的第一个链接略加修改的示例
在这里,我首先使用@DeclareRoles
声明了角色@PermitAll
授予所有经过身份验证的用户访问权限,而@RolesAllowed
仅授予对所述角色的访问权限
您需要在部署描述符和glassfish中设置角色。我觉得这很有帮助。这本书详细介绍了细节。你也可能想看看这个。如果您遇到一些问题,请稍后再问。谢谢,但我认为保护特定人群对网页的访问对于我的应用程序来说已经足够了。我试图遵循安全文档,但它似乎与CAS身份验证冲突。有什么想法吗?那你想用glassfish进行身份验证或授权吗?或者CAS服务器(通过这些过滤器元件)应该阻止未经验证的请求吗?您确实要求glassfish服务器通过指定这些索引页的安全约束来限制对它们的访问。由于您没有提供身份验证方法,我猜它默认为基本身份验证。也许您可以删除这些约束,让CAS服务器完成它的工作。CAS应该阻止未经身份验证的请求。此外,CAS或Glassfish应该阻止经过身份验证的请求,但角色不允许。可能吗?我删除了约束,但没有执行授权,因此任何LDAP组都可以在身份验证后访问。因此,在删除安全约束时,使用CAS服务器的身份验证已经起作用了?是的,身份验证起作用。问题在于授权。。。