Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 51 additions & 36 deletions cadastral/.gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
mvnw
mvnw.cmd
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

src/main/resources/static/
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
mvnw
mvnw.cmd
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

src/main/resources/static/

### Arquivos de log ###
*.log
*.tmp
*.bak

### Arquivos de configuração local ###
.env
*.properties
*.yml
*.yaml

### Sistema operacional ###
Thumbs.db
.DS_Store
6 changes: 6 additions & 0 deletions cadastral/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>3.0.0</version>
</dependency>


</dependencies>
<dependencyManagement>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.unipampa.crud.config;

import com.mongodb.client.MongoClients;
import com.unipampa.crud.enums.UserType;
import io.github.cdimascio.dotenv.Dotenv;
import org.bson.Document;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.List;

@Configuration
public class MongoScriptInitializer implements CommandLineRunner {

private final PasswordEncoder passwordEncoder;
private final Dotenv dotenv = Dotenv.load();

public MongoScriptInitializer(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
}


@Override
public void run(String... args) throws Exception {
System.out.println("Verificando se os dados já existem no banco...");

try (var client = MongoClients.create("mongodb://localhost:27017")) {
var database = client.getDatabase("cadastral");
var roleCollection = database.getCollection("role");
var userCollection = database.getCollection("user");


long count = roleCollection.countDocuments();

if (count == 0) {
System.out.println("Dados não encontrados, criando inicialização...");

roleCollection.insertMany(List.of(
new Document("_id", "65f3c89d-8f45-4732-9021-f84d559d6a12").append("roleName", "ROLE_HOST"),
new Document("_id", "65f3c89d-8f45-4732-9021-f84d559d6a13").append("roleName", "ROLE_GUEST"),
new Document("_id", "65f3c89d-8f45-4732-9021-f84d559d6a14").append("roleName", "ROLE_ADMINISTRATOR")
));

System.out.println("Dados de inicialização criados com sucesso!");
} else {
System.out.println("Dados já existem no banco. Inicialização não necessária.");
}

// Inicializar usuários
long userCount = userCollection.countDocuments();

if (userCount == 0) {
System.out.println("Usuários não encontrados, criando inicialização...");

userCollection.insertMany(List.of(
new Document("_id", "admin-1")
.append("userName", dotenv.get("ADMIN1_USERNAME"))
.append("password", passwordEncoder.encode(dotenv.get("ADMIN1_PASSWORD"))) // Senha criptografada
.append("roles", UserType.ROLE_ADMINISTRATOR),

new Document("_id", "admin-2")
.append("userName", dotenv.get("ADMIN2_USERNAME"))
.append("password", passwordEncoder.encode(dotenv.get("ADMIN2_PASSWORD"))) // Senha criptografada
.append("roles", UserType.ROLE_ADMINISTRATOR)
));

System.out.println("Usuários criados com sucesso!");
} else {
System.out.println("Usuários já existem no banco. Inicialização de usuários não necessária.");
}


} catch (Exception e) {
System.err.println("Erro ao inicializar o MongoDB: " + e.getMessage());
}
}
}
12 changes: 12 additions & 0 deletions cadastral/src/main/resources/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Variáveis relacionadas ao MongoDB
ADMIN1_USERNAME=samuel
ADMIN1_PASSWORD=123456

ADMIN2_USERNAME=denner
ADMIN2_PASSWORD=123456

ADMIN2_USERNAME=basso
ADMIN2_PASSWORD=123456

ADMIN2_USERNAME=auri
ADMIN2_PASSWORD=123456
21 changes: 6 additions & 15 deletions cadastral/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# SONAR LOCAL: mvn clean verify sonar:sonar -Dsonar.projectKey=Imovato -Dsonar.host.url=http://localhost:9000 -Dsonar.login=sqp_8065f01e13e240636a05812095cc3af86e62507c
server:
port: ${PORT:0}
servlet:
context-path:
port: 8585

spring:
jpa:
Expand All @@ -17,22 +15,15 @@ spring:
mongodb:
host: localhost
port: 27017
database: crud-service
database: cadastral
auto-index-creation: true
mongodb:
embedded:
version: 4.0.21
sql:
init:
mode: always
schema-locations: classpath:db/init-mongo.js


rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
username: un_user
password: un_user

crud:
rabbitmq:
Expand All @@ -45,8 +36,8 @@ crud:

ead:
serviceRegistry:
username: admin
password: '123456'
username: un_user
password: 'un_user'

eureka:
client:
Expand Down
2 changes: 1 addition & 1 deletion cadastral/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

spring:
application:
name: CrudService
name: cadastral
profiles:
active: dev
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
@Bean
public UserDetailsService userDetailsService(PasswordEncoder encoder) {
UserDetails user = User.builder()
.username("admin")
.password(encoder.encode("123456"))
.username("un_user")
.password(encoder.encode("un_user"))
.roles("ADMIN")
.build();

Expand Down
12 changes: 9 additions & 3 deletions discovery/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ server:
spring:
application:
name: discovery
data:
mongodb:
host: localhost
port: 27017
database: cadastral
username: un_user
password: un_user
auto-index-creation: true

ead:
serviceRegistry:
Expand All @@ -13,6 +21,4 @@ ead:
eureka:
client:
registerWithEureka: false
fetchRegistry: false
service-url:
defaultZone: 'http://${ead.serviceRegistry.username}:${ead.serviceRegistry.password}@localhost:8761/eureka'
fetchRegistry: false
12 changes: 0 additions & 12 deletions rent/src/main/java/com/example/rent/RentApplication.java

This file was deleted.

29 changes: 0 additions & 29 deletions rent/src/main/java/com/example/rent/entities/Payment.java

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading