के लिए अलग-अलग लॉगिन हैलो मैं एक लॉगिन पृष्ठ के साथ स्प्रिंग सुरक्षा के साथ सुरक्षित एक वेब एप्लिकेशन है। यह मेरी सुरक्षा विन्यासस्प्रिंग ओयूथ - वेब और आरईएसटी
@Configuration
@ComponentScan("it.besmart")
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Autowired
@Qualifier("customUserDetailsService")
UserDetailsService userDetailsService;
@Autowired
CustomSuccessHandler customSuccessHandler;
@Autowired
CustomAuthenticationFailureHandler customAuthenticationFailureHandler;
@Autowired
DataSource dataSource;
@Autowired
private ConnectionFactoryLocator connectionFactoryLocator;
@Autowired
private UsersConnectionRepository usersConnectionRepository;
@Autowired
private FacebookConnectionSignup facebookConnectionSignup;
private final static Logger logger = LoggerFactory.getLogger(SecurityConfiguration.class);
@Autowired
public void configureGlobalService(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
protected void configure(HttpSecurity http) throws Exception {
logger.debug("Webapp security configured");
http.
authorizeRequests()
.antMatchers("/", "/register", "/registrationConfirm", "/resendRegistrationToken", "/park/**")
.permitAll()
.antMatchers("/edit/**", "/payment/**", "/plate/**", "/book/**", "/home", "/stop/**",
"/notification/**", "/include/**")
.access("hasRole('USER') or hasRole('ADMIN') or hasRole('PARK')").antMatchers("/admin/**")
.access("hasRole('ADMIN') or hasRole('PARK')").antMatchers("/updatePassword")
.hasAuthority("CHANGE_PASSWORD_PRIVILEGE")
.and().formLogin().loginPage("/")
.successHandler(customSuccessHandler).failureHandler(customAuthenticationFailureHandler)
.usernameParameter("email").passwordParameter("password").and().rememberMe()
.rememberMeParameter("remember-me").tokenRepository(persistentTokenRepository())
.tokenValiditySeconds(86400).and().exceptionHandling().accessDeniedPage("/Access_Denied").and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/?logout=true").permitAll();
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public PersistentTokenRepository persistentTokenRepository() {
JdbcTokenRepositoryImpl db = new JdbcTokenRepositoryImpl();
db.setDataSource(dataSource);
return db;
}
}
यह मेरी सभी वेब आवेदन प्राप्त करके अच्छा काम करता है।
उसी एप्लिकेशन में मेरे पास कुछ आरईएसटी एपीआई की सुरक्षा के लिए संसाधन/प्राधिकरण सर्वर भी है।
कुछ संसाधन प्राधिकरण कोड अनुदान से सुरक्षित हैं, इसलिए अविश्वसनीय मोबाइल ऐप को मेरे आवेदन से लॉगिन फॉर्म के साथ एक्सेस टोकन लेना चाहिए। मैं चाहता हूं कि एप्लिकेशन मोबाइल ऐप से लॉगिन करने का प्रयास करते समय एक अलग लॉगिन पेज का उपयोग करें।
यह मेरा resourceServer विन्यास
@EnableResourceServer
@ComponentScan("it.besmart.easyparking")
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ResourceServerConfig {
private final Logger logger = LoggerFactory.getLogger(ResourceServerConfig.class);
@Autowired
DataSource dataSource;
private static final String RESOURCE_ID = "easyparking_api";
@Configuration
// @Order(2)
public class grantCredentialsConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
logger.debug("Api security configured");
http
.requestMatchers().antMatchers("/api/oauth/**").and().authorizeRequests()
.antMatchers("/api/oauth/**").access("hasRole('USER')").and().formLogin().loginPage("/apilogin")
.permitAll();
}
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.tokenStore(tokenStore()).resourceId(RESOURCE_ID);
}
}
@Configuration
// @Order(4)
public class clientCredentialsConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
logger.debug("Client security configured");
http
.requestMatchers().antMatchers("/oauth2/**", "/api/registration", "/api/park/**").and()
.authorizeRequests().antMatchers("/oauth2/**", "/api/registration", "/api/park/**").authenticated();
}
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.tokenStore(tokenStore()).resourceId(RESOURCE_ID);
}
}
@Bean
public TokenStore tokenStore() {
return new JdbcTokenStore(dataSource);
}
}
हां, तो grantCredentialsConfiguration
अनुरोध रीडायरेक्ट करना चाहिए करने के लिए/apilogin रूप है, लेकिन ऐसा नहीं, मैं मुख्य वेब अनुप्रयोग लॉगिन पृष्ठ पर पुनः निर्देशित कर रहा हूँ करता है ... यह कैसे हो सकता है पूरा किया?
संपादित
लॉग में करीब देख रहे हैं, यह है कि तरह लग रहा है जब मैं प्राप्त करने का प्रयास/OAuth/अधिकृत करते हैं/सामान्य सुरक्षा श्रृंखला जगह लेता है और मैं
2017-05-25 12:23:15 DEBUG o.s.security.web.FilterChainProxy[310] - /oauth/authorize?response_type=token&client_id=test&redirect_uri=https://www.getpostman.com/oauth2/callback reached end of additional filter chain; proceeding with original chain
2017-05-25 12:23:15 DEBUG o.s.s.o.p.e.FrameworkEndpointHandlerMapping[310] - Looking up handler method for path /oauth/authorize
2017-05-25 12:23:15 DEBUG o.s.s.o.p.e.FrameworkEndpointHandlerMapping[317] - Returning handler method [public org.springframework.web.servlet.ModelAndView org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint.authorize(java.util.Map<java.lang.String, java.lang.Object>,java.util.Map<java.lang.String, java.lang.String>,org.springframework.web.bind.support.SessionStatus,java.security.Principal)]
2017-05-25 12:23:15 DEBUG o.s.s.w.a.ExceptionTranslationFilter[163] - Authentication exception occurred; redirecting to authentication entry point
org.springframework.security.authentication.InsufficientAuthenticationException: User must be authenticated with Spring Security before authorization can be completed.
तो यह लग रहा है मिल अनुरोध के प्रबंधन के लिए एक हैंडलर की तलाश करना, वांछित के रूप में/एपीआई/एपिलोगिन पर रीडायरेक्ट करने की बजाय, उसे Authentication exception
मिल जाता है और इसलिए मैं मानक लॉगिन पेज पर जाता हूं ... लेकिन मुझे यह अपवाद क्यों मिलता है? के बाद से यह अप्रमाणित पहुंच सूची में नहीं जोड़ा गया है
धन्यवाद उत्तर के लिए, मैं करने की कोशिश की है, लेकिन मैं वेब अनुप्रयोग लॉगिन पृष्ठ पर पुनः निर्देशित किया जाना जारी, apilogin खाते में – besmart