Skip to content

Commit 97f704c

Browse files
author
Christian Wansart
committed
add Dockerfile
1 parent 8869c8a commit 97f704c

File tree

9 files changed

+76
-52
lines changed

9 files changed

+76
-52
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM eclipse-temurin:21-jre-alpine
2+
3+
RUN addgroup -S spring && adduser -S spring -G spring
4+
USER spring:spring
5+
6+
ARG JAR_FILE=build/libs/unipoll-1.0.0.jar
7+
COPY ${JAR_FILE} app.jar
8+
9+
EXPOSE 8080
10+
ENTRYPOINT [ "java", "-jar", "/app.jar" ]

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.3.1'
3+
id 'org.springframework.boot' version '3.3.2'
44
id 'io.spring.dependency-management' version '1.1.5'
55
}
66

@@ -23,12 +23,13 @@ dependencies {
2323
implementation 'org.springframework.boot:spring-boot-starter-web'
2424
implementation 'org.springframework.boot:spring-boot-starter-security'
2525
developmentOnly 'org.springframework.boot:spring-boot-devtools'
26-
runtimeOnly 'com.h2database:h2'
27-
// runtimeOnly 'org.postgresql:postgresql'
26+
//runtimeOnly 'com.h2database:h2'
27+
runtimeOnly 'org.postgresql:postgresql'
2828
testImplementation 'org.springframework.boot:spring-boot-starter-test'
2929
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
3030
}
3131

3232
tasks.named('test') {
3333
useJUnitPlatform()
3434
}
35+

src/main/java/de/cwansart/unipoll/AuthService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
@Component
99
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
1010
public class AuthService {
11-
private final String storedPassword = "$2a$10$r9rH7cW8tIOJnzPX81SyOOTlAM0xNMPUf/Jvqr2IMEHpyuqN.lj8y";
11+
private static final String passwordHash = "$2a$10$r9rH7cW8tIOJnzPX81SyOOTlAM0xNMPUf/Jvqr2IMEHpyuqN.lj8y";
12+
1213
private boolean isAuthenticated = false;
1314

1415
public boolean isAuthenticated() {
1516
return isAuthenticated;
1617
}
1718

1819
public boolean login(String password) {
19-
isAuthenticated = BCrypt.checkpw(password, storedPassword);
20+
isAuthenticated = BCrypt.checkpw(password, passwordHash);
2021
return this.isAuthenticated;
2122
}
2223
}

src/main/java/de/cwansart/unipoll/CreateController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public String doCreate(@ModelAttribute("createForm") CreateForm createForm, Mode
6969

7070
Poll poll = new Poll();
7171
poll.setName(createForm.getName());
72-
poll.setChoices(topics.stream().map(t -> new Choice(t)).collect(Collectors.toList()));
72+
poll.setChoices(topics.stream().map(t -> new UChoice(t)).collect(Collectors.toList()));
7373
poll = repo.save(poll);
7474
return "redirect:/vote?id=" + poll.getId();
7575
}

