All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kasinf.framework.security.DefaultUserDetailsService Maven / Gradle / Ivy

package com.kasinf.framework.security;

import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * 整合SpringSecurity用户查询逻辑实现
 *
 * @author likh
 */
@NoArgsConstructor
@Slf4j
public class DefaultUserDetailsService implements UserDetailsService {
    /**
     * 注入上下文
     */
    @Autowired
    private ApplicationContext applicationContext;

    /**
     * 根据用户名读取用户基本信息
     * 

* 查询完成用户信息后执行发布LoadUserEvent事件 * * @param username 用户名 * @return 查询出该用户名的用户信息 * @throws UsernameNotFoundException 用户未找到异常 */ @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { log.info("Login user:[{}]", username); // find ApiBootStoreDelegate support instance // default is com.kasinf.framework.security.delegate.DefaultStoreDelegate RestStoreDelegate apiBootStoreDelegate = applicationContext.getBean(RestStoreDelegate.class); UserDetails userDetails = apiBootStoreDelegate.loadUserByUsername(username); // publish loadUserEvent applicationContext.publishEvent(new LoadUserEvent(this, username)); return userDetails; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy