User account has expired in spring Security

So basically I’m trying to Login with user Email and password. using spring security. but it is not login and give an error “User account has expired”. i’m trying to solve that but not found any right solution so can any help to.
Note: I’m storing userdata in MySQL using encryption.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>**HomeController.java**
@Controller
public class HomeController {
Logger log = LoggerFactory.getLogger(HomeController.class);
@Autowired
private BCryptPasswordEncoder passwordEncoder;
@Autowired
UserRepository userRepository;
@GetMapping("/home")
public String home() {
return "index";
}
@GetMapping("/about")
public String aboutUs() {
return "about";
}
@GetMapping("/signup")
public String signup(Model model) {
model.addAttribute("User",new User());
return "signup";
}
@GetMapping("/login")
public String login() {
return "login";
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@RequestMapping(value = "/do_register" ,method = RequestMethod.POST)
public String registerUser(@Valid @ModelAttribute("User") User user,BindingResult bindingResult,@RequestParam(value = "acceptTerms",defaultValue = "false")boolean aggrement,
Model model,HttpSession session) {
User ans = null;
try {
if(aggrement == false){
System.out.println("You are not agrre with terms and condition");
throw new Exception("you have not accept terms and Condition.");
}
if(bindingResult.hasErrors()){
System.err.println("Error:"+bindingResult.toString());
// if any error occur so the all data are save to the form in signup page
model.addAttribute("User",user);
return "signup";
}
user.setRole("user");
log.info("Password::"+user.getPassword());
user.setPassword(passwordEncoder.encode(user.getPassword()));
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String dateString = currentDate.format(formatter);
user.setCreatedDate(dateString);
ans = userRepository.save(user);
User emptyUser = new User();
model.addAttribute("User",emptyUser);
session.setAttribute("message", new Message("Succesfully User Registerd", "alert-success"));
} catch (Exception e) {
e.printStackTrace();
model.addAttribute("User",user);
session.setAttribute("message", new Message("Something went Wrong!"+e.getMessage(),"alert-danger"));
return "signup";
}
return "signup";
}
}
**myConfig.java**
@Configuration
@EnableWebSecurity
public class myConfig {
@Bean
public UserDetailsService getUserDetailsService() {
return new userDetailServiceimpl();
}
@Bean
public BCryptPasswordEncoder encyptPassword() {
return new BCryptPasswordEncoder();
}
@Bean
public DaoAuthenticationProvider AuthenticationProvider() {
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
daoAuthenticationProvider.setUserDetailsService(this.getUserDetailsService());
daoAuthenticationProvider.setPasswordEncoder(encyptPassword());
return daoAuthenticationProvider;
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.csrf().disable().
authorizeHttpRequests().requestMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/user/**").hasRole("user")
.anyRequest().permitAll()
.and().formLogin();
return http.build();
}
}
</code>
<code>**HomeController.java** @Controller public class HomeController { Logger log = LoggerFactory.getLogger(HomeController.class); @Autowired private BCryptPasswordEncoder passwordEncoder; @Autowired UserRepository userRepository; @GetMapping("/home") public String home() { return "index"; } @GetMapping("/about") public String aboutUs() { return "about"; } @GetMapping("/signup") public String signup(Model model) { model.addAttribute("User",new User()); return "signup"; } @GetMapping("/login") public String login() { return "login"; } @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @RequestMapping(value = "/do_register" ,method = RequestMethod.POST) public String registerUser(@Valid @ModelAttribute("User") User user,BindingResult bindingResult,@RequestParam(value = "acceptTerms",defaultValue = "false")boolean aggrement, Model model,HttpSession session) { User ans = null; try { if(aggrement == false){ System.out.println("You are not agrre with terms and condition"); throw new Exception("you have not accept terms and Condition."); } if(bindingResult.hasErrors()){ System.err.println("Error:"+bindingResult.toString()); // if any error occur so the all data are save to the form in signup page model.addAttribute("User",user); return "signup"; } user.setRole("user"); log.info("Password::"+user.getPassword()); user.setPassword(passwordEncoder.encode(user.getPassword())); LocalDate currentDate = LocalDate.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String dateString = currentDate.format(formatter); user.setCreatedDate(dateString); ans = userRepository.save(user); User emptyUser = new User(); model.addAttribute("User",emptyUser); session.setAttribute("message", new Message("Succesfully User Registerd", "alert-success")); } catch (Exception e) { e.printStackTrace(); model.addAttribute("User",user); session.setAttribute("message", new Message("Something went Wrong!"+e.getMessage(),"alert-danger")); return "signup"; } return "signup"; } } **myConfig.java** @Configuration @EnableWebSecurity public class myConfig { @Bean public UserDetailsService getUserDetailsService() { return new userDetailServiceimpl(); } @Bean public BCryptPasswordEncoder encyptPassword() { return new BCryptPasswordEncoder(); } @Bean public DaoAuthenticationProvider AuthenticationProvider() { DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); daoAuthenticationProvider.setUserDetailsService(this.getUserDetailsService()); daoAuthenticationProvider.setPasswordEncoder(encyptPassword()); return daoAuthenticationProvider; } @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.csrf().disable(). authorizeHttpRequests().requestMatchers("/admin/**").hasRole("ADMIN") .requestMatchers("/user/**").hasRole("user") .anyRequest().permitAll() .and().formLogin(); return http.build(); } } </code>
**HomeController.java** 


@Controller
public class HomeController {

    Logger log = LoggerFactory.getLogger(HomeController.class);
    
    @Autowired
    private BCryptPasswordEncoder passwordEncoder;
    
    @Autowired
    UserRepository userRepository;

    @GetMapping("/home")
    public String home() {
        return "index";
    }
    @GetMapping("/about")
    public String aboutUs() {
        return "about";
    }

    @GetMapping("/signup")
    public String signup(Model model) {
        model.addAttribute("User",new User());
        return "signup";
    }
    @GetMapping("/login")
    public String login() {
        return "login";
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
    @RequestMapping(value = "/do_register" ,method = RequestMethod.POST)
    public String registerUser(@Valid @ModelAttribute("User") User user,BindingResult bindingResult,@RequestParam(value = "acceptTerms",defaultValue = "false")boolean aggrement,
    Model model,HttpSession session) {
        User ans = null;
        try {
            if(aggrement == false){
                System.out.println("You are not agrre with terms and condition");
                throw new Exception("you have not accept terms and Condition.");
            }

            if(bindingResult.hasErrors()){
                System.err.println("Error:"+bindingResult.toString());
                //  if any error occur so the all data are save to the form in signup page
                model.addAttribute("User",user);
                return "signup";
            }

            user.setRole("user");
            log.info("Password::"+user.getPassword());
            user.setPassword(passwordEncoder.encode(user.getPassword()));
            LocalDate currentDate = LocalDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            String dateString = currentDate.format(formatter);
            user.setCreatedDate(dateString);
            ans = userRepository.save(user);
            User emptyUser = new User();
            model.addAttribute("User",emptyUser);
            session.setAttribute("message", new Message("Succesfully User Registerd", "alert-success"));
        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute("User",user);
            session.setAttribute("message", new Message("Something went Wrong!"+e.getMessage(),"alert-danger"));
            return "signup";
        }
        return "signup";
        
    }
        
}

**myConfig.java**

@Configuration
@EnableWebSecurity
public class myConfig  {

    @Bean
    public UserDetailsService getUserDetailsService() {
        return new userDetailServiceimpl();
    }
    @Bean
    public BCryptPasswordEncoder encyptPassword() {
        return new BCryptPasswordEncoder();
    }
    
    @Bean
    public DaoAuthenticationProvider AuthenticationProvider() {
        DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
        daoAuthenticationProvider.setUserDetailsService(this.getUserDetailsService());
        daoAuthenticationProvider.setPasswordEncoder(encyptPassword());
        
        return daoAuthenticationProvider;
    }
    
     @Bean
     public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
             http.csrf().disable().
             authorizeHttpRequests().requestMatchers("/admin/**").hasRole("ADMIN")
             .requestMatchers("/user/**").hasRole("user")
             .anyRequest().permitAll()
             .and().formLogin();
             return http.build();
     }
     
     
        
    
    
}

SO i want to Login with UserEmail and password which enter by user.and redirect to the user dashboard.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật