- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Spring Security 3.0 + PostgreSql
当我创建第一个用户并登录后,身份验证工作正常。
问题:在我创建另一个用户并尝试登录后,我收到用户名或密码错误的验证错误;
这是 xml 配置:
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<global-method-security pre-post-annotations="enabled">
<expression-handler ref="expressionHandler"/>
</global-method-security>
<http realm="Facebook">
<intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/register" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/**" access="ROLE_USER"/>
<form-login login-page="/login" authentication-failure-url="/login?login_error=1"/>
<http-basic/>
<logout />
<custom-filter ref="switchUserProcessingFilter" position="SWITCH_USER_FILTER"/>
</http>
<b:bean id="daoAuthenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<!-- b:property name="saltSource" ref="saltSource"/>
<b:property name="passwordEncoder" ref="passwordEncoder"/> -->
<b:property name="userDetailsService" ref="userDetailsService"/>
</b:bean>
<b:bean id="authenticationManager"
class="org.springframework.security.authentication.ProviderManager">
<b:property name="providers">
<b:list>
<b:ref local="daoAuthenticationProvider" />
</b:list>
</b:property>
</b:bean>
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService">
<password-encoder hash="md5"/>
</authentication-provider>
</authentication-manager>
<b:bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener"/>
<b:bean id="switchUserProcessingFilter" class="org.springframework.security.web.authentication.switchuser.SwitchUserFilter" autowire="byType">
<b:property name="targetUrl" value="/secure/index.htm"/>
</b:bean>
<b:bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
<b:property name="permissionEvaluator" ref="permissionEvaluator"/>
</b:bean>
<b:bean id="permissionEvaluator" class="org.springframework.security.acls.AclPermissionEvaluator">
<b:constructor-arg ref="aclService"/>
</b:bean>
</b:beans>
这是记录器输出:
2011-12-19 17:45:50,545 DEBUG [org.springframework.security.web.access.ExceptionTranslationFilter] - <Chain processed normally>
2011-12-19 17:45:50,545 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] - <SecurityContext contents are anonymous - c
ontext will not be stored in HttpSession. >
2011-12-19 17:45:50,558 DEBUG [org.springframework.security.web.context.SecurityContextPersistenceFilter] - <SecurityContextHolder now cleared, as request
processing completed>
2011-12-19 17:46:06,668 DEBUG [org.springframework.security.web.FilterChainProxy] - <Converted URL to lowercase, from: '/j_spring_security_check'; to: '/j_
spring_security_check'>
2011-12-19 17:46:06,669 DEBUG [org.springframework.security.web.FilterChainProxy] - <Candidate is: '/j_spring_security_check'; pattern is /**; matched=true
>
2011-12-19 17:46:06,669 DEBUG [org.springframework.security.web.FilterChainProxy] - </j_spring_security_check at position 1 of 11 in additional filter chai
n; firing Filter: 'org.springframework.security.web.context.SecurityContextPersistenceFilter@7f69378d'>
2011-12-19 17:46:06,670 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] - <HttpSession returned null object for SPRIN
G_SECURITY_CONTEXT>
2 011-12-19 17:46:06,670 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] - <No SecurityContext was available from the
HttpSession: org.apache.catalina.session.StandardSessionFacade@ec139fb. A new one will be created.>
2011-12-19 17:46:06,671 DEBUG [org.springframework.security.web.FilterChainProxy] - </j_spring_security_check at position 2 of 11 in additional filter chai
n; firing Filter: 'org.springframework.security.web.authentication.logout.LogoutFilter@47568bde'>
2011-12-19 17:46:06,671 DEBUG [org.springframework.security.web.FilterChainProxy] - </j_spring_security_check at position 3 of 11 in additional filter chai
n; firing Filter: 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@2f8c069'>
2011-12-19 17:46:06,672 DEBUG [org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter] - <Request is to process authenticatio
n>
2011-12-19 17:46:06,672 DEBUG [org.springframework.security.authentication.ProviderManager] - <Authentication attempt using org.springframework.security.au
thentication.dao.DaoAuthenticationProvider>
Hibernate: select user0_.id as id2_, user0_.active as active2_, user0_.avatarLocation as avatarLo3_2_, user0_.registration_date as registra4_2_, user0_.ema
il as email2_, user0_.name as name2_, user0_.password as password2_, user0_.surname as surname2_, user0_.username as username2_ from Member user0_ limit ?
Hibernate: select wallposts0_.author_id as author2_2_1_, wallposts0_.id as id1_, wallposts0_.id as id1_0_, wallposts0_.author_id as author2_1_0_, wallposts
0_.creationDate as creation3_1_0_ from WallPost wallposts0_ where wallposts0_.author_id=?
Hibernate: select mesaje0_.author_id as author2_2_1_, mesaje0_.id as id1_, mesaje0_.id as id3_0_, mesaje0_.author_id as author2_3_0_, mesaje0_.content as c
ontent3_0_, mesaje0_.receiver_Id as receiver4_3_0_, mesaje0_.subject as subject3_0_, mesaje0_.wall_post_id as wall6_3_0_ from Message mesaje0_ where mesaje
0_.author_id=?
Hibernate: select authoritie0_.id as id2_1_, authoritie0_.authority_Id as authority2_1_, authority1_.authority_Id as authority1_4_0_, authority1_.authority
as authority4_0_ from Member_Authorities authoritie0_ inner join Authorities authority1_ on authoritie0_.authority_Id=authority1_.authority_Id where autho
ritie0_.id=?
Hibernate: select wallposts0_.author_id as author2_2_1_, wallposts0_.id as id1_, wallposts0_.id as id1_0_, wallposts0_.author_id as author2_1_0_, wallposts
0_.creationDate as creation3_1_0_ from WallPost wallposts0_ where wallposts0_.author_id=?
Hibernate: select mesaje0_.author_id as author2_2_1_, mesaje0_.id as id1_, mesaje0_.id as id3_0_, mesaje0_.author_id as author2_3_0_, mesaje0_.content as c
ontent3_0_, mesaje0_.receiver_Id as receiver4_3_0_, mesaje0_.subject as subject3_0_, mesaje0_.wall_post_id as wall6_3_0_ from Message mesaje0_ where mesaje
0_.author_id=?
Hibernate: select authoritie0_.id as id2_1_, authoritie0_.authority_Id as authority2_1_, authority1_.authority_Id as authority1_4_0_, authority1_.authority
as authority4_0_ from Member_Authorities authoritie0_ inner join Authorities authority1_ on authoritie0_.authority_Id=authority1_.authority_Id where autho
ritie0_.id=?
2011-12-19 17:46:06,836 WARN [org.springframework.security.authentication.event.LoggerListener] - <Authentication event AuthenticationFailureServiceExcepti
onEvent: gogu; details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: 7A08BE43A052A
757AD35DB97351167A7; exception: result returns more than one elements>
2011-12-19 17:46:06,837 DEBUG [org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter] - <Authentication request failed: org.
springframework.security.authentication.AuthenticationServiceException: result returns more than one elements>
2011-12-19 17:46:06,838 DEBUG [org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter] - <Updated SecurityContextHolder to co
ntain null Authentication>
2011-12-19 17:46:06,838 DEBUG [org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter] - <Delegating to authentication failur
e handlerorg.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler@fdb5ed9>
2011-12-19 17:46:06,839 DEBUG [org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler] - <Redirecting to /login?login_error=
1>
2011-12-19 17:46:06,839 DEBUG [org.springframework.security.web.DefaultRedirectStrategy] - <Redirecting to '/facebook-1.0.0-SNAPSHOT/login?login_error=1'>
2011-12-19 17:46:06,839 DEBUG [org.springframework.security.web.context.SecurityContextPersistenceFilter] - <SecurityContextHolder now cleared, as request
processing completed>
2011-12-19 17:46:06,842 DEBUG [org.springframework.security.web.FilterChainProxy] - <Converted URL to lowercase, from: '/login'; to: '/login'>
2011-12-19 17:46:06,842 DEBUG [org.springframework.security.web.FilterChainProxy] - <Candidate is: '/login'; pattern is /**; matched=true>
2011-12-19 17:46:06,843 DEBUG [org.springframework.security.web.FilterChainProxy] - </login?login_error=1 at position 1 of 11 in additional filter chain; f
iring Filter: 'org.springframework.security.web.context.SecurityContextPersistenceFilter@7f69378d'>
2011-12-19 17:46:06,843 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] - <HttpSession returned null object for SPRING_SECURITY_CONTEXT>
谢谢!
<小时/>谢谢乔恩!是的,我的 UserDetailsServiceImpl 有问题,因为当我使用 <jdbc-user-service data-source ref="myDataSource"/>
时效果很好。
UserDetailsServiceImpl - loadUserByUsername(用户名):
导入org.springframework.security.core.userdetails.User;
…….. …… .
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
org.myapp.app.domain.User userEntity = userDao.getUserByName(username);
if (userEntity == null)
throw new UsernameNotFoundException("user not found");
String password = userEntity.getPassword();
Set<Authority> authorities = userEntity.getAuthorities();
Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
for (Authority authority : authorities) {
grantedAuthorities.add(new GrantedAuthorityImpl(authority.getAuthority()));
}
return new User(username, password, true, true, true, true, grantedAuthorities);
有人对 UserDetailsServiceImpl 有类似的问题并可以给出提示
最佳答案
hibernate :
select
user0_.id as id2_,
user0_.active as active2_,
user0_.avatarLocation as avatarLo3_2_,
user0_.registration_date as registra4_2_,
user0_.email as email2_,
user0_.name as name2_,
user0_.password as password2_,
user0_.surname as surname2_,
user0_.username as username2_
from Member user0_ limit ?
您的用户请求似乎没有按名称过滤用户。检查您的 UserDetailsService 实现。
关于java - 数据库中超过一个用户的 Spring Security 身份验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8564062/
我使用这个 cmd 应用程序 https://github.com/tokland/youtube-upload 上传 50 个视频后,我收到此错误: [RequestError] Server re
尝试将 docker 容器提交到镜像时出现错误: [root@dockerregistry /]# docker commit da4180ab1536 dockerregistry:5000/myi
我只是想知道这样做会更好吗: if((fd = open(filename, O_RDWR)) == -1) { fprintf(stderr, "open [ %s ]\n", strerror(e
我在我的开发机器(单个笔记本)中使用 Elasticsearch 1.4.4。一切都设置为默认值,因为我从未更改过任何设置。 当我启动它时,我通常会收到以下消息: [2015-10-27 09:38:
我收到错误 Lock wait timeout exceeded;尝试重新启动事务。这是什么原因,如何解决?仅供引用:MySQL 配置文件中的 innodb_lock_wait_timeout = 1
我对 Slack 中的 block 功能有疑问。有人设法构建 3 列而不是 2 列吗? 我凭直觉尝试了以下代码,但它不起作用: { "blocks": [ {
div 中的内容超过由 css 决定的固定大小。 #fixeddiv { position: fixed; margin: auto; max-height: 300px
我想将 EditText 字段限制为 150 个字符,我可以很容易地做到这一点。但是,当用户试图超过该限制时,我还需要通过键入(即第 151 个字符)或粘贴超过 150 个字符来提醒用户。 解决这个问
我目前正在使用此代码并排记录两个窗口: ffmpeg -f gdigrab -framerate 30 -i title="" -f gdigrab -framerate 30 -i title=""
我在几个包含长字符串的单元格上使用嵌套的 SUBSTITUE 函数,并定期更新 SUBSTITUE fx,这导致我将其复制并粘贴到所有需要它的单元格中。问题是,我的 SUBSTITUTE 列表会随着时
我创建了一个标题 div,如下所示:
Here is the demo link 您怎么看,页面中只有 8 个广告可见,但我有 14 个广告。我已阅读有关广告限制的信息 here但不明白是不是我的情况?有人可以给我确切的答案,为什么我看不
我的非常简单的算法 - C 中的快速排序有问题。它非常有效(随机化大约 0.1 秒并检查列表是否已排序)但是当我想要对超过 500k 的元素进行排序时它会崩溃。不幸的是,我需要对它们进行更多排序,因为
我成功解决了一个关于 Hackerrank 的问题,它通过了所有测试用例,但我得到了一个错误,超过了时间限制。我猜如果我优化我的代码它会工作,但我想不出任何方法来使我的代码更有效率。 问题是: 对大小
你会如何用 包围下面的文字3 个反引号 ```使用 tpope 的 Vim Surround . 我所能做的就是 1 个反引号 使用 S`在视觉模式下: 最佳答案 这不是你问的,但这可以在没有环绕的情
我目前有一个模拟账户。我正在尝试为我的雇主使用 SwifType 制作 POC。我们有一个非常大的数据库,每 1 小时索引一次,并创建一个 JSON 文件。我认为与 Elastic 的集成将非常容易,
我为一个大约有 100 到 120 名成员的小型组织维护网站。 每个月,我们都会发送一封电子邮件,通知我们的成员我们将在即将举行的 session 中讨论的主题。 我正在尝试使用我们的网站为我们提供一
这个问题已经有答案了: How to automatically input an array formula as string with more than 255 characters in l
我有一个在 JBoss 6.1 中运行的 JSF 应用程序,它使用内部Tomcat Servlet 容器。 我已经通过apache commons文件上传实现了上传。我想防止上传过大的文件并设置了属性
当我尝试在 PyMySQL 上执行查询时,出现以下错误: pymysql.err.InternalError: (1205, 'Lock wait timeout exceeded; try rest
我是一名优秀的程序员,十分优秀!