Skip to content
Open
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
5 changes: 5 additions & 0 deletions kanban-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
48 changes: 36 additions & 12 deletions kanban-server/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
baseName = 'ru.otus.spring.hw.kanban'
version = '1.0.0'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
// classpath('gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.13.0')
}
}

Expand All @@ -19,8 +23,9 @@ apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
//apply plugin: 'com.palantir.docker'

group = 'ru.otus.spring.hw'
group = 'otus.spring'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand All @@ -30,24 +35,41 @@ repositories {
}

bootJar {
baseName = 'ru.otus.spring.hw'
version = '0.1.0'
baseName = project.baseName
version = project.version
}

def changeLog = "$projectDir/src/main/resources/db/changelog/db.changelog-master.yaml"

liquibase {
activities {
main {
changeLogFile changeLog
url 'jdbc:h2:file:~/kanban'
username 'sa'
password ''
//liquibase {
// activities {
// main {
// changeLogFile changeLog
// url 'jdbc:h2:file:~/kanban'
// username 'sa'
// password ''
// }
// }
//}

task unpack(type: Copy) {
dependsOn bootJar
from(zipTree(tasks.bootJar.outputs.files.singleFile))
into("build/dependency")
}

task assembleDockerImage {
dependsOn bootJar
doLast {
exec {
workingDir '.'
environment "JAR_FILE", "./build/libs/${baseName}-${version}.jar"
executable "sh"
args "-c", "docker build . -t kanban.server:v1 --build-arg JAR_FILE"
}
}
}


dependencies {
compile('org.springframework.boot:spring-boot-parent:2.0.3.RELEASE')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
Expand All @@ -62,13 +84,15 @@ dependencies {
compile 'org.springframework.security:spring-security-config:5.0.7.RELEASE'
compile 'org.springframework:spring-context-support:5.0.7.RELEASE'
compile 'net.sf.ehcache:ehcache-core:2.6.11'
compile 'org.postgresql:postgresql:42.1.1'


// compile 'org.liquibase:liquibase-core:3.6.2'

compile('org.springframework.boot:spring-boot-starter-data-jpa:1.5.8.RELEASE')
runtime('com.h2database:h2')

// All of your normal project dependencies would be here in addition to...

// liquibaseRuntime 'org.liquibase:liquibase-core:3.6.1'
// liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.0.1'
// liquibaseRuntime 'com.h2database:h2'
Expand Down
18 changes: 18 additions & 0 deletions kanban-server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '2'
services:
kanban:
image: kanban.server:v1
ports:
- "8080:8080"
depends_on:
- db
db:
image: postgres
volumes:
- ~/db:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=12345678
- POSTGRES_USER=postgres
- POSTGRES_DB=kanban
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ public TaskDTO create(TaskDTO newTaskDTO) {

taskRepository.save(task);

final Sid owner = new PrincipalSid(SecurityContextHolder.getContext().getAuthentication());
final Sid admin = new GrantedAuthoritySid("ROLE_ADMIN");
// создать ObjectIdentity для бизнес сущности
final ObjectIdentity oid = new ObjectIdentityImpl(Task.class, task.getId());
// создать пустой ACL
final MutableAcl acl = aclService.createAcl(oid);

// определить владельца сущности и права пользователей
acl.setOwner(owner);
acl.insertAce(acl.getEntries().size(), BasePermission.READ, owner, true);
acl.insertAce(acl.getEntries().size(), BasePermission.ADMINISTRATION, admin, true);
// обновить ACL в БД
aclService.updateAcl(acl);
// final Sid owner = new PrincipalSid(SecurityContextHolder.getContext().getAuthentication());
// final Sid admin = new GrantedAuthoritySid("ROLE_ADMIN");
// // создать ObjectIdentity для бизнес сущности
// final ObjectIdentity oid = new ObjectIdentityImpl(Task.class, task.getId());
// // создать пустой ACL
// final MutableAcl acl = aclService.createAcl(oid);
//
// // определить владельца сущности и права пользователей
// acl.setOwner(owner);
// acl.insertAce(acl.getEntries().size(), BasePermission.READ, owner, true);
// acl.insertAce(acl.getEntries().size(), BasePermission.ADMINISTRATION, admin, true);
// // обновить ACL в БД
// aclService.updateAcl(acl);

return TaskDTO.fromTask(task);
}
Expand Down
24 changes: 16 additions & 8 deletions kanban-server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/kanban
spring.datasource.url=jdbc:postgresql://db:5432/kanban
spring.datasource.username=postgres
spring.datasource.password=12345678

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

server.servlet.context-path=/api

# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:file:~/kanban
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=none
## H2
#spring.h2.console.enabled=true
#spring.h2.console.path=/h2
## Datasource
#spring.datasource.url=jdbc:h2:file:~/kanban
#spring.datasource.username=sa
#spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create
logging.level.org.springframework.security=DEBUG
#server.port=8090
142 changes: 93 additions & 49 deletions kanban-server/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -1,58 +1,102 @@
create table IF NOT EXISTS system_message (id integer not null, content varchar(255), primary key (id));

CREATE TABLE IF NOT EXISTS acl_sid (
id bigint(20) NOT NULL AUTO_INCREMENT,
principal tinyint(1) NOT NULL,
sid varchar(100) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY unique_uk_1 (sid,principal)

create table acl_sid(
id bigserial not null primary key,
principal boolean not null,
sid varchar(100) not null,
constraint unique_uk_1 unique(sid,principal)
);

CREATE TABLE IF NOT EXISTS acl_class (
id bigint(20) NOT NULL AUTO_INCREMENT,
class varchar(255) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY unique_uk_2 (class)
create table acl_class(
id bigserial not null primary key,
class varchar(100) not null,
class_id_type varchar(100),
constraint unique_uk_2 unique(class)
);
CREATE TABLE IF NOT EXISTS acl_entry (
id bigint(20) NOT NULL AUTO_INCREMENT,
acl_object_identity bigint(20) NOT NULL,
ace_order int(11) NOT NULL,
sid bigint(20) NOT NULL,
mask int(11) NOT NULL,
granting tinyint(1) NOT NULL,
audit_success tinyint(1) NOT NULL,
audit_failure tinyint(1) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY unique_uk_4 (acl_object_identity,ace_order)

create table acl_object_identity(
id bigserial primary key,
object_id_class bigint not null,
object_id_identity varchar(36) not null,
parent_object bigint,
owner_sid bigint,
entries_inheriting boolean not null,
constraint unique_uk_3 unique(object_id_class,object_id_identity),
constraint foreign_fk_1 foreign key(parent_object)references acl_object_identity(id),
constraint foreign_fk_2 foreign key(object_id_class)references acl_class(id),
constraint foreign_fk_3 foreign key(owner_sid)references acl_sid(id)
);

CREATE TABLE IF NOT EXISTS acl_object_identity (
id bigint(20) NOT NULL AUTO_INCREMENT,
object_id_class bigint(20) NOT NULL,
object_id_identity bigint(20) NOT NULL,
parent_object bigint(20) DEFAULT NULL,
owner_sid bigint(20) DEFAULT NULL,
entries_inheriting tinyint(1) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY unique_uk_3 (object_id_class,object_id_identity)

create table acl_entry(
id bigserial primary key,
acl_object_identity bigint not null,
ace_order int not null,
sid bigint not null,
mask integer not null,
granting boolean not null,
audit_success boolean not null,
audit_failure boolean not null,
constraint unique_uk_4 unique(acl_object_identity,ace_order),
constraint foreign_fk_4 foreign key(acl_object_identity) references acl_object_identity(id),
constraint foreign_fk_5 foreign key(sid) references acl_sid(id)
);

ALTER TABLE acl_entry
ADD FOREIGN KEY (acl_object_identity) REFERENCES acl_object_identity(id);

ALTER TABLE acl_entry
ADD FOREIGN KEY (sid) REFERENCES acl_sid(id);


-- create table IF NOT EXISTS system_message (id integer not null, content varchar(255), primary key (id));
--
-- Constraints for table acl_object_identity
-- CREATE TABLE IF NOT EXISTS acl_sid (
-- id bigint(20) NOT NULL AUTO_INCREMENT,
-- principal tinyint(1) NOT NULL,
-- sid varchar(100) NOT NULL,
-- PRIMARY KEY (id),
-- UNIQUE KEY unique_uk_1 (sid,principal)
-- );
--
ALTER TABLE acl_object_identity
ADD FOREIGN KEY (parent_object) REFERENCES acl_object_identity (id);

ALTER TABLE acl_object_identity
ADD FOREIGN KEY (object_id_class) REFERENCES acl_class (id);

ALTER TABLE acl_object_identity
ADD FOREIGN KEY (owner_sid) REFERENCES acl_sid (id);
-- CREATE TABLE IF NOT EXISTS acl_class (
-- id bigint(20) NOT NULL AUTO_INCREMENT,
-- class varchar(255) NOT NULL,
-- PRIMARY KEY (id),
-- UNIQUE KEY unique_uk_2 (class)
-- );
--
-- CREATE TABLE IF NOT EXISTS acl_entry (
-- id bigint(20) NOT NULL AUTO_INCREMENT,
-- acl_object_identity bigint(20) NOT NULL,
-- ace_order int(11) NOT NULL,
-- sid bigint(20) NOT NULL,
-- mask int(11) NOT NULL,
-- granting tinyint(1) NOT NULL,
-- audit_success tinyint(1) NOT NULL,
-- audit_failure tinyint(1) NOT NULL,
-- PRIMARY KEY (id),
-- UNIQUE KEY unique_uk_4 (acl_object_identity,ace_order)
-- );
--
-- CREATE TABLE IF NOT EXISTS acl_object_identity (
-- id bigint(20) NOT NULL AUTO_INCREMENT,
-- object_id_class bigint(20) NOT NULL,
-- object_id_identity bigint(20) NOT NULL,
-- parent_object bigint(20) DEFAULT NULL,
-- owner_sid bigint(20) DEFAULT NULL,
-- entries_inheriting tinyint(1) NOT NULL,
-- PRIMARY KEY (id),
-- UNIQUE KEY unique_uk_3 (object_id_class,object_id_identity)
-- );
--
-- ALTER TABLE acl_entry
-- ADD FOREIGN KEY (acl_object_identity) REFERENCES acl_object_identity(id);
--
-- ALTER TABLE acl_entry
-- ADD FOREIGN KEY (sid) REFERENCES acl_sid(id);
--
-- --
-- -- Constraints for table acl_object_identity
-- --
-- ALTER TABLE acl_object_identity
-- ADD FOREIGN KEY (parent_object) REFERENCES acl_object_identity (id);
--
-- ALTER TABLE acl_object_identity
-- ADD FOREIGN KEY (object_id_class) REFERENCES acl_class (id);
--
-- ALTER TABLE acl_object_identity
-- ADD FOREIGN KEY (owner_sid) REFERENCES acl_sid (id);