@@ -67,17 +67,9 @@ public function createUser(UserInterface $user)
67
67
*/
68
68
public function loadUserByUsername ($ username )
69
69
{
70
- if (!isset ($ this ->users [strtolower ($ username )])) {
71
- $ ex = new UsernameNotFoundException (sprintf ('Username "%s" does not exist. ' , $ username ));
72
- $ ex ->setUsername ($ username );
73
-
74
- throw $ ex ;
75
- }
70
+ $ user = $ this ->getUser ($ username );
76
71
77
- $ user = $ this ->users [strtolower ($ username )];
78
-
79
- return new User ($ user ->getUsername (), $ user ->getPassword (), $ user ->getRoles (), $ user ->isEnabled (), $ user ->isAccountNonExpired (),
80
- $ user ->isCredentialsNonExpired (), $ user ->isAccountNonLocked ());
72
+ return new User ($ user ->getUsername (), $ user ->getPassword (), $ user ->getRoles (), $ user ->isEnabled (), $ user ->isAccountNonExpired (), $ user ->isCredentialsNonExpired (), $ user ->isAccountNonLocked ());
81
73
}
82
74
83
75
/**
@@ -89,7 +81,9 @@ public function refreshUser(UserInterface $user)
89
81
throw new UnsupportedUserException (sprintf ('Instances of "%s" are not supported. ' , get_class ($ user )));
90
82
}
91
83
92
- return $ this ->loadUserByUsername ($ user ->getUsername ());
84
+ $ storedUser = $ this ->getUser ($ user ->getUsername ());
85
+
86
+ return new User ($ storedUser ->getUsername (), $ storedUser ->getPassword (), $ storedUser ->getRoles (), $ storedUser ->isEnabled (), $ storedUser ->isAccountNonExpired (), $ storedUser ->isCredentialsNonExpired () && $ storedUser ->getPassword () === $ user ->getPassword (), $ storedUser ->isAccountNonLocked ());
93
87
}
94
88
95
89
/**
@@ -99,4 +93,25 @@ public function supportsClass($class)
99
93
{
100
94
return $ class === 'Symfony\Component\Security\Core\User\User ' ;
101
95
}
96
+
97
+ /**
98
+ * Returns the user by given username.
99
+ *
100
+ * @param string $username The username.
101
+ *
102
+ * @return User
103
+ *
104
+ * @throws UsernameNotFoundException If user whose given username does not exist.
105
+ */
106
+ private function getUser ($ username )
107
+ {
108
+ if (!isset ($ this ->users [strtolower ($ username )])) {
109
+ $ ex = new UsernameNotFoundException (sprintf ('Username "%s" does not exist. ' , $ username ));
110
+ $ ex ->setUsername ($ username );
111
+
112
+ throw $ ex ;
113
+ }
114
+
115
+ return $ this ->users [strtolower ($ username )];
116
+ }
102
117
}
0 commit comments