Я внедряю аутентификацию в моем приложении Spring rest прямо сейчас, поэтому я отправляю запрос из приложения Electron.js, и Spring обрабатывает все.
Так что сейчас, если я войду через браузер, это сохранитмой объект и возвращает принципал успешно.Но если я войду в систему и попытаюсь отправить запрос на возврат этого Принципала через приложение Electron.js, оно выдаст NullException.
@GetMapping("/user")
public String user(Principal principal)
{
return principal.getName(); // null via rest app (electron app), not null via browser (authenticated)
}
@GetMapping("/loginRequest") // this is method that requires user's credentials
public UserModel login(Principal principal)
{
return userDAO.findByUsername(principal.getName()); // signs in on both (browser and rest app), returns json object
}
Конфигурация выглядит следующим образом:
@Autowired
private MongoUserDetailsService userDetailsService;
@Override
public void configure(HttpSecurity http) throws Exception
{
http.cors().and()
.csrf().disable()
.authorizeRequests()
.antMatchers("/loginRequest").authenticated()
.and()
.httpBasic();
}
@Override
public void configure(AuthenticationManagerBuilder builder) throws Exception
{
builder.userDetailsService(userDetailsService);
}
@Bean
public PasswordEncoder passwordEncoder()
{
return new BCryptPasswordEncoder();
}
Запрос отElectron.js
axios(API + 'loginRequest', {
method: 'GET',
auth: {
username: this.username, // Both username & pass are taken from fields
password: this.password
}
})
.then(response => {
this.userObject = response.data;
}).catch(err => this.showError('Username or password is invalid', 2));
Заранее спасибо!