Skip to content

Instantly share code, notes, and snippets.

@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();
@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")
@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')"")
@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.httpBasic().disable();
// ...
}
}
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.logout().disable();
http.formLogin().disable();
// ...
}
@artem-smotrakov
artem-smotrakov / SecurityConfig.java
Last active October 10, 2018 14:01
Disabling built-in session management in Spring Boot config, 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.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// ...
}
@artem-smotrakov
artem-smotrakov / ChannelSecurityConfig.java
Last active October 10, 2018 14:01
Enforcing HTTPS and enabling HSTS header in Spring security config, see more in https://blog.gypsyengineer.com/en/security/tips-configuring-security-rest-api-spring.html
@Configuration
@EnableWebSecurity
public class ChannelSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requiresChannel().anyRequest().requiresSecure();
http.headers().httpStrictTransportSecurity();
// ...
}
import dht
import machine
try:
import usocket as socket
except:
import socket
import ussl as ssl
# a template of HTTP request to ThingSpeak to post temperature and humidity
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 =