forked from gaganachiranjitha99/SpringBoot_HMS_Back_End
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96f3980
commit 59b316d
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
HMS_BACKEND/src/main/java/com/rhms/hms_backend/Configurations/Configs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.rhms.hms_backend.Configurations; | ||
|
||
import com.rhms.hms_backend.Repositories.UserRepo; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.authentication.AuthenticationProvider; | ||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider; | ||
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class Configs { | ||
|
||
private final UserRepo userRepo; | ||
|
||
@Bean | ||
public UserDetailsService userDetailsService () { | ||
return index -> (UserDetails) userRepo.findByIndex(index) | ||
.orElseThrow(() -> new UsernameNotFoundException("Index Not Found!")); | ||
} | ||
|
||
|
||
@Bean | ||
public PasswordEncoder passwordEncoder () { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
@Bean | ||
public AuthenticationProvider authenticationProvider(){ | ||
DaoAuthenticationProvider authProvider=new DaoAuthenticationProvider(); | ||
authProvider.setUserDetailsService(userDetailsService()); | ||
authProvider.setPasswordEncoder(passwordEncoder()); | ||
return authProvider; | ||
} | ||
|
||
|
||
@Bean | ||
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception { | ||
return configuration.getAuthenticationManager(); | ||
} | ||
|
||
@Bean | ||
public WebMvcConfigurer corsConfigurer() { //Enabling Cross Origin Access | ||
return new WebMvcConfigurer() { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/api/**") | ||
.allowedOrigins("http://localhost:4200") | ||
.allowedMethods("GET", "POST", "PUT", "DELETE") | ||
.allowedHeaders("*"); | ||
} | ||
}; | ||
} | ||
@Bean | ||
public ExecutorService executorService() { | ||
return Executors.newFixedThreadPool(10); // Adjust the pool size as per your requirements | ||
} | ||
|
||
} | ||
|
||
|