|  | @ -1,3 +1,4 @@
 | 
	
		
			
				|  |  | <<<<<<< HEAD:app/public-health-server/src/main/java/com/yihu/health/security/core/EhrWebAuthenticationProvider.java
 | 
	
		
			
				|  |  | package com.yihu.health.security.core;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import org.springframework.security.authentication.BadCredentialsException;
 | 
	
	
		
			
				|  | @ -150,3 +151,161 @@ public class EhrWebAuthenticationProvider extends AbstractUserDetailsAuthenticat
 | 
	
		
			
				|  |  |         return this.userDetailsService;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 | 
	
		
			
				|  |  | =======
 | 
	
		
			
				|  |  | //package com.yihu.ehr.iot.security.core;
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //import org.springframework.security.authentication.BadCredentialsException;
 | 
	
		
			
				|  |  | //import org.springframework.security.authentication.InternalAuthenticationServiceException;
 | 
	
		
			
				|  |  | //import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 | 
	
		
			
				|  |  | //import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider;
 | 
	
		
			
				|  |  | //import org.springframework.security.authentication.dao.SaltSource;
 | 
	
		
			
				|  |  | //import org.springframework.security.authentication.encoding.PasswordEncoder;
 | 
	
		
			
				|  |  | //import org.springframework.security.authentication.encoding.PlaintextPasswordEncoder;
 | 
	
		
			
				|  |  | //import org.springframework.security.core.AuthenticationException;
 | 
	
		
			
				|  |  | //import org.springframework.security.core.session.SessionRegistry;
 | 
	
		
			
				|  |  | //import org.springframework.security.core.userdetails.UserDetails;
 | 
	
		
			
				|  |  | //import org.springframework.security.core.userdetails.UserDetailsService;
 | 
	
		
			
				|  |  | //import org.springframework.security.core.userdetails.UsernameNotFoundException;
 | 
	
		
			
				|  |  | //import org.springframework.util.Assert;
 | 
	
		
			
				|  |  | //import org.springframework.web.context.request.RequestContextHolder;
 | 
	
		
			
				|  |  | //import org.springframework.web.context.request.ServletRequestAttributes;
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | ///**
 | 
	
		
			
				|  |  | // * Created by progr1mmer on 2018/1/26.
 | 
	
		
			
				|  |  | // */
 | 
	
		
			
				|  |  | //public class EhrWebAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider {
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    private static final String USER_NOT_FOUND_PASSWORD = "userNotFoundPassword";
 | 
	
		
			
				|  |  | //    private PasswordEncoder passwordEncoder;
 | 
	
		
			
				|  |  | //    private String userNotFoundEncodedPassword;
 | 
	
		
			
				|  |  | //    private SaltSource saltSource;
 | 
	
		
			
				|  |  | //    private UserDetailsService userDetailsService;
 | 
	
		
			
				|  |  | //    private SessionRegistry sessionRegistry;
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    public EhrWebAuthenticationProvider() {
 | 
	
		
			
				|  |  | //        this.setPasswordEncoder((PasswordEncoder)(new PlaintextPasswordEncoder()));
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    public EhrWebAuthenticationProvider(UserDetailsService userDetailsService) {
 | 
	
		
			
				|  |  | //        this.userDetailsService = userDetailsService;
 | 
	
		
			
				|  |  | //        this.setPasswordEncoder((PasswordEncoder)(new PlaintextPasswordEncoder()));
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    /**
 | 
	
		
			
				|  |  | //    public EhrWebAuthenticationProvider(UserDetailsService userDetailsService, SessionRegistry sessionRegistry) {
 | 
	
		
			
				|  |  | //        this.userDetailsService = userDetailsService;
 | 
	
		
			
				|  |  | //        this.sessionRegistry = sessionRegistry;
 | 
	
		
			
				|  |  | //        this.setPasswordEncoder((PasswordEncoder)(new PlaintextPasswordEncoder()));
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //     */
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    /**
 | 
	
		
			
				|  |  | //     * Step 3
 | 
	
		
			
				|  |  | //     * @param userDetails
 | 
	
		
			
				|  |  | //     * @param authentication
 | 
	
		
			
				|  |  | //     * @throws AuthenticationException
 | 
	
		
			
				|  |  | //     */
 | 
	
		
			
				|  |  | //    protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
 | 
	
		
			
				|  |  | //        Object salt = null;
 | 
	
		
			
				|  |  | //        if(this.saltSource != null) {
 | 
	
		
			
				|  |  | //            salt = this.saltSource.getSalt(userDetails);
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        if(authentication.getCredentials() == null) {
 | 
	
		
			
				|  |  | //            this.logger.debug("Authentication failed: no credentials provided");
 | 
	
		
			
				|  |  | //            throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
 | 
	
		
			
				|  |  | //        } else {
 | 
	
		
			
				|  |  | //            EhrWebAuthenticationToken ehrWebAuthenticationToken = (EhrWebAuthenticationToken) authentication;
 | 
	
		
			
				|  |  | //            if(!ehrWebAuthenticationToken.isSso()) {
 | 
	
		
			
				|  |  | //                String presentedPassword = authentication.getCredentials().toString();
 | 
	
		
			
				|  |  | //                if (!this.passwordEncoder.isPasswordValid(userDetails.getPassword(), presentedPassword, salt)) {
 | 
	
		
			
				|  |  | //                    this.logger.debug("Authentication failed: password does not match stored value");
 | 
	
		
			
				|  |  | //                    throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
 | 
	
		
			
				|  |  | //                }
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //            //HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
 | 
	
		
			
				|  |  | //            //sessionRegistry.registerNewSession(request.getSession().getId(), userDetails);
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    protected void doAfterPropertiesSet() throws Exception {
 | 
	
		
			
				|  |  | //        Assert.notNull(this.userDetailsService, "A UserDetailsService must be set");
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    protected final UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
 | 
	
		
			
				|  |  | //        UserDetails loadedUser;
 | 
	
		
			
				|  |  | //        try {
 | 
	
		
			
				|  |  | //            loadedUser = this.getUserDetailsService().loadUserByUsername(username);
 | 
	
		
			
				|  |  | //        } catch (UsernameNotFoundException var6) {
 | 
	
		
			
				|  |  | //            if(authentication.getCredentials() != null) {
 | 
	
		
			
				|  |  | //                String presentedPassword = authentication.getCredentials().toString();
 | 
	
		
			
				|  |  | //                this.passwordEncoder.isPasswordValid(this.userNotFoundEncodedPassword, presentedPassword, (Object)null);
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            throw var6;
 | 
	
		
			
				|  |  | //        } catch (Exception var7) {
 | 
	
		
			
				|  |  | //            throw new InternalAuthenticationServiceException(var7.getMessage(), var7);
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        if(loadedUser == null) {
 | 
	
		
			
				|  |  | //            throw new InternalAuthenticationServiceException("UserDetailsService returned null, which is an interface contract violation");
 | 
	
		
			
				|  |  | //        } else {
 | 
	
		
			
				|  |  | //            return loadedUser;
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    public void setPasswordEncoder(Object passwordEncoder) {
 | 
	
		
			
				|  |  | //        Assert.notNull(passwordEncoder, "passwordEncoder cannot be null");
 | 
	
		
			
				|  |  | //        if(passwordEncoder instanceof PasswordEncoder) {
 | 
	
		
			
				|  |  | //            this.setPasswordEncoder((PasswordEncoder)passwordEncoder);
 | 
	
		
			
				|  |  | //        } else if(passwordEncoder instanceof org.springframework.security.crypto.password.PasswordEncoder) {
 | 
	
		
			
				|  |  | //            final org.springframework.security.crypto.password.PasswordEncoder delegate = (org.springframework.security.crypto.password.PasswordEncoder)passwordEncoder;
 | 
	
		
			
				|  |  | //            this.setPasswordEncoder(new PasswordEncoder() {
 | 
	
		
			
				|  |  | //                public String encodePassword(String rawPass, Object salt) {
 | 
	
		
			
				|  |  | //                    this.checkSalt(salt);
 | 
	
		
			
				|  |  | //                    return delegate.encode(rawPass);
 | 
	
		
			
				|  |  | //                }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //                public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
 | 
	
		
			
				|  |  | //                    this.checkSalt(salt);
 | 
	
		
			
				|  |  | //                    return delegate.matches(rawPass, encPass);
 | 
	
		
			
				|  |  | //                }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //                private void checkSalt(Object salt) {
 | 
	
		
			
				|  |  | //                    Assert.isNull(salt, "Salt value must be null when used with crypto module PasswordEncoder");
 | 
	
		
			
				|  |  | //                }
 | 
	
		
			
				|  |  | //            });
 | 
	
		
			
				|  |  | //        } else {
 | 
	
		
			
				|  |  | //            throw new IllegalArgumentException("passwordEncoder must be a PasswordEncoder instance");
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    private void setPasswordEncoder(PasswordEncoder passwordEncoder) {
 | 
	
		
			
				|  |  | //        Assert.notNull(passwordEncoder, "passwordEncoder cannot be null");
 | 
	
		
			
				|  |  | //        this.userNotFoundEncodedPassword = passwordEncoder.encodePassword("userNotFoundPassword", (Object)null);
 | 
	
		
			
				|  |  | //        this.passwordEncoder = passwordEncoder;
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    protected PasswordEncoder getPasswordEncoder() {
 | 
	
		
			
				|  |  | //        return this.passwordEncoder;
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    public void setSaltSource(SaltSource saltSource) {
 | 
	
		
			
				|  |  | //        this.saltSource = saltSource;
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    protected SaltSource getSaltSource() {
 | 
	
		
			
				|  |  | //        return this.saltSource;
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    public void setUserDetailsService(UserDetailsService userDetailsService) {
 | 
	
		
			
				|  |  | //        this.userDetailsService = userDetailsService;
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    protected UserDetailsService getUserDetailsService() {
 | 
	
		
			
				|  |  | //        return this.userDetailsService;
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | //}
 | 
	
		
			
				|  |  | >>>>>>> eb49bc9a23d809112535a9bde36737ef12f77756:app/app-iot-server/src/main/java/com/yihu/ehr/iot/security/core/EhrWebAuthenticationProvider.java
 |