मेरे पास एक वसंत बूट एप्लिकेशन है जो वसंत सुरक्षा का उपयोग करता है, इसलिए मेरे मामले में मेरे पास 2 प्रकार के उपयोगकर्ता एक एडमिन हैं, एक साधारण उपयोगकर्ता मुझे डेटासोर्स से डेटा मिलता है, फिर मैं एक क्वेरी निष्पादित करता हूं, मेरी समस्या है पुनर्निर्देशन मेरे पास प्रत्येक उपयोगकर्ता के लिए एक अलग होमपेज है, मैं प्रमाणीकरण SUccessHandler पर उपयोग करने के लिए कोशिश कर रहा हूं लेकिन यह काम नहीं करेगा कृपया मेरी मदद करें;प्रमाणीकरण SuccessHandler स्प्रिंग सुरक्षा
मेरी स्प्रिंग सुरक्षा वर्ग विन्यास:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import javax.sql.DataSource ;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
Securityhandler successHandler ;
//Pour l'authentification des Utilisateur de Table Utilisateur
@Autowired
public void GlobalConfig(AuthenticationManagerBuilder auth,DataSource dataSource) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("SELECT \"Pseudo\" AS principal , \"Password\" AS credentials , true FROM \"UTILISATEUR\" WHERE \"Pseudo\" = ? ")
.authoritiesByUsernameQuery("SELECT u.\"Pseudo\" AS principal , r.role as role FROM \"UTILISATEUR\" u ,\"Role\" r where u.id_role=r.id_role AND \"Pseudo\" = ? ")
.rolePrefix("_ROLE");
}
//ne pas appliqué la securité sur les ressources
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/bootstrap/**","/css/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.successHandler(successHandler)
}
}
और यह मेरा AuthenticationSuccessHandler
import java.io.IOException;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
public class Securityhandler implements AuthenticationSuccessHandler {
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
if (roles.contains("ROLE_Admin")) {
response.sendRedirect("/admin/home.html");
}
}
}
है और इस कंसोल में त्रुटि है:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed;
और 'सुरक्षाहैंडलर' का उदाहरण बनाने की क्या उम्मीद है? कोई 'घटक' नहीं है और न ही इसे '@ बीन' के रूप में घोषित किया गया है। तो उदाहरण पर कभी मौजूद होगा। –
मुझे वास्तव में वसंत सुरक्षा में एक नौसिखिया समझा सकता है –
इसका वसंत सुरक्षा के साथ कुछ लेना देना नहीं है, जो कि मूल वसंत उपयोग है ... आपको वसंत को बताने की ज़रूरत है कि कौन से ऑब्जेक्ट्स को तुरंत चालू करना है, यह उन उदाहरणों को स्वचालित नहीं कर सकता है। –