Skip to content
Snippets Groups Projects
Commit 84d28389 authored by Ondřej Trojan's avatar Ondřej Trojan
Browse files

integration with postgres

parent c1b7bde7
No related branches found
No related tags found
No related merge requests found
Showing
with 220 additions and 49 deletions
FROM openjdk:12-alpine
VOLUME /tpm
ARG JAR_FILE=target/5d-projection.jar
ARG JAR_FILE=target/5d-backend.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-Djava.com.museum.projection.security.egd=file:/dev/./urandom","-jar","/app.jar"]
......
......@@ -2,14 +2,31 @@
This repository uses
Spring Boot
(MySQL)
(postgres)
## Getting started
### Using docker
First generate .jar file as is shown in Dockerfile. Then run as follows:
Spring boot requires running postgres db. For initial start run as stated below
```docker run --name 5d-postgres-manual -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres:alpine```
Then just start with
```docker start 5d-postgres-manual```
For the first time, you need to create a database. Connect to running container with
```docker exec -it 5d-postgres-manual bash```
and in container connecto to postgres
```psql -U postgres```
and run SQL command
```CREATE DATABASE projection;```
Then generate .jar file as is shown in Dockerfile. Then run as follows:
```
docker build -t spring .
&& docker run
......@@ -19,7 +36,9 @@ docker build -t spring .
spring
```
### Running VLC Instances
The server application requires running instances of VLC with RC interface. Such application is available at
https://gitlab.fel.cvut.cz/trojaond/5d.git
\ No newline at end of file
https://gitlab.fel.cvut.cz/trojaond/5d.git
......@@ -38,14 +38,30 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
</dependency>
<!-- JDBC-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<!-- END JDBC-->
<!-- JWT-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
......
Manifest-Version: 1.0
Main-Class: com.museum.projection.Application
package com.museum.projection.controller;
import com.museum.projection.models.ControlEntity;
import com.museum.projection.model.ControlEntity;
import com.museum.projection.service.ControlService;
import com.museum.projection.service.ResponseService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
......
package com.museum.projection.dao;
import com.museum.projection.model.Account;
import com.museum.projection.security.ApplicationUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import static com.museum.projection.security.ApplicationUserRole.*;
@Repository("postgres")
public class PostgresApplicationUserDaoService implements ApplicationUserDao {
private final PasswordEncoder passwordEncoder;
private final JdbcTemplate jdbcTemplate;
@Autowired
public PostgresApplicationUserDaoService(PasswordEncoder passwordEncoder, JdbcTemplate jdbcTemplate) {
this.passwordEncoder = passwordEncoder;
this.jdbcTemplate = jdbcTemplate;
}
@Override
public Optional<ApplicationUser> selectApplicationUserByUsername(String username) {
return getApplicationUsers()
.stream()
.filter(applicationUser -> username.equals(applicationUser.getUsername()))
.findFirst();
}
private List<ApplicationUser> getApplicationUsers() {
List<ApplicationUser> applicationUsers = getAccounts().stream().map(x -> new ApplicationUser(
ADMIN.getGrantedAuthorities(),
x.getPassword(),
x.getUsername(),
true,
true,
true,
true)).collect(Collectors.toList());
return applicationUsers;
}
private List<Account> getAccounts() {
final String sql = "SELECT id, username, password FROM account";
List<Account> accounts = jdbcTemplate.query(sql, (resultSet, i) -> {
UUID id = UUID.fromString(resultSet.getString("id"));
String name = resultSet.getString("username");
String password = resultSet.getString("password");
return new Account(id, name, password);
});
return accounts;
}
}
\ No newline at end of file
package com.museum.projection.datasource;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class PostgresDatasource {
@Bean
@ConfigurationProperties("app.datasource")
public HikariDataSource hikariDataSource(){
return DataSourceBuilder
.create()
.type(HikariDataSource.class)
.build();
}
}
package com.museum.projection.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import javax.validation.constraints.NotBlank;
import java.util.UUID;
public class Account {
private final UUID id;
@NotBlank
private final String username;
@NotBlank
private final String password;
public Account(@JsonProperty("id") UUID id, @JsonProperty("username") String username, @JsonProperty("password") String password) {
this.id = id;
this.username = username;
this.password = password;
}
public UUID getId() {
return id;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}
package com.museum.projection.models;
package com.museum.projection.model;
import com.fasterxml.jackson.annotation.JsonProperty;
......
......@@ -56,9 +56,9 @@ public class ApplicationSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/signin", "/", "index", "/css/*", "/js/*").permitAll()
.antMatchers("/api/**").hasRole(ADMIN.name())
.anyRequest()
.authenticated()
.and()
.exceptionHandling().accessDeniedPage("/error");
.authenticated();
//.and()
//.exceptionHandling().accessDeniedPage("/error");
}
......
......@@ -14,7 +14,7 @@ public class ApplicationUserService implements UserDetailsService {
private final ApplicationUserDao applicationUserDao;
@Autowired
public ApplicationUserService(@Qualifier("fake") ApplicationUserDao applicationUserDao) {
public ApplicationUserService(@Qualifier("postgres") ApplicationUserDao applicationUserDao) {
this.applicationUserDao = applicationUserDao;
}
......
spring.datasource.url=jdbc:mysql://localhost:3306/restapi
spring.datasource.username=root
spring.datasource.password=
#spring.thymeleaf.cache=false
spring.task.scheduling.pool.size=10
spring.task.scheduling.shutdown.await-termination=true
################5D-projection-config###################
5d.videoFolderPath = /home/user/vid/
5d.scheduling.enabled=false
5d.client1ip=127.0.0.1
5d.client2ip=127.0.0.1
5d.client1port=5041
5d.client2port=5051
#5d.connection-maintain-interval=1000
#5d.init-interval=400
#5d.socket-timeout=200
################5D-projection-security###################
5d.security.jwt.secretKey=xtdW9ESxOhiglXIO6yj0sY7gX55Sz4195KRnkMCpd2HpFA6aQXHnhJGwGBS9G5HUXjjrkzefu2tQczABCQhWlgbQX3QxTSWuADO99lc77Yt3KRieEbVZNWb1
5d.security.jwt.tokenPrefix=Bearer
5d.security.jwt.tokenExpirationAfterDays=10
\ No newline at end of file
app:
datasource:
jdbc-url: jdbc:postgresql://localhost:5432/projection
username: postgres
password: password
poll-size: 30
spring:
task:
scheduling:
pool:
size: 10
shudown:
await-termination: true
thymeleaf:
#cache: false
################5D-projection-config###################
5d:
videoFolderPath: /home/user/vid/
scheduling:
enabled: false
client1ip: 127.0.0.1
client2ip: 127.0.0.1
client1port: 5041
client2port: 5051
################5D-projection-security###################
security:
jwt:
secretKey: xtdW9ESxOhiglXIO6yj0sY7gX55Sz4195KRnkMCpd2HpFA6aQXHnhJGwGBS9G5HUXjjrkzefu2tQczABCQhWlgbQX3QxTSWuADO99lc77Yt3KRieEbVZNWb1
tokenPrefix: Bearer
tokenExpirationAfterDays: 10
DROP TABLE IF EXISTS account;
CREATE TABLE account (
id UUID NOT NULL PRIMARY KEY,
username VARCHAR(100) NOT NULL,
password VARCHAR(100) NOT NULL
);
CREATE EXTENSION "uuid-ossp";
INSERT INTO account (id,username,password) VALUES (uuid_generate_v4(),'admin','$2a$10$2DAipSvgd75ir6BZ3a7NiOHRwi5sEWr9AP5yDO65034aZjZnc2f8e');
......@@ -52,7 +52,7 @@ console.log(event)
})
event.preventDefault();
}
a
form.addEventListener("submit", formLogin);
......
......@@ -16,7 +16,7 @@
<h1>
Oops!</h1>
<h2>
403 Not Authorized</h2>
Error</h2>
<div class="error-details">
Sorry, an error has occured, Requested page unauthorized!
</div>
......
......@@ -25,8 +25,8 @@
</div>
<div class="container">
<h1 class="display-4">5D projection monitor</h1>
<h2>Basic operations</h2>
<h1 class="display-4">5D projection monitor edited</h1>
<h2>Basic operations :)</h2>
<p class="lead">Here you can perform basics testing and monitoring, it serves as a secondary tool for control.</p>
<button id="play" type="button" class="btn btn-primary">Play</button>
<button id="pause" type="button" class="btn btn-primary">Pause</button>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment