Compare commits
1 Commits
2f70cc687a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be48853e0e |
@@ -49,6 +49,7 @@ public class SecurityConfig {
|
||||
.requestMatchers(HttpMethod.POST, "/api/usuarios/registrar").permitAll()
|
||||
.requestMatchers("/api/usuarios/**").permitAll()
|
||||
.requestMatchers("/favicon.ico", "/error", "/static/**", "/contador/**").permitAll()
|
||||
.requestMatchers("/panel", "/panel/**").permitAll()
|
||||
.requestMatchers("/admin/**").hasAuthority("ADMIN")
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.example.fercoganbackend.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.resource.PathResourceResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Configuration
|
||||
public class SpaPanelConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/panel/**")
|
||||
.addResourceLocations("classpath:/static/panel/")
|
||||
.resourceChain(true)
|
||||
.addResolver(new PathResourceResolver() {
|
||||
@Override
|
||||
protected Resource getResource(String resourcePath, Resource location) throws IOException {
|
||||
Resource requested = location.createRelative(resourcePath);
|
||||
if (requested.exists() && requested.isReadable()) {
|
||||
return requested;
|
||||
}
|
||||
return new ClassPathResource("/static/panel/index.html");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.fercoganbackend.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.persistence.*;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -10,6 +11,7 @@ public class Usuario {
|
||||
private Long id;
|
||||
|
||||
private String username;
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String password;
|
||||
|
||||
@Column(nullable = false)
|
||||
|
||||
@@ -38,13 +38,17 @@ public class UsuarioDetailsService implements UserDetailsService {
|
||||
logger.info("Usuario encontrado: {}, aprobado: {}", usuario.getUsername(), usuario.isAprobado());
|
||||
logger.info("Roles del usuario: {}", usuario.getRoles());
|
||||
|
||||
var authorities = usuario.getRoles() == null
|
||||
? List.<SimpleGrantedAuthority>of()
|
||||
: usuario.getRoles().stream()
|
||||
.map(r -> new SimpleGrantedAuthority(r.name()))
|
||||
.toList();
|
||||
|
||||
return new org.springframework.security.core.userdetails.User(
|
||||
usuario.getUsername(),
|
||||
usuario.getPassword(),
|
||||
usuario.isAprobado(), true, true, true,
|
||||
usuario.getRoles().stream()
|
||||
.map(r -> new SimpleGrantedAuthority(r.name()))
|
||||
.toList()
|
||||
authorities
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
0
src/main/resources/static/panel/.gitkeep
Normal file
0
src/main/resources/static/panel/.gitkeep
Normal file
Reference in New Issue
Block a user