- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
如标题所示,我正在尝试使用角色在 Tomcat 上集成 Spring Security 和 Waffle。该应用程序将部署到 Windows 环境中,用户已经通过域身份验证,我想进行单点登录。更进一步,我想检查经过身份验证的用户所属的组并配置拦截器以防止不属于已批准组成员的用户访问 Web 应用程序。
这是应用上下文的样子:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">
<mvc:annotation-driven />
<cache:annotation-driven />
<import resource="mvc-config.xml"/>
<!--WAFFLE CONFIG-->
<!-- windows authentication provider -->
<bean id="waffleWindowsAuthProvider" class="waffle.windows.auth.impl.WindowsAuthProviderImpl" />
<!-- collection of security filters -->
<bean id="negotiateSecurityFilterProvider" class="waffle.servlet.spi.NegotiateSecurityFilterProvider">
<constructor-arg ref="waffleWindowsAuthProvider" />
</bean>
<bean id="waffleSecurityFilterProviderCollection" class="waffle.servlet.spi.SecurityFilterProviderCollection">
<constructor-arg>
<list>
<ref bean="negotiateSecurityFilterProvider" />
<ref bean="basicSecurityFilterProvider" />
</list>
</constructor-arg>
</bean>
<!-- spring filter entry point -->
<sec:http use-expressions="true" entry-point-ref="negotiateSecurityFilterEntryPoint">
<sec:intercept-url pattern="/**" access="hasRole('APP_USER')" />
<sec:custom-filter ref="waffleNegotiateSecurityFilter" position="BASIC_AUTH_FILTER" />
</sec:http>
<bean id="basicSecurityFilterProvider" class="waffle.servlet.spi.BasicSecurityFilterProvider">
<constructor-arg ref="waffleWindowsAuthProvider" />
</bean>
<bean id="negotiateSecurityFilterEntryPoint" class="waffle.spring.NegotiateSecurityFilterEntryPoint">
<property name="Provider" ref="waffleSecurityFilterProviderCollection" />
</bean>
<!-- spring authentication provider -->
<sec:authentication-manager alias="authenticationProvider" />
<!-- spring security filter -->
<bean id="waffleNegotiateSecurityFilter" class="waffle.spring.NegotiateSecurityFilter">
<property name="Provider" ref="waffleSecurityFilterProviderCollection" />
<property name="AllowGuestLogin" value="false" />
<property name="PrincipalFormat" value="fqn" />
<property name="RoleFormat" value="both" />
</bean>
<!--END WAFFLE CONFIG-->
<!-- the mvc resources tag does the magic -->
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/img/**" location="/img/" />
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="1000000" />
</bean>
<bean id="excelExportView" class="com.mycompany.appname.view.ExcelExportView"></bean>
<context:component-scan base-package="com.mycompany.appname" />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="columnNames"/>
</set>
</property>
</bean>
<beans profile="dev">
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<qualifier value="internal"/>
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.internal.url}" />
<property name="username" value="${jdbc.internal.username}" />
<!--<property name="password" value="${jdbc.internal.password}"/>-->
<property name="minEvictableIdleTimeMillis" value="120000"/>
<property name="testOnBorrow" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="120000"/>
<property name="minIdle" value="1"/>
</bean>
<bean id="dataSourceExternal" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<qualifier value="external"/>
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.external.url}" />
<property name="username" value="${jdbc.external.username}" />
<!--<property name="password" value="${jdbc.external.password}"/>-->
<property name="minEvictableIdleTimeMillis" value="120000"/>
<property name="testOnBorrow" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="120000"/>
<property name="minIdle" value="1"/>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/db-dev.properties"></property>
</bean>
</beans>
<beans profile="test">
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<qualifier value="internal"/>
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.internal.url}" />
<property name="minEvictableIdleTimeMillis" value="120000"/>
<property name="testOnBorrow" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="120000"/>
<property name="minIdle" value="1"/>
</bean>
<bean id="dataSourceExternal" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<qualifier value="external"/>
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.external.url}" />
<property name="minEvictableIdleTimeMillis" value="120000"/>
<property name="testOnBorrow" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="120000"/>
<property name="minIdle" value="1"/>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/db-test.properties"></property>
</bean>
</beans>
<beans profile="production">
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<qualifier value="internal"/>
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.internal.url}" />
<property name="minEvictableIdleTimeMillis" value="120000"/>
<property name="testOnBorrow" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="120000"/>
<property name="minIdle" value="1"/>
</bean>
<bean id="dataSourceExternal" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<qualifier value="external"/>
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.external.url}" />
<property name="minEvictableIdleTimeMillis" value="120000"/>
<property name="testOnBorrow" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="120000"/>
<property name="minIdle" value="1"/>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/db-prod.properties"></property>
</bean>
</beans>
和 web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Beans in these files will makeup the configuration of the root web application context -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appname-servlet.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Protect against XSS -->
<context-param>
<param-name>defaultHtmlEscape</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Deploys the 'accounts' dispatcher servlet whose configuration resides in /WEB-INF/mvc-config.xml -->
<servlet>
<servlet-name>appname</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appname-servlet.xml</param-value>
</init-param>
</servlet>
<!-- Maps all URLs to the 'appname' servlet -->
<servlet-mapping>
<servlet-name>appname</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<!--
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
-->
<welcome-file-list>
<welcome-file>/WEB-INF/views/appname_main.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>60</session-timeout>
<cookie-config>
<http-only>true</http-only>
</cookie-config>
</session-config>
现在发生的是所有尝试点击应用程序“appName”的结果都会立即提示进行身份验证。通过阅读 Waffle,我只能假设这是后备身份验证,因为它无法获取 Windows token 并无法对用户进行身份验证(通过失败的尝试或无效的凭据)。
以前的尝试包括不使用“hasRole”而是使用
access="IS_AUTHENTICATED_FULLY" />
这不会检查用户的角色,但至少会根据域身份验证限制对应用程序的访问。不幸的是,在这种情况下,每次用户点击应用程序时它仍然会提示用户。至少此配置实际上允许域用户访问应用程序,这与每次都返回拒绝访问的“hasRole”方法不同。
任何见解将不胜感激...
[编辑:从我们的日志中添加一些细节]
事实证明,当我认为单点登录正在使用“IS_AUTHENTICATED_FULLY”时,我实际上得到了误报结果。浏览器正在缓存凭据并将其应用于请求,因此 SSO 从未真正起作用。我总是得到提示。 ROLE_USER 产生相同的结果:提示并接受凭据。
奇怪的是,我们在试图从 waffle 中获取一些细节时遇到了麻烦。我们在 Tomcat 的 conf logging.properties 中添加了以下行:
waffle.servlet.NegotiateSecurityFilter.level = FINE
waffle.servlet.spi.SecurityFilterProviderCollection.level = FINE
waffle.servlet.spi.NegotiateSecurityFilterProvider.level = FINE
waffle.servlet.spi.BasicSecurityFilterProvider.level = FINE
然而,localhost、catalina 等并没有产生关于 waffle 的额外细节。
我们能找到的与游戏角色相关的唯一日志信息是:
token:'org.springframework.security.authentication.AnonymousAuthenticationToken@905571d8: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@0: RemoteIpAddress: 10.10.90.70; SessionId: null; Granted Authorities: ROLE_ANONYMOUS'>
2013-02-21 11:25:10,527 DEBUG [org.springframework.security.web.FilterChainProxy] - </WEB-INF/views/ourappname_main.jsp at position 6 of 8 in additional filter chain; firing Filter: 'SessionManagementFilter'>
2013-02-21 11:25:10,528 DEBUG [org.springframework.security.web.FilterChainProxy] - </WEB-INF/views/ourappname_main.jsp at position 7 of 8 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'>
2013-02-21 11:25:10,528 DEBUG [org.springframework.security.web.FilterChainProxy] - </WEB-INF/views/ourappname_main.jsp at position 8 of 8 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'>
2013-02-21 11:25:10,529 DEBUG [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] - <Secure object: FilterInvocation: URL: /WEB-INF/views/ourappname_main.jsp; Attributes: [IS_AUTHENTICATED_FULLY]>
2013-02-21 11:25:10,529 DEBUG [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] - <Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@905571d8: Principal: anonymous
我们从 WFETCH 捕获了这个:
User; Credentials: [PROTECTED];
Authenticated: true;
Details: org.springframework.security.web.authentication.WebAuthenticationDetails@0:
RemoteIpAddress: 10.10.10.10;
SessionId: null;
Granted Authorities: ROLE_ANONYMOUS>
http://10.10.10.10/ourappname/
Transfer-Encoding: chunked
Date: Thu, 21 Feb 2013 16:29:42 GMT
[再次编辑]根据要求来自失败调用的 header 信息。值得注意的是,当使用 localhost 时,Waffle-filter 示例可以正常工作,不会提示用户。当使用 IP 或域时,它会提示。我猜这是一个系统管理/可信主机问题?
GET /ourappnameHTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: localhost:8080
Connection: Keep-Alive
HTTP/1.1 302 Found
Server: Apache-Coyote/1.1
Location: http://localhost:8080/ourappname/
Transfer-Encoding: chunked
Date: Thu, 21 Feb 2013 20:15:51 GMT
GET /ourappname/ HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: localhost:8080
Connection: Keep-Alive
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=F2216F75CBA6AC8476189DA48A63A872; Domain=.domain.tld; Path=/something/; HttpOnly
Connection: keep-alive
WWW -Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="BasicSecurityFilterProvider"
Transfer-Encoding: chunked
Date: Thu, 21 Feb 2013 20:15:51 GMT
GET /fismacm/ HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: localhost:8080
Connection: Keep-Alive
Authorization: Negotiate YHkGBisGAQUFAqBvMG2gMDAuBgorBgEEAYI3AgIKBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKKwYBBAGCNwICHqI5BDd OVExNU1NQAAEAAACXsgjiBAAEADMAAAALAAsAKAAAAAYBsR0AAAAPVzJLOFIyLURFVjFHT0xE
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=2CC0FDBF578629857113C6A72EE67FF5; Domain=.domain.tld; Path=/something/; HttpOnly
Connection: keep-alive
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="BasicSecurityFilterProvider"
Transfer-Encoding: chunked
Date: Thu, 21 Feb 2013 20:15:51 GMT
GET /favicon.ico HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: localhost:8080
Connection: Keep-Alive
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Accept-Ranges: bytes
ETag: W/"21630-1349272326000"
Last-Modified: Wed, 03 Oct 2012 13:52:06 GMT
Content-Type: image/x-icon
Content-Length: 21630
Date: Thu, 21 Feb 2013 20:16:07 GMT
最佳答案
我今天遇到了同样的问题。
原来问题与Spring安全上下文中生成的GrantedAuthority的名称有关。这将默认设置为 ROLE_"domain"\"role",例如ROLE_MYDOMAIN\MYROLE。
这是您应该在 hasRole 检查中检查的名称。
请参阅文档:https://github.com/Waffle/waffle/blob/master/Docs/spring/SpringSecurityAuthenticationProvider.md ,
授予权限
成功登录后,Waffle 将使用 GrantedAuthority 实例填充 Spring Security 的身份验证对象。
默认情况下,Waffle 将使用以下内容填充身份验证对象:
具有字符串 ROLE_USER 的 GrantedAuthority。用户所属的每个组一个 GrantedAuthority。 GrantedAuthority 字符串将是带有 ROLE_ 前缀的大写组名称。例如,如果用户是 Everyone 组的成员,则他获得 ROLE_EVERYONE 授予的权限。可以通过在 waffleSpringAuthenticationProvider 上配置不同的 defaultGrantedAuthority 和 grantedAuthorityFactory 来更改默认行为
关于java - 通过角色检查在 Tomcat 上集成 Spring Security 和 Waffle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14965989/
请帮助我的建议。 我需要通过 xml 文件中的某个变量在我的应用程序上禁用/启用 spring 安全性。 我的 spring-security.xml 文件
我做了很多研究,对我来说一切看起来都是正确的......但我无法让它发挥作用!有人有什么想法吗? 无论我做什么,相关映射仍然对任何人公开(匿名或登录,无论他们具有什么角色)。 理想情况下,我希望所有请
我们正在考虑为我们网站的一部分启用 SSL,但某些页面包含来自第三方供应商(如 Google AdSense)的广告。 我认为这会给我们的用户带来一个恼人的问题,因为他们在查看带有广告的页面时会看到类
我正在开发一个休息服务,它将通过浏览器提供 浏览器单页应用程序和移动应用程序。目前我的服务正在运行 根本没有 Spring 。 oauth2 客户端是在过滤器内部实现的,所以可以说是“手动”。 我正在
我正在为我公司的网站添加 Content-Security-Policy-Report-Only 标题。在我研究它时,我发现一些页面已经设置了 Content-Security-Policy head
在 XML 配置中,我可以使用 security 命名空间来启用对安全性的支持,例如: 我尝试使用没有 XML 的 Spring,只有 @Configuration 类。与上述 XM
我正在使用 Spring Security 3.0.2,但找不到从数据库加载匿名用户角色的方法(我有动态角色,可以将角色分配给每个人)。 我尝试使用自定义的anonymousAuthenticatio
我有那个代码。但是当我在浏览器中进入 app_dev.php/login浏览器说:该页面进行了太多重定向 安全.yml安全: 编码器: Symfony\Component\Security\Core\
我正在使用SSH Secure Shell客户端,这是一个连接服务器的好工具。 但是,我想知道是否可以记录通过SSH Secure Shell客户端运行的程序中所有即将出现的消息。例如:./ test
我有那个代码。但是当我在浏览器中进入 app_dev.php/login浏览器说:该页面进行了太多重定向 安全.yml安全: 编码器: Symfony\Component\Security\Core\
如何为表单例份验证提供程序设置 success_handler(和 failure_handler)? Silex 使用此配置忽略我: register(new Silex\Provider\Secu
新手问题...我已成功实现自定义处理程序和服务(自定义用户详细信息服务、身份验证成功、身份验证失败)并且一切正常。我现在还实现了如果 3 次并发身份验证失败将锁定帐户(一定时间)的功能。 我现在继续处
我正在使用 Spring security java 配置,我想知道一种实现多个 url 注销的方法。即 logout().logoutRequestMatcher(new AntPathReques
我正在为我的 SP 使用 Spring Security SAML 扩展。用户通过 IDP 身份验证后,SP 使用某种方法允许后续调用不必通过 IDP 重新进行身份验证。这是如何在 Spring Se
spring security 有没有办法防止下面的最后一点?我正在使用 3.0.5 - 用户登录我的网站 - 用户转到网站中的任何页面并单击注销 -注销链接使用户 session 无效并将它们发送到
要么我迟到了,要么我做错了什么。我正在使用 Visual Studio 2013,但是我试图使用 Membership 类,using System.Web.Security;我的程序集中不存在命名空
我有一个具有依赖性的oauth2客户端spring-boot应用程序: - Spring 靴1.2.0.RC1 -spring-security-oauth2 2.0.4.RELEASE - Spri
我想在控制台应用程序中生成 HashPasswordForStoringInConfigFile。 它是在 Web 应用程序中使用以下类完成的 System.Web.Security.FormsAut
我需要有多个 PRE_AUTH Spring 安全过滤器。特别是我需要使用 PRE_AUTH除了配置为 PRE_AUTH 的两个过滤器之外的过滤器在 Spring Security 3.0 的 SAM
我猜这里没有答案,但我想知道是否有办法创建这样的自定义注释: @Documented @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({E
我是一名优秀的程序员,十分优秀!