Skip to content

Instantly share code, notes, and snippets.

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.logout().disable();
http.formLogin().disable();
// ...
}
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().disable();
// ...
}
}
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.anonymous().disable();
// ...
}
}
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// ...
http.authorizeRequests()
.antMatchers(HttpMethod.GET).access("#oauth2.hasScope('get')")
.antMatchers(HttpMethod.POST).access(""#oauth2.hasScope('post')"")
@artem-smotrakov
artem-smotrakov / SecurityConfig.java
Last active October 10, 2018 13:59
Example of security config for a Spring-based RESTful application, see more in https://blog.gypsyengineer.com/en/security/tips-configuring-security-rest-api-spring.html
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.rememberMe().disable();
http.authorizeRequests()
.antMatchers("/api/foo").hasRole("bar")
.antMatchers("/api/bat").hasRole("foo")
@artem-smotrakov
artem-smotrakov / SecurityConfig.java
Last active October 10, 2018 13:59
Disable creating a default user with random password in Spring, see more in https://blog.gypsyengineer.com/en/security/tips-configuring-security-rest-api-spring.html
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// ...
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
package com.gypsyengineer.jackson.unsafe.one;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
public class SaferPersonDeserialization {
private static final String bad =
package com.gypsyengineer.jackson.unsafe.one;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import java.io.Serializable;
public class Person {
public String name;
public int age;
@artem-smotrakov
artem-smotrakov / ClassicSwitchStatement.java
Last active March 7, 2020 16:06
An example of a switch statement with enum in Java
public class ClassicSwitchStatement {
enum Person {
Mozart, Picasso, Goethe, Dostoevsky, Prokofiev, Dali
}
public static void main(String[] args) {
print(Person.Mozart);
print(Person.Dali);
print(Person.Dostoevsky);
@artem-smotrakov
artem-smotrakov / WhoIsWho.java
Created March 7, 2020 16:26
An example of the new switch expressions in Java 14
public class WhoIsWho {
enum Person {
Mozart, Picasso, Goethe, Dostoevsky, Prokofiev, Dali
}
public static void main(String[] args) {
print(Person.Mozart);
print(Person.Dali);
print(Person.Dostoevsky);