Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue 17 #19

Merged
merged 3 commits into from
Aug 27, 2020
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
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.liquibase:liquibase-core'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'io.r2dbc:r2dbc-postgresql'
runtimeOnly 'org.postgresql:postgresql'
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/su/svn/daybook/domain/security/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This file was last modified at 2020.08.27 08:34 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* Role.java
* $Id$
*/

package su.svn.daybook.domain.security;

public enum Role {
ROLE_USER, ROLE_ADMIN
}
84 changes: 84 additions & 0 deletions src/main/java/su/svn/daybook/domain/security/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* This file was last modified at 2020.08.27 08:34 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* User.java
* $Id$
*/

package su.svn.daybook.domain.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
@NoArgsConstructor
public class User implements UserDetails {

private String username;
private String password;

@Getter
@Setter
private Boolean enabled;

@Getter
@Setter
private List<Role> roles;

public User(String username) {
this.username = username;
}

@Override
public boolean isAccountNonExpired() {
return false;
}

@Override
public boolean isAccountNonLocked() {
return false;
}

@Override
public boolean isCredentialsNonExpired() {
return false;
}

@Override
public boolean isEnabled() {
return this.enabled;
}

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return this.roles.stream().map(authority -> new SimpleGrantedAuthority(authority.name())).collect(Collectors.toList());
}

@Override
public String getUsername() {
return username;
}

@JsonIgnore
@Override
public String getPassword() {
return password;
}

@JsonProperty
public void setPassword(String password) {
this.password = password;
}
}
1 change: 1 addition & 0 deletions src/main/java/su/svn/daybook/services/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package su.svn.daybook.services;
29 changes: 29 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
application:
db:
username: ${DB_USER:dbuser}
password: ${DB_PASS:password}
r2dbc:
host-rw: ${MASTER_DB_HOST:localhost}
host-ro: ${CLUSTER_DB_HOST:localhost}
port-rw: ${MASTER_DB_PORT:3306}
port-ro: ${CLUSTER_DB_PORT:3306}
database: ${DB_NAME:db}
pool:
connect-timeout: 500
duration: 30000
validation-depth: REMOTE
validation-query: "SELECT 1"
reactive:
buffer-size: 128
duration: 30000
limit: 1000
security:
strength: 12

logging:
level:
ROOT: INFO
Expand All @@ -7,3 +29,10 @@ spring:
url: r2dbc:postgresql://localhost/db
username: dbuser
password: password

springbootwebfluxjjwt:
password:
encoder:
secret: mysecret
iteration: 33
keylength: 256