1616
1717package org .springframework .ws .soap .security .wss4j2 .callback ;
1818
19- import java .io .IOException ;
2019import java .util .Objects ;
2120
2221import javax .security .auth .callback .UnsupportedCallbackException ;
3231import org .springframework .security .core .userdetails .UserCache ;
3332import org .springframework .security .core .userdetails .UserDetails ;
3433import org .springframework .security .core .userdetails .UserDetailsService ;
35- import org .springframework .security .core .userdetails .UsernameNotFoundException ;
3634import org .springframework .security .core .userdetails .cache .NullUserCache ;
3735import org .springframework .util .Assert ;
3836import org .springframework .ws .soap .security .callback .CleanupCallback ;
@@ -80,21 +78,18 @@ public void afterPropertiesSet() throws Exception {
8078 * <p>
8179 * Default implementation throws an {@link UnsupportedCallbackException}.
8280 */
83- protected void handleUsernameToken (WSPasswordCallback callback ) throws IOException , UnsupportedCallbackException {
81+ protected void handleUsernameToken (WSPasswordCallback callback ) {
8482 UserDetails user = loadUserDetails (callback .getIdentifier ());
85- if (user != null ) {
86- SpringSecurityUtils .checkUserValidity (user );
87- callback .setPassword (user .getPassword ());
88- }
83+ SpringSecurityUtils .checkUserValidity (user );
84+ callback .setPassword (user .getPassword ());
8985 }
9086
9187 @ Override
92- protected void handleUsernameTokenPrincipal (UsernameTokenPrincipalCallback callback )
93- throws IOException , UnsupportedCallbackException {
88+ protected void handleUsernameTokenPrincipal (UsernameTokenPrincipalCallback callback ) {
9489 UserDetails user = loadUserDetails (callback .getPrincipal ().getName ());
9590 WSUsernameTokenPrincipalImpl principal = callback .getPrincipal ();
9691 UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken (principal ,
97- principal .getPassword (), ( user != null ) ? user .getAuthorities () : null );
92+ principal .getPassword (), user .getAuthorities ());
9893 if (this .logger .isDebugEnabled ()) {
9994 this .logger .debug ("Authentication success: " + authRequest );
10095 }
@@ -103,23 +98,15 @@ protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callb
10398 }
10499
105100 @ Override
106- protected void handleCleanup (CleanupCallback callback ) throws IOException , UnsupportedCallbackException {
101+ protected void handleCleanup (CleanupCallback callback ) {
107102 SecurityContextHolder .clearContext ();
108103 }
109104
110- private @ Nullable UserDetails loadUserDetails (String username ) throws DataAccessException {
105+ private UserDetails loadUserDetails (String username ) throws DataAccessException {
111106 UserDetails user = this .userCache .getUserFromCache (username );
112107
113108 if (user == null ) {
114- try {
115- user = Objects .requireNonNull (this .userDetailsService ).loadUserByUsername (username );
116- }
117- catch (UsernameNotFoundException notFound ) {
118- if (this .logger .isDebugEnabled ()) {
119- this .logger .debug ("Username '" + username + "' not found" );
120- }
121- return null ;
122- }
109+ user = Objects .requireNonNull (this .userDetailsService ).loadUserByUsername (username );
123110 this .userCache .putUserInCache (user );
124111 }
125112 return user ;
0 commit comments