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");
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try (Connection con = ds.getConnection()) {
// применяете
}
}
int Sum(int a, int b)
{ return a+b; }
double Sum(double a, double b)
{ return a+b; }
class A
{
virtual ~A(){}
virtual char* Name() { return "Class A"; }
};
class B
{
virtual char* Name() { return "Class B"; }
};
void main()
{
A* a1 = new A;
A * a2 = new B;
cout << a1->Name(); // Class A
cout << a2->Name(); // Class B
}
class Test {
public static void main(String[] args) {
LongHolder holder = new LongHolder(0L);
System.out.println(holder);
updateValue(holder, 150L);
System.out.println(holder);
}
private static void updateValue(LongHolder holder, Long newValue) {
holder.setValue(newValue);
}
private static class LongHolder{
private Long value;
public LongHolder(Long value) {
this.value = value;
}
public Long getValue() {
return value;
}
public void setValue(Long value) {
this.value = value;
}
@Override
public String toString() {
return "LongHolder{" +
"value=" + value +
'}';
}
}
}