mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 08:58:48 +00:00
añadidor los ficheros que faltaban en el commit anterior
This commit is contained in:
@ -0,0 +1,65 @@
|
||||
package com.imprimelibros.erp.config;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
||||
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Configuration
|
||||
public class InternationalizationConfig implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public LocaleResolver localeResolver() {
|
||||
SessionLocaleResolver slr = new SessionLocaleResolver();
|
||||
slr.setDefaultLocale(Locale.of("es"));
|
||||
return slr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
|
||||
interceptor.setParamName("lang");
|
||||
registry.addInterceptor(interceptor);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageSource messageSource() throws IOException {
|
||||
ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
|
||||
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
Resource[] resources = resolver.getResources("classpath*:i18n/*.properties");
|
||||
|
||||
// Extraer los nombres base sin extensión ni sufijos (_en, _es, etc.)
|
||||
Set<String> basenames = Arrays.stream(resources)
|
||||
.map(res -> {
|
||||
try {
|
||||
String uri = Objects.requireNonNull(res.getURI()).toString();
|
||||
// Ej: file:/.../i18n/login_en.properties
|
||||
String path = uri.substring(uri.indexOf("/i18n/") + 1); // i18n/login_en.properties
|
||||
String base = path.replaceAll("_[a-z]{2}\\.properties$", "") // login.properties
|
||||
.replaceAll("\\.properties$", "");
|
||||
return "classpath:" + base;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
source.setBasenames(basenames.toArray(new String[0]));
|
||||
source.setDefaultEncoding("UTF-8");
|
||||
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.imprimelibros.erp.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/", "/assets/**", "/css/**", "/js/**", "/images/**", "/public/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.formLogin(login -> login
|
||||
//.loginPage("/login") añadir cuando se tenga login personalizado
|
||||
.permitAll()
|
||||
)
|
||||
.logout(logout -> logout.permitAll());
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.imprimelibros.erp.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
@Autowired
|
||||
private MessageSource messageSource;
|
||||
|
||||
@GetMapping("/")
|
||||
public String index(Model model, Locale locale) {
|
||||
//model.addAttribute("title", messageSource.getMessage("t-home", null, locale));
|
||||
model.addAttribute("title", "Inicio");
|
||||
return "imprimelibros/home";
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.imprimelibros.erp.controller;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
public class LoginController {
|
||||
|
||||
@GetMapping("/login")
|
||||
public String index(Model model, Locale locale) {
|
||||
return "imprimelibros/login/login";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user