Я создал приложение весенней загрузки с неявным предоставлением oAuth2. Я могу проверить это из браузера. Я планирую интегрировать это в угловое приложение 2. Я застрял, потому что я не могу передать идентификатор пользователя и пароль для аутентификации, так как я использовал location.href и браузер запрашивает идентификатор пользователя и пароль. Как только я сообщу подробности, меня перенаправят на указанный токен доступа. Я ищу подход, чтобы браузер не запрашивал информацию о пользователе, не отображал страницу входа и не мог получить токен доступа из браузера.
authGrantType(userName:string, password:string){
//Not able to pass User id and password
let url = "http://localhost:8080/oauth/authorize?response_type=code&client_id=authClient1&redirect_uri=http://localhost:4200/users"
location.href = url;
}
@Configuration
@EnableWebSecurity
//@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource ds;
@Autowired
private ClientDetailsService clientDetailsService;
@Bean("userDetailsService")
protected UserDetailsService userDetailsService() {
JdbcDaoImpl jd = new JdbcDaoImpl();
jd.setDataSource(ds);
return jd;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService());
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("index.html")
.antMatchers("/**/*.js")
.antMatchers("/**/*.css")
.antMatchers("/");
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.requestMatchers(CorsUtils:: isPreFlightRequest).permitAll()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.csrf().disable()
.anonymous().disable()
.authorizeRequests()
.antMatchers("/oauth/**").permitAll()
.and()
.httpBasic();
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public JdbcTokenStore tokenStore() {
return new JdbcTokenStore(ds);
}
@Bean
@Autowired
public TokenStoreUserApprovalHandler userApprovalHandler(TokenStore tokenStore){
TokenStoreUserApprovalHandler handler = new TokenStoreUserApprovalHandler();
handler.setTokenStore(tokenStore);
handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService));
handler.setClientDetailsService(clientDetailsService);
return handler;
}
@Bean
@Autowired
public ApprovalStore approvalStore(TokenStore tokenStore) throws Exception {
TokenApprovalStore store = new TokenApprovalStore();
store.setTokenStore(tokenStore);
return store;
}
}