Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. <beans:beans xmlns="http://www.springframework.org/schema/security"
  2. xmlns:beans="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  6. http://www.springframework.org/schema/security
  7. http://www.springframework.org/schema/security/spring-security-4.0.xsd">
  8.  
  9. <http auto-config="true" use-expressions="true">
  10. <csrf disabled="true"/>
  11. <form-login login-processing-url="/login" login-page='/showlogin' default-target-url='/' authentication-failure-url='/authentication-failure' />
  12. <intercept-url pattern="/secureview/**" access="hasRole('ROLE_USER')" />
  13. <remember-me key="patternMinder"/>
  14. <logout logout-url="/logout" logout-success-url="/?logout" />
  15. </http>
  16.  
  17. <beans:bean id='userDetailsService' class='com.pmz.charting.security.UserDetailServiceImpl'>
  18. </beans:bean>
  19.  
  20. <authentication-manager alias="authenticationManager">
  21. <authentication-provider user-service-ref="userDetailsService" >
  22.  
  23. </authentication-provider>
  24. </authentication-manager>
  25.  
  26. </beans:beans>
  27.  
  28. public class UserDetailServiceImpl implements UserDetailsService{
  29.  
  30. @Override
  31. public UserDetails loadUserByUsername(String user) throws UsernameNotFoundException {
  32. System.out.println("In loadUserByUsername:" + user);
  33. return buildUserFromUserEntity();
  34. }
  35.  
  36.  
  37. private UserDetails buildUserFromUserEntity() {
  38. // convert model user to spring security user
  39. String username = "testuser@test.com";
  40. String password = "testuser";
  41. boolean enabled = true;
  42. boolean accountNonExpired = true;
  43. boolean credentialsNonExpired = true;
  44. boolean accountNonLocked = true;
  45. Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
  46. authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
  47.  
  48. UserDetails springUser = new User(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
  49. return springUser;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement