У меня есть весенний проект, который включает angularjs веб-интерфейс. Я должен удалить весь интерфейс и оставить все API RESTful для другого отдельного интерфейса (angular 8). Из pom. xml Я удалил все зависимости от внешнего интерфейса (тимили), но теперь мне интересно, как сохранить аутентификацию mongodb. Теперь у меня есть эта конфигурация без API входа в систему ani:
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, proxyTargetClass = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationConfiguration authenticationConfiguration;
@Autowired
private UserServices userServices;
@Configuration
protected static class AuthenticationConfiguration implements
AuthenticationProvider {
static final Logger LOG = LoggerFactory.getLogger(AuthenticationConfiguration.class);
@Autowired
private UserDetailsService userDetailsService;
@Override
public Authentication authenticate(Authentication authentication) {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
if (name == null || name.isEmpty() || password == null || password.isEmpty())
return null;
UserDetails user = userDetailsService.loadUserByUsername(name);
if (user != null){
Boolean authenticationSuccess = new BCryptPasswordEncoder().matches(password, user.getPassword());
if (authenticationSuccess){
return new UsernamePasswordAuthenticationToken(user, password, user.getAuthorities());
}else {
return null;
}
}else {
return null;
}
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}
@Autowired
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationConfiguration);
}
@Override
public void configure(WebSecurity web) throws Exception {
web
//Spring Security ignores request to static resources such as CSS or JS files.
.ignoring()
.antMatchers("/static/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
List<String> roles = userServices.findAllRole();
//Retrieve array of roles(only string field without id)
String[] rolesArray = roles.toArray(new String[roles.size()]);
http
.authorizeRequests() //Authorize Request Configuration
//the "/" and "/register" path are accepted without login
.antMatchers("/registration/user").authenticated()
//all the path need authentication
.anyRequest().hasAnyRole(rolesArray)//.authenticated()
.and()//Login Form configuration for all others
.formLogin()
.loginPage("/login").defaultSuccessUrl("/#!/sap", true)
//important because otherwise it goes in a loop because login page require authentication and authentication require login page
.permitAll()
.and()
//redirect on page "registration" if user doens't exist in DART database
.exceptionHandling().accessDeniedPage("/registration")
.and()
.logout()
.logoutSuccessUrl("/login?logout")
.deleteCookies("JSESSIONID", "JSESSIONID")
.invalidateHttpSession(true)
.permitAll();
}
}
Мне нужен API входа в систему, где передаются имя пользователя и пароль, и этот API должен вернуть токен. Так как он мне нужен только временно, тогда SSO будет реализован, есть ли способ сделать это? Спасибо