viernes, 31 de marzo de 2017

Tutorial gitlab

https://gist.github.com/m-kyle/fb0f3e9edc369adfcac7

miércoles, 29 de marzo de 2017

arrancar aplicación springboot en segundo plano desde unix

nohup java -jar -Dspring.profiles.active=production example-springboot.jar > /dev/null 2>&1 &

miércoles, 15 de marzo de 2017

Spring data rest, HATEOAS exposeIds

Para que las rests HATEOAS muestren los campos id de cada elemento:

 @Component  
 @Slf4j  
 public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter {  
   @Override  
   public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {  
     listMatchingClasses(Entity.class).forEach(entity -> config.exposeIdsFor(entity));  
   }  
   public List<Class> listMatchingClasses(Class annotationClass) {  
     List<Class> classes = new LinkedList<Class>();  
     ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);  
     scanner.addIncludeFilter(new AnnotationTypeFilter(annotationClass));  
     for (BeanDefinition bd : scanner.findCandidateComponents(Project.class.getPackage().getName())) {  
       try {  
         classes.add(Class.forName(bd.getBeanClassName()));  
       } catch (ClassNotFoundException e) {  
         log.error("listMatchingClasses problem", e);  
       }  
     }  
     return classes;  
   }  
 }  

jueves, 2 de marzo de 2017

Spring4, cors, problema con seguridad

 
Paso 1. Añadir una clase de configuración para corsConfigurer: 
 
 
 @Configuration
public class MyConfiguration {

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**");
            }
        };
    }
} 
 
Paso 2. Añadir Clase para seguridad
 
 @EnableWebSecurity
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.antMatcher("/**").authorizeRequests().requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
                .anyRequest().fullyAuthenticated().and().httpBasic().and().csrf().disable();
    }
}