src/main/java/de/cwansart/unipoll/Poll.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Poll {
1919
private String name;
2020

2121
@OneToMany(cascade = CascadeType.ALL)
22-
private List<Choice> choices;
22+
private List<UChoice> choices;
2323

2424
private boolean deleted;
2525

@@ -30,10 +30,10 @@ public void setId(Long id) {
3030
this.id = id;
3131
}
3232

33-
public List<Choice> getChoices() {
33+
public List<UChoice> getChoices() {
3434
return choices;
3535
}
36-
public void setChoices(List<Choice> choices) {
36+
public void setChoices(List<UChoice> choices) {
3737
this.choices = choices;
3838
}
3939

src/main/java/de/cwansart/unipoll/Choice.java renamed to src/main/java/de/cwansart/unipoll/UChoice.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
import jakarta.persistence.GenerationType;
66
import jakarta.persistence.Id;
77

8+
// for some reason compilation fails when this class is just called "Choice"
89
@Entity
9-
public class Choice {
10+
public class UChoice {
1011
@Id @GeneratedValue(strategy = GenerationType.AUTO)
1112
private Long id;
1213

1314
private String name;
1415

15-
public Choice() {}
16-
public Choice(String name) {
16+
public UChoice() {}
17+
public UChoice(String name) {
1718
this.name = name;
1819
}
1920

src/main/java/de/cwansart/unipoll/Vote.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class Vote {
1616
private Long id;
1717

1818
@ManyToAny
19-
private List<Choice> choices;
19+
private List<UChoice> choices;
2020

2121
@ManyToOne
2222
private Poll poll;
@@ -30,10 +30,10 @@ public void setId(Long id) {
3030
this.id = id;
3131
}
3232

33-
public List<Choice> getChoices() {
33+
public List<UChoice> getChoices() {
3434
return choices;
3535
}
36-
public void setChoices(List<Choice> choices) {
36+
public void setChoices(List<UChoice> choices) {
3737
this.choices = choices;
3838
}
3939

src/main/java/de/cwansart/unipoll/VoteController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public String save(
9999
}
100100

101101
// check if selected ids belong to the given poll
102-
List<Choice> choices = new ArrayList<>();
102+
List<UChoice> choices = new ArrayList<>();
103103
for(String s: voteForm.getSelected()) {
104104
long sLong = Long.parseLong(s);
105-
Optional<Choice> choice = poll.get().getChoices().stream().filter(t -> t.getId().equals(sLong)).findFirst();
105+
Optional<UChoice> choice = poll.get().getChoices().stream().filter(t -> t.getId().equals(sLong)).findFirst();
106106
if (choice.isPresent()) {
107107
choices.add(choice.get());
108108
} else {
Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
11
spring.application.name=unipoll
22

3-
spring.datasource.url=jdbc:h2:mem:testdb;MODE=PostgreSQL;
4-
spring.datasource.driverClassName=org.h2.Driver
5-
spring.datasource.username=sa
6-
spring.datasource.password=password
7-
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
8-
9-
spring.jpa.show-sql=true
10-
spring.jpa.properties.hibernate.format_sql=true
11-
logging.level.org.hibernate.SQL=DEBUG
12-
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
13-
logging.level.org.hibernate.orm.jdbc.bind=TRACE
14-
logging.level.org.hibernate.type=TRACE
15-
16-
logging.level.org.hibernate=info
17-
# Statistics and slow queries
18-
logging.level.org.hibernate.stat=debug
19-
logging.level.org.hibernate.SQL_SLOW=info
20-
# 2nd Level Cache
21-
logging.level.org.hibernate.cache=debug
22-
# Direct log messages to stdout
23-
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
24-
log4j.appender.stdout.Target=System.out
25-
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
26-
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
27-
# Root logger option
28-
log4j.rootLogger=INFO, stdout
29-
# Hibernate logging options (INFO only shows startup messages)
30-
log4j.logger.org.hibernate=INFO
31-
# Log JDBC bind parameter runtime arguments
32-
log4j.logger.org.hibernate.type=trace
33-
34-
spring.h2.console.enabled=true
35-
spring.h2.console.path=/h2-console
36-
spring.h2.console.settings.trace=false
37-
spring.h2.console.settings.web-allow-others=false
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
#spring.datasource.url=jdbc:h2:mem:testdb;MODE=PostgreSQL;
15+
#spring.datasource.driverClassName=org.h2.Driver
16+
#spring.datasource.username=sa
17+
#spring.datasource.password=password
18+
#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
19+
#
20+
#spring.jpa.show-sql=true
21+
#spring.jpa.properties.hibernate.format_sql=true
22+
#logging.level.org.hibernate.SQL=DEBUG
23+
#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
24+
#logging.level.org.hibernate.orm.jdbc.bind=TRACE
25+
#logging.level.org.hibernate.type=TRACE
26+
#
27+
#logging.level.org.hibernate=info
28+
## Statistics and slow queries
29+
#logging.level.org.hibernate.stat=debug
30+
#logging.level.org.hibernate.SQL_SLOW=info
31+
## 2nd Level Cache
32+
#logging.level.org.hibernate.cache=debug
33+
## Direct log messages to stdout
34+
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
35+
#log4j.appender.stdout.Target=System.out
36+
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
37+
#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
38+
## Root logger option
39+
#log4j.rootLogger=INFO, stdout
40+
## Hibernate logging options (INFO only shows startup messages)
41+
#log4j.logger.org.hibernate=INFO
42+
## Log JDBC bind parameter runtime arguments
43+
#log4j.logger.org.hibernate.type=trace
44+
#
45+
#spring.h2.console.enabled=true
46+
#spring.h2.console.path=/h2-console
47+
#spring.h2.console.settings.trace=false
48+
#spring.h2.console.settings.web-allow-others=false

0 commit comments

Comments
 (0)