Java
- 3 ответа
- 0 вопросов
3
Вклад в тег
role should not start with 'ROLE_' since it is automatically inserted. Got 'ROLE_ADMIN'
private static String hasAnyRole(String... authorities) {
String anyAuthorities = StringUtils.arrayToDelimitedString(authorities, "','ROLE_");
return "hasAnyRole('ROLE_" + anyAuthorities + "')";
}
private static String hasRole(String role) {
Assert.notNull(role, "role cannot be null");
if (role.startsWith("ROLE_")) {
throw new IllegalArgumentException("role should not start with 'ROLE_' since it is automatically inserted. Got '" + role + "'");
}
return "hasRole('ROLE_" + role + "')";
}
http.
authorizeRequests()
.antMatchers("/", "/login").permitAll()
.antMatchers("welcome").hasAnyRole("USER", "ADMIN")
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated() //TODO Розобраться что это-такое
.and()
.formLogin()
.loginPage("/login").failureUrl("/login?error")
.defaultSuccessUrl("/welcome")
.usernameParameter("username")
.passwordParameter("password")
.and().logout()
.logoutSuccessUrl("/login?logout");