{"id":203318,"date":"2013-11-23T11:55:02","date_gmt":"2013-11-23T07:55:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=203318"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=203318","title":{"rendered":"<span class=\"post_title\">\u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 Spring Security<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0418\u0442\u0430\u043a, \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0445\u0430\u0431\u0440\u0430\u044e\u0437\u0435\u0440, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0442\u0435\u0431\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b Spring Security \u043a\u0430\u043a:<\/p>\n<ul>\n<li> \u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 Spring Security.  <\/li>\n<li> \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 Spring Security.  <\/li>\n<li> \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u043e\u0433\u043e Spring Security \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443.  <\/li>\n<\/ul>\n<p>  <a name=\"habracut\"><\/a><br \/>  Spring Security \u044d\u0442\u043e Java\/JavaEE framework, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Framework. \u041f\u0440\u043e\u0435\u043a\u0442 \u0431\u044b\u043b \u043d\u0430\u0447\u0430\u0442 \u0411\u0435\u043d\u043e\u043c \u0410\u043b\u0435\u043a\u0441\u043e\u043c (Ben Alex) \u0432 \u043a\u043e\u043d\u0446\u0435 2003 \u0433\u043e\u0434\u0430 \u043f\u043e\u0434 \u0438\u043c\u0435\u043d\u0435\u043c \u00abAcegi Security\u00bb, \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0435\u043b\u0438\u0437 \u0432\u044b\u0448\u0435\u043b \u0432 2004 \u0433\u043e\u0434\u0443. \u0412\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u0431\u044b\u043b \u043f\u043e\u0433\u043b\u043e\u0449\u0451\u043d Spring&#8217;\u043e\u043c \u0438 \u0441\u0442\u0430\u043b \u0435\u0433\u043e \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c. \u0412\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u043e\u0434 \u043d\u043e\u0432\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c Spring Security 2.0.0 \u0432 \u0430\u043f\u0440\u0435\u043b\u0435 2008 \u0433\u043e\u0434\u0430.<\/p>\n<h4>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 Spring Security:<\/h4>\n<ul>\n<li>SecurityContextHolder, \u0432 \u043d\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435(Principal) \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u043c \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e SecurityContextHolder \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442ThreadLocal \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u0441\u0430\u043c\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 SecurityContextHolder.setStrategyName(String strategy). \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e <a href=\"http:\/\/docs.spring.io\/autorepo\/docs\/spring-security\/3.0.x\/apidocs\/org\/springframework\/security\/core\/context\/SecurityContextHolder.html\">SecurityContextHolder<\/a>   <\/li>\n<li>SecurityContext, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 Authentication \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.   <\/li>\n<li>Authentication \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (Principal) \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f Spring Security.   <\/li>\n<li>GrantedAuthority \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u044b\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0432 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u00ab\u0440\u043e\u043b\u0438\u00bb), \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 ROLE_ANONYMOUS, ROLE_USER, ROLE_ADMIN.   <\/li>\n<li>UserDetails \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Authentication \u0438\u0437 DAO \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u041e\u0431\u044a\u0435\u043a\u0442 UserDetails\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u0430\u0440\u043e\u043b\u044c, \u0444\u043b\u0430\u0433\u0438: isAccountNonExpired, isAccountNonLocked, isCredentialsNonExpired, isEnabled \u0438 Collection \u2014 \u043f\u0440\u0430\u0432 (\u0440\u043e\u043b\u0435\u0439) \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.   <\/li>\n<li>UserDetailsService, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c UserDetails \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0443\u0442\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\n<pre><code class=\"java\">UserDetails loadUserByUsername(String username) throws UsernameNotFoundException;  <\/code><\/pre>\n<p>  \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442 UserDetails \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c Spring Security.   <\/li>\n<\/ul>\n<h4>\u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/h4>\n<p>  (1) \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u0432\u043e\u0439\u0442\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0438\u043c\u044f (\u043b\u043e\u0433\u0438\u043d \u0438\u043b\u0438 email) \u0438 \u043f\u0430\u0440\u043e\u043b\u044c. \u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 UsernamePasswordAuthenticationToken(\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 Authentication) \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043e\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0443 AuthenticationManager \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<p>  (2) \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 BadCredentialsException \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c \u201cBad Credentials\u201d.<\/p>\n<p>  (3) \u0415\u0441\u043b\u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0448\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Authentication.<\/p>\n<p>  (4) \u0414\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043f\u0443\u0442\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 SecurityContextHolder.getContext().setAuthentication(\u2026), \u043a\u0443\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0435\u0440\u043d\u0443\u043b AuthenticationManager.<\/p>\n<h4>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 Security \u0434\u043b\u044f SpringFramework \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/h4>\n<p>  <b>1. pom.xml<\/b><\/p>\n<pre><code class=\"xml\">&lt;properties&gt;         &lt;spring.version&gt;3.1.4.RELEASE&lt;\/spring.version&gt;  &lt;\/properties&gt;  &lt;!-- Spring Security --&gt;  &lt;dependency&gt;         &lt;groupId&gt;org.springframework.security&lt;\/groupId&gt;         &lt;artifactId&gt;spring-security-core&lt;\/artifactId&gt;            &lt;version&gt;${spring.version}&lt;\/version&gt;  &lt;\/dependency&gt;    &lt;dependency&gt;         &lt;groupId&gt;org.springframework.security&lt;\/groupId&gt;          &lt;artifactId&gt;spring-security-web&lt;\/artifactId&gt;            &lt;version&gt;${spring.version}&lt;\/version&gt;  &lt;\/dependency&gt;  &lt;dependency&gt;          &lt;groupId&gt;org.springframework.security&lt;\/groupId&gt;         &lt;artifactId&gt;spring-security-config&lt;\/artifactId&gt;            &lt;version&gt;${spring.version}&lt;\/version&gt;  &lt;\/dependency&gt; <\/code><\/pre>\n<p>  <b>2. web.xml<\/b><\/p>\n<pre><code class=\"xml\">&lt;filter&gt;     &lt;filter-name&gt;springSecurityFilterChain&lt;\/filter-name&gt;     &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;\/filter-class&gt;  &lt;\/filter&gt;  &lt;filter-mapping&gt;     &lt;filter-name&gt;springSecurityFilterChain&lt;\/filter-name&gt;     &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;  &lt;\/filter-mapping&gt; <\/code><\/pre>\n<p>  \u041d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0441\u0430\u043c \u0444\u0430\u0439\u043b \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439<b> security.xml<\/b><\/p>\n<pre><code class=\"xml\">&lt;beans:beans xmlns=&quot;http:\/\/www.springframework.org\/schema\/security&quot;                 xmlns:beans=&quot;http:\/\/www.springframework.org\/schema\/beans&quot;       xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;             xsi:schemaLocation=&quot;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&quot;&gt;      &lt;http access-denied-page=&quot;\/error403.jsp&quot;&gt;     &lt;intercept-url pattern=&quot;\/index*&quot; access=&quot;ROLE_USER,ROLE_ANONYMOUS&quot;\/&gt;     &lt;intercept-url pattern=&quot;\/add*&quot; access=&quot;ROLE_USER&quot;\/&gt;     &lt;intercept-url pattern=&quot;\/delete\/*&quot; access=&quot;ROLE_ADMIN&quot;\/&gt;     &lt;form-login login-page=&quot;\/login.jsp&quot; default-target-url=&quot;\/index&quot; authentication-failure-url=&quot;\/login.jsp?error=true&quot;\/&gt;     &lt;logout logout-url=&quot;\/logout&quot; logout-success-url=&quot;\/index&quot;\/&gt;     &lt;anonymous username=&quot;guest&quot; granted-authority=&quot;ROLE_ANONYMOUS&quot;\/&gt;     &lt;remember-me\/&gt;  &lt;\/http&gt;     &lt;authentication-manager&gt;     &lt;authentication-provider&gt;        &lt;user-service&gt;           &lt;user name=&quot;admin&quot; password=&quot;pass&quot; authorities=&quot;ROLE_ADMIN,ROLE_USER&quot;\/&gt;           &lt;user name=&quot;user1&quot; password=&quot;1111&quot; authorities=&quot;ROLE_USER&quot;\/&gt;           &lt;user name=&quot;user2&quot; password=&quot;2222&quot; disabled=&quot;true&quot; authorities=&quot;ROLE_USER&quot;\/&gt;           &lt;\/user-service&gt;     &lt;\/authentication-provider&gt;  &lt;\/authentication-manager&gt;  &lt;\/beans:beans&gt;  <\/code><\/pre>\n<p>  <u>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u043a \u043a\u043e\u0434\u0443 security.xml:<\/u><br \/>  <i>\u041f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0442\u043e \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 login.jsp \u0435\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0430 \u0441 action=&quot;\/j_spring_security_check&quot; \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f input&#8217;\u044b \u0434\u043b\u044f \u0438\u043c\u0435\u043d\u0438 \u0438 \u043f\u0430\u0440\u043e\u043b\u044f \u0441 name=\u00abj_username\u00bb \u0438 name=\u00abj_password\u00bb, \u0430 \u0442\u0430\u043a\u0436\u0435 checkbox c name=&quot;_spring_security_remember_me&quot;. \u042d\u0442\u043e \u0432\u0441\u0451 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 Spring Security \u0438\u043d\u0430\u0447\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \/index \u0433\u0434\u0435 \u0443\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438.<\/i><\/p>\n<p>  \u041d\u0430 url \/index* \u0434\u043e\u0441\u0442\u0443\u043f \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 ROLE_USER, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0433\u043e\u0441\u0442\u0438 (\u0432\u0441\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0438\u043c\u044f guest \u0438 \u043f\u0440\u0430\u0432\u0430 ROLE_ANONYMOUS).<br \/>  \u0414\u043e\u0441\u0442\u0443\u043f \u043a url \/add* \u0438\u043c\u0435\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 ROLE_USER \u0414\u043e\u0441\u0442\u0443\u043f \u043a url \/delete* \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 ROLE_ADMIN<\/p>\n<p>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0432 .xml \u0444\u0430\u0439\u043b\u0435 \u0442.\u0435. \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 UsernamePasswordAuthenticationToken \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 loadUserByUsername \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 UserDetailsService \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432 &lt;authentication-provider user-service-ref=\u00abuserDetailsService\u00bb &gt; \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 bean \u0432\u0430\u0448\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 UserDetailsService. \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u043e\u043b\u0435\u0439:<\/p>\n<pre><code class=\"xml\">&lt;authentication-manager&gt;      &lt;authentication-provider&gt;         &lt;password-encoder hash=&quot;sha&quot;\/&gt;         &lt;user-service&gt;            &lt;user name=&quot;jimi&quot; password=&quot;d7e6351eaa13189a5a3641bab846c8e8c69ba39f&quot; authorities=&quot;ROLE_USER, ROLE_ADMIN&quot; \/&gt;            &lt;user name=&quot;bob&quot; password=&quot;4e7421b1b8765d8f9406d87e7cc6aa784c4ab97f&quot; authorities=&quot;ROLE_USER&quot; \/&gt;        &lt;\/user-service&gt;      &lt;\/authentication-provider&gt;   &lt;\/authentication-manager&gt;     &lt;password-encoder hash=&quot;sha&quot;&gt;          &lt;salt-source user-property=&quot;username&quot;\/&gt;   &lt;\/password-encoder&gt;  <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0439 \u0437\u0434\u0435\u0441\u044c:<br \/>  (1) <a href=\"http:\/\/docs.spring.io\/spring-security\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a><br \/>  (2) <a href=\"http:\/\/habrahabr.ru\/post\/111102\/\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/a> \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/203318\/\"> http:\/\/habrahabr.ru\/post\/203318\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0418\u0442\u0430\u043a, \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0445\u0430\u0431\u0440\u0430\u044e\u0437\u0435\u0440, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0442\u0435\u0431\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b Spring Security \u043a\u0430\u043a:<\/p>\n<ul>\n<li> \u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 Spring Security.  <\/li>\n<li> \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 Spring Security.  <\/li>\n<li> \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u043e\u0433\u043e Spring Security \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443.  <\/li>\n<\/ul>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-203318","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203318"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203318\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}