├── settings.gradle ├── assets ├── communikey-logo-light.svg.png └── communikey-logo-light.svg ├── src ├── test │ └── resources │ │ └── application-test.yml ├── integration-test │ ├── resources │ │ └── application-integration-test.yml │ └── java │ │ └── de │ │ └── communicode │ │ └── communikey │ │ ├── CommunikeyIntegrationTest.java │ │ └── api │ │ ├── ApiRootIt.java │ │ └── AuthorityApiIt.java └── main │ ├── resources │ ├── application-prod.yml │ ├── schema.sql │ ├── application-dev.yml │ ├── log4j2-dev.yml │ ├── log4j2.yml │ ├── banner.txt │ └── application.yaml │ └── java │ └── de │ └── communicode │ └── communikey │ ├── domain │ ├── package-info.java │ ├── Authority.java │ ├── UserEncryptedPassword.java │ ├── AbstractEntity.java │ ├── Tag.java │ ├── EncryptionJob.java │ └── UserGroup.java │ ├── package-info.java │ ├── service │ ├── view │ │ └── AuthoritiesRestView.java │ ├── payload │ │ ├── KeyCategoryMovePayload.java │ │ ├── TagPayload.java │ │ ├── EncryptionJobPayload.java │ │ ├── KeyPayloadEncryptedPasswords.java │ │ ├── EncryptionJobAbortPayload.java │ │ ├── EncryptionJobStatusPayload.java │ │ ├── KeyCategoryPayload.java │ │ ├── UserCreationPayload.java │ │ ├── UserPasswordResetPayload.java │ │ ├── UserCredentialPayload.java │ │ ├── UserPublicKeyResetPayload.java │ │ ├── KeyPayload.java │ │ └── UserPayload.java │ └── AuthorityService.java │ ├── exception │ ├── HashidNotValidException.java │ ├── KeyNotAccessibleByUserException.java │ ├── KeyConflictException.java │ ├── ResetTokenNotFoundException.java │ ├── UserConflictException.java │ ├── AuthorityNotFoundException.java │ ├── UserGroupConflictException.java │ ├── UserNotFoundException.java │ ├── KeyCategoryConflictException.java │ ├── UserNotActivatedException.java │ ├── ActivationTokenNotFoundException.java │ ├── KeyNotFoundException.java │ ├── TagNotFoundException.java │ ├── EncryptionJobNotFoundException.java │ ├── KeyCategoryNotFoundException.java │ ├── UserGroupNotFoundException.java │ ├── UserEncryptedPasswordNotFoundException.java │ ├── TagControllerExceptionHandler.java │ ├── AuthorityControllerExceptionHandler.java │ ├── CrowdEncryptionControllerExceptionHandler.java │ ├── UserGroupControllerExceptionHandler.java │ ├── KeyCategoryControllerExceptionHandler.java │ ├── ErrorResponse.java │ ├── KeyControllerExceptionHandler.java │ └── UserControllerExceptionHandler.java │ ├── security │ ├── AuthoritiesConstants.java │ ├── SecurityAuditorAware.java │ └── RestUserDetailsService.java │ ├── repository │ ├── TagRepository.java │ ├── UserGroupRepository.java │ ├── AuthorityRepository.java │ ├── KeyRepository.java │ ├── KeyCategoryRepository.java │ ├── EncryptionJobRepository.java │ ├── UserEncryptedPasswordRepository.java │ └── UserRepository.java │ ├── config │ ├── DateTimeFormatConfig.java │ ├── MethodSecurityConfig.java │ ├── HashidsConfig.java │ ├── WebSocketConfig.java │ ├── JacksonConfig.java │ ├── util │ │ ├── ApplicationStartup.java │ │ └── DefaultProfileUtil.java │ ├── WebSocketSecurityConfig.java │ ├── CorsFilter.java │ ├── RestViewConfiguration.java │ ├── DataSourceConfig.java │ └── SecurityConfig.java │ ├── controller │ ├── RequestParameter.java │ ├── PathVariables.java │ ├── AuthorityController.java │ └── CrowdEncryptionController.java │ ├── CommunikeyApplication.java │ └── ApplicationDataBootstrap.java ├── .gitignore ├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE │ ├── enhancement.md │ └── bugs.md ├── .editorconfig ├── .mailmap ├── CHANGELOG.md └── README.md /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "communikey" 2 | -------------------------------------------------------------------------------- /assets/communikey-logo-light.svg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/communicode/communikey-backend/HEAD/assets/communikey-logo-light.svg.png -------------------------------------------------------------------------------- /src/test/resources/application-test.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: test 4 | jpa: 5 | hibernate: 6 | ddl-auto: create-drop -------------------------------------------------------------------------------- /src/integration-test/resources/application-integration-test.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: integration-test 4 | jpa: 5 | hibernate: 6 | ddl-auto: create-drop -------------------------------------------------------------------------------- /src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: prod 4 | jpa: 5 | hibernate: 6 | ddl-auto: update 7 | jackson: 8 | serialization: 9 | indent_output: false 10 | devtools: 11 | restart: 12 | enabled: false 13 | livereload: 14 | enabled: false 15 | -------------------------------------------------------------------------------- /src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS oauth_access_token; 2 | 3 | CREATE TABLE IF NOT EXISTS oauth_access_token ( 4 | token_id VARCHAR(255), 5 | token LONG VARBINARY, 6 | authentication_id VARCHAR(255) PRIMARY KEY, 7 | user_name VARCHAR(255), 8 | client_id VARCHAR(255), 9 | authentication LONG VARBINARY, 10 | refresh_token VARCHAR(255) 11 | ) DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # +---------------+ 2 | # + IntelliJ IDEA + 3 | # +---------------+ 4 | .idea 5 | !.idea/runConfigurations 6 | *.iws 7 | *.iml 8 | *.ipr 9 | /out/ 10 | 11 | # +------+ 12 | # + Java + 13 | # +------+ 14 | *.class 15 | *.jar 16 | 17 | # JVM crash logs 18 | # http://www.java.com/en/download/help/error_hotspot.xml 19 | hs_err_pid* 20 | 21 | # +--------+ 22 | # + Gradle + 23 | # +--------+ 24 | .gradle 25 | /build/ 26 | -------------------------------------------------------------------------------- /src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev 4 | jpa: 5 | hibernate: 6 | ddl-auto: create-drop 7 | jackson: 8 | serialization: 9 | indent_output: true 10 | devtools: 11 | restart: 12 | enabled: true 13 | livereload: 14 | enabled: false 15 | output: 16 | ansi: 17 | enabled: always 18 | 19 | logging: 20 | config: classpath:log4j2-dev.yml 21 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Configuration for the GitHub feature to automatically request reviews from the code owners when a pull request changes any owned files. 2 | # 3 | # [References] 4 | # https://github.com/blog/2392-introducing-code-owners 5 | # https://help.github.com/articles/about-codeowners 6 | 7 | # +--------------------+ 8 | # + Default Code Owner + 9 | # +--------------------+ 10 | * @DennisVonDerBey 11 | * @lleifermann 12 | * @svengreb 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | # ++++++++++++++++++++++ 4 | # + Base Configuration + 5 | # ++++++++++++++++++++++ 6 | [*] 7 | charset = utf-8 8 | end_of_line = lf 9 | indent_size = 4 10 | indent_style = space 11 | insert_final_newline = true 12 | max_line_length = 160 13 | trim_trailing_whitespace = true 14 | 15 | # +++++++++++++ 16 | # + Languages + 17 | # +++++++++++++ 18 | # +++ Markdown +++ 19 | [*.{md,gfm}] 20 | trim_trailing_whitespace = false 21 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | # Configuration for Git mail mapping feature to coalesce together commits by the same person in the shortlog, where their name and/or email address was spelled differently. 2 | # 3 | # References: 4 | # https://git-scm.com/docs/git-shortlog#_mapping_authors 5 | Dennis von der Bey 6 | Lauritz Leifermann 7 | Sven Greb 8 | -------------------------------------------------------------------------------- /src/main/resources/log4j2-dev.yml: -------------------------------------------------------------------------------- 1 | Configutation: 2 | status: warn 3 | 4 | Appenders: 5 | Console: 6 | name: CONSOLE 7 | target: SYSTEM_OUT 8 | PatternLayout: 9 | Pattern: "[%highlight{%-5level}] %d{yyyy-MM-dd HH:mm:ss.SSS} <%t> %c{1}: %m%n" 10 | 11 | Loggers: 12 | Root: 13 | level: info 14 | AppenderRef: 15 | - ref: CONSOLE 16 | Logger: 17 | - name: de.communicode.communikey 18 | additivity: false 19 | level: debug 20 | AppenderRef: 21 | - ref: CONSOLE 22 | -------------------------------------------------------------------------------- /src/main/resources/log4j2.yml: -------------------------------------------------------------------------------- 1 | Configutation: 2 | status: warn 3 | 4 | Appenders: 5 | RollingFile: 6 | - name: COMMUNIKEY 7 | fileName: "./logs/communikey.log" 8 | filePattern: "./logs/$${date:yyyy-MM}/my-app-%d{yyyy-MM-dd}-%i.log.gz" 9 | PatternLayout: 10 | Pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} <%t> %c{1}: %m%n" 11 | policies: 12 | TimeBasedTriggeringPolicy: 13 | interval: 1 14 | modulate: true 15 | 16 | Loggers: 17 | Root: 18 | level: warn 19 | AppenderRef: 20 | - ref: COMMUNIKEY 21 | Logger: 22 | - name: de.communicode.communikey 23 | additivity: false 24 | level: info 25 | AppenderRef: 26 | - ref: COMMUNIKEY 27 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/domain/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /** 19 | * JPA domain objects. 20 | * 21 | * @since 0.1.0 22 | */ 23 | package de.communicode.communikey.domain; 24 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /** 19 | * A simple centralized, cross-platform credential manager. 20 | * 21 | *

The application entry point is the {@link de.communicode.communikey.CommunikeyApplication} boot class. 22 | * 23 | * @since 0.1.0 24 | */ 25 | package de.communicode.communikey; 26 | -------------------------------------------------------------------------------- /src/integration-test/java/de/communicode/communikey/CommunikeyIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package de.communicode.communikey; 20 | 21 | /** 22 | * Category marker interface to identify integration tests. 23 | * 24 | * @author sgreb@communicode.de 25 | * @since 0.3.0 26 | */ 27 | public interface CommunikeyIntegrationTest { 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ${AnsiColor.GREEN}${AnsiStyle.BOLD} 2 | .--. 3 | /.-. '----------. 4 | \'-' .--"--""-"-' 5 | '--'${AnsiColor.BLUE}${AnsiStyle.NORMAL} 6 | ██████╗ ██████╗ ${AnsiColor.GREEN}███╗ ███╗███╗ ███╗${AnsiColor.BLUE}██╗ ██╗███╗ ██╗██╗██╗ ██╗███████╗██╗ ██╗ 7 | ██╔════╝██╔═══██╗${AnsiColor.GREEN}████╗ ████║████╗ ████║${AnsiColor.BLUE}██║ ██║████╗ ██║██║██║ ██╔╝██╔════╝╚██╗ ██╔╝ 8 | ██║ ██║ ██║${AnsiColor.GREEN}██╔████╔██║██╔████╔██║${AnsiColor.BLUE}██║ ██║██╔██╗ ██║██║█████╔╝ █████╗ ╚████╔╝ 9 | ██║ ██║ ██║${AnsiColor.GREEN}██║╚██╔╝██║██║╚██╔╝██║${AnsiColor.BLUE}██║ ██║██║╚██╗██║██║██╔═██╗ ██╔══╝ ╚██╔╝ 10 | ╚██████╗╚██████╔╝${AnsiColor.GREEN}██║ ╚═╝ ██║██║ ╚═╝ ██║${AnsiColor.BLUE}╚██████╔╝██║ ╚████║██║██║ ██╗███████╗ ██║ 11 | ╚═════╝ ╚═════╝ ${AnsiColor.GREEN}╚═╝ ╚═╝╚═╝ ╚═╝ ${AnsiColor.BLUE}╚═════╝ ╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ 12 | 13 | ${AnsiColor.GREEN}❱${AnsiColor.WHITE}${AnsiStyle.BOLD} Version: ${AnsiStyle.NORMAL}${application.version} 14 | ${AnsiColor.GREEN}❱${AnsiColor.WHITE}${AnsiStyle.BOLD} Spring Boot: ${AnsiStyle.NORMAL}${spring-boot.version} -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/view/AuthoritiesRestView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.view; 19 | 20 | import de.communicode.communikey.domain.Authority; 21 | 22 | /** 23 | * Defines REST views based on the {@link Authority}s granted to the current user. 24 | * 25 | * @author sgreb@communicode.de 26 | * @since 0.2.0 27 | */ 28 | public class AuthoritiesRestView { 29 | public interface User {} 30 | 31 | public interface Admin extends User {} 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/HashidNotValidException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | /** 21 | * Thrown to indicate that the specified Hashid is not valid. 22 | * 23 | * @author dvonderbey@communicode.de 24 | * @since 0.2.0 25 | */ 26 | public class HashidNotValidException extends RuntimeException { 27 | 28 | /** 29 | * Constructs a {@code HashidNotValidException}. 30 | */ 31 | public HashidNotValidException() { 32 | super("Hashid not valid"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/KeyNotAccessibleByUserException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | /** 21 | * Thrown to indicate that the user has no access to a key. Is checked for every 22 | * userEncryptedPassword that is posted. 23 | * 24 | * @author dvonderbey@communicode.de 25 | * @since 0.2.0 26 | */ 27 | public class KeyNotAccessibleByUserException extends RuntimeException { 28 | 29 | /** 30 | * Constructs a {@code KeyNotAccessibleByUserException}. 31 | */ 32 | public KeyNotAccessibleByUserException() { 33 | super("Key not accessible by user!"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | application: 2 | version: 0.3.0 3 | 4 | spring: 5 | application: 6 | name: communikey 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/communikey?useUnicode=true&characterEncoding=utf8&createDatabaseIfNotExist=true&autoReconnect=true 9 | username: 10 | password: 11 | hikari: 12 | data-source-properties: 13 | # Reference: https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration 14 | cachePrepStmts: true 15 | prepStmtCacheSize: 250 16 | prepStmtCacheSqlLimit: 2048 17 | useServerPrepStmts: true 18 | useLocalSessionState: true 19 | useLocalTransactionState: true 20 | rewriteBatchedStatements: true 21 | cacheResultSetMetadata: true 22 | cacheServerConfiguration: true 23 | elideSetAutoCommits: true 24 | maintainTimeStats: false 25 | mvc: 26 | favicon: 27 | enabled: false 28 | 29 | communikey: 30 | security: 31 | root: 32 | login: root 33 | email: cckey_root@communicode.de 34 | password: password 35 | public-key: | 36 | -----BEGIN PUBLIC KEY----- 37 | THIS IS AN EXAMPLE KEY !!! 38 | -----END PUBLIC KEY----- 39 | 40 | server: 41 | address: localhost 42 | port: 8080 43 | compression: 44 | enabled: true 45 | mime-types: application/json 46 | 47 | logging: 48 | config: classpath:log4j2.yml 49 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/KeyCategoryMovePayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.KeyCategory; 21 | 22 | /** 23 | * A payload object for a {@link KeyCategory} move action. 24 | * 25 | * @author lleifermann@communicode.de 26 | * @since 0.17.0 27 | */ 28 | public class KeyCategoryMovePayload { 29 | 30 | private String parent; 31 | 32 | public KeyCategoryMovePayload() {} 33 | 34 | public String getParent() { return parent; } 35 | 36 | @Override 37 | public String toString() { 38 | return "KeyCategoryPayload{" + "parent='" + parent + '\'' + '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/KeyConflictException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.Key; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed conflicting {@link Key} data. 24 | * 25 | * @author sgreb@communicode.de 26 | * @since 0.2.0 27 | */ 28 | public class KeyConflictException extends RuntimeException { 29 | 30 | /** 31 | * Constructs an {@code KeyConflictException} with the detailed conflict message. 32 | * 33 | * @param message the detailed message about the conflict 34 | */ 35 | public KeyConflictException(String message) { 36 | super(message); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/TagPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.Tag; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | /** 24 | * A payload object for a {@link Tag}. 25 | * 26 | * @author dvonderbey@communicode.de 27 | * @since 0.18.0 28 | */ 29 | public class TagPayload { 30 | 31 | @NotBlank 32 | private String name; 33 | 34 | @NotBlank 35 | private String color; 36 | 37 | public TagPayload() {} 38 | 39 | public String getName() { 40 | return name.trim(); 41 | } 42 | 43 | public String getColor() { 44 | return color; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/ResetTokenNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | /** 21 | * Thrown to indicate that a method has been passed a not existing reset token. 22 | * 23 | * @author sgreb@communicode.de 24 | * @since 0.2.0 25 | */ 26 | public class ResetTokenNotFoundException extends RuntimeException { 27 | 28 | /** 29 | * Constructs an {@code ResetTokenNotFoundException} for the specified reset token. 30 | * 31 | * @param resetToken the reset token that has not been found 32 | */ 33 | public ResetTokenNotFoundException(String resetToken) { 34 | super("reset token '" + resetToken + "' not found"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/security/AuthoritiesConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.security; 19 | 20 | /** 21 | * Provides constants for Spring Security authorities. 22 | * 23 | * @author sgreb@communicode.de 24 | * @author lleifermann@communicode.de 25 | * @since 0.2.0 26 | */ 27 | public final class AuthoritiesConstants { 28 | 29 | public static final String ADMIN = "ROLE_ADMIN"; 30 | public static final String USER = "ROLE_USER"; 31 | public static final String ANONYMOUS = "ROLE_ANONYMOUS"; 32 | public static final String ROOT = "root"; 33 | public static final String ROOT_EMAIL = "cckey_root@communicode.de"; 34 | 35 | private AuthoritiesConstants() {} 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/UserConflictException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.User; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed conflicting {@link User} entity data. 24 | * 25 | * @author sgreb@communicode.de 26 | * @since 0.2.0 27 | */ 28 | public class UserConflictException extends RuntimeException { 29 | 30 | /** 31 | * Constructs an {@code UserConflictException} with the detailed conflict message. 32 | * 33 | * @param message the detailed message about the conflict 34 | */ 35 | public UserConflictException(String message) { 36 | super(message); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/AuthorityNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | /** 21 | * Thrown to indicate that a method has been passed a not existing authority. 22 | * 23 | * @author sgreb@communicode.de 24 | * @since 0.3.0 25 | */ 26 | public class AuthorityNotFoundException extends RuntimeException { 27 | /** 28 | * Constructs an {@code AuthorityNotFoundException} for the specified authority name. 29 | * 30 | * @param authorityName the name of the authority that has not been found 31 | */ 32 | public AuthorityNotFoundException(String authorityName) { 33 | super("authority '" + authorityName + "' not found"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/UserGroupConflictException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.UserGroup; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed conflicting {@link UserGroup} data. 24 | * 25 | * @author sgreb@communicode.de 26 | * @since 0.2.0 27 | */ 28 | public class UserGroupConflictException extends RuntimeException { 29 | 30 | /** 31 | * Constructs a {@code UserGroupConflictException} with the detailed conflict message. 32 | * 33 | * @param message the detailed message about the conflict 34 | */ 35 | public UserGroupConflictException(String message) { 36 | super(message); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/repository/TagRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.repository; 19 | 20 | import de.communicode.communikey.domain.Tag; 21 | import org.springframework.data.repository.CrudRepository; 22 | import org.springframework.stereotype.Repository; 23 | 24 | import java.util.Set; 25 | 26 | /** 27 | * A repository for {@link Tag} entities. 28 | * 29 | * @author dvonderbey@communicode.de 30 | * @since 0.18.0 31 | */ 32 | @Repository 33 | public interface TagRepository extends CrudRepository { 34 | /** 35 | * Finds all tag entities of the repository. 36 | * 37 | * @return a collection of found tag entities 38 | */ 39 | @Override 40 | Set findAll(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.User; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed a not existing {@link User}. 24 | * 25 | * @author sgreb@communicode.de 26 | * @since 0.2.0 27 | */ 28 | public class UserNotFoundException extends RuntimeException { 29 | 30 | /** 31 | * Constructs an {@code UserNotFoundException} for the specified {@link User} login. 32 | * 33 | * @param userLogin the login of the user that has not been found 34 | */ 35 | public UserNotFoundException(String userLogin) { 36 | super("could not find user " + userLogin); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/KeyCategoryConflictException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.KeyCategory; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed conflicting {@link KeyCategory} data. 24 | * 25 | * @author sgreb@communicode.de 26 | * @since 0.2.0 27 | */ 28 | public class KeyCategoryConflictException extends RuntimeException { 29 | 30 | /** 31 | * Constructs an {@code KeyCategoryConflictException} with the detailed conflict message. 32 | * 33 | * @param message the detailed message about the conflict 34 | */ 35 | public KeyCategoryConflictException(String message) { 36 | super(message); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/UserNotActivatedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.User; 21 | 22 | /** 23 | * Thrown to indicate that a not activated {@link User} trying to authenticate. 24 | * 25 | * @author sgreb@communicode.de 26 | * @since 0.2.0 27 | */ 28 | public class UserNotActivatedException extends RuntimeException { 29 | 30 | /** 31 | * Constructs an {@code UserNotActivatedException} for the specified {@link User} login. 32 | * 33 | * @param login the login of the user that has not been found 34 | */ 35 | public UserNotActivatedException(String login) { 36 | super("user " + login + " is not activated"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/ActivationTokenNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | /** 21 | * Thrown to indicate that a method has been passed a not existing activation token. 22 | * 23 | * @author sgreb@communicode.de 24 | * @since 0.2.0 25 | */ 26 | public class ActivationTokenNotFoundException extends RuntimeException { 27 | 28 | /** 29 | * Constructs an {@code ActivationTokenNotFoundException} for the specified activation token. 30 | * 31 | * @param activationToken the activation token that has not been found 32 | */ 33 | public ActivationTokenNotFoundException(String activationToken) { 34 | super("activation token '" + activationToken +"' not found"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/DateTimeFormatConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.format.FormatterRegistry; 22 | import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; 23 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 24 | 25 | @Configuration 26 | public class DateTimeFormatConfig implements WebMvcConfigurer { 27 | 28 | @Override 29 | public void addFormatters(FormatterRegistry registry) { 30 | DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar(); 31 | registrar.setUseIsoFormat(true); 32 | registrar.registerFormatters(registry); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/repository/UserGroupRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.repository; 19 | 20 | import de.communicode.communikey.domain.UserGroup; 21 | import org.springframework.data.repository.CrudRepository; 22 | import org.springframework.stereotype.Repository; 23 | 24 | /** 25 | * A repository for {@link UserGroup}s. 26 | * 27 | * @author sgreb@communicode.de 28 | * @since 0.2.0 29 | */ 30 | @Repository 31 | public interface UserGroupRepository extends CrudRepository { 32 | 33 | /** 34 | * Finds the user group with the specified name. 35 | * 36 | * @param name the name of the user group to find 37 | * @return the user group entity 38 | */ 39 | UserGroup findOneByName(String name); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/EncryptionJobPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.EncryptionJob; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | /** 24 | * A payload object for a {@link EncryptionJob} fulfillment. 25 | * 26 | * @author dvonderbey@communicode.de 27 | * @since 0.15.0 28 | */ 29 | public class EncryptionJobPayload { 30 | 31 | @NotBlank 32 | private String encryptedPassword; 33 | 34 | public EncryptionJobPayload() {} 35 | 36 | public String getEncryptedPassword() { 37 | return encryptedPassword; 38 | } 39 | 40 | public void setEncryptedPassword(String encryptedPassword) { 41 | this.encryptedPassword = encryptedPassword; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/KeyPayloadEncryptedPasswords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.UserEncryptedPassword; 21 | 22 | import javax.validation.constraints.NotBlank; 23 | 24 | /** 25 | * A payload container object for a {@link UserEncryptedPassword}. 26 | * 27 | * @author sgreb@communicode.de 28 | * @author dvonderbey@communicode.de 29 | * @since 0.15.0 30 | */ 31 | public class KeyPayloadEncryptedPasswords { 32 | @NotBlank 33 | private String login; 34 | 35 | @NotBlank 36 | private String encryptedPassword; 37 | 38 | public String getLogin() { 39 | return login; 40 | } 41 | 42 | public String getEncryptedPassword() { 43 | return encryptedPassword; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/EncryptionJobAbortPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.EncryptionJob; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | /** 24 | * A payload object for a {@link EncryptionJob} abort. 25 | * 26 | * @author dvonderbey@communicode.de 27 | * @since 0.15.0 28 | */ 29 | public class EncryptionJobAbortPayload { 30 | 31 | @NotBlank 32 | private String token; 33 | 34 | public EncryptionJobAbortPayload() {} 35 | 36 | public EncryptionJobAbortPayload(String token) { 37 | this.token = token; 38 | } 39 | 40 | public String getToken() { 41 | return token; 42 | } 43 | 44 | public void setToken(String token) { 45 | this.token = token; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/EncryptionJobStatusPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.EncryptionJob; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | /** 24 | * A payload object for a {@link EncryptionJob} fulfillment status. 25 | * 26 | * @author dvonderbey@communicode.de 27 | * @since 0.15.0 28 | */ 29 | public class EncryptionJobStatusPayload { 30 | 31 | @NotBlank 32 | private String status; 33 | 34 | public EncryptionJobStatusPayload() {} 35 | 36 | public EncryptionJobStatusPayload(String status) { 37 | this.status = status; 38 | } 39 | 40 | public String getStatus() { 41 | return status; 42 | } 43 | 44 | public void setStatus(String status) { 45 | this.status = status; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/KeyCategoryPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.KeyCategory; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | /** 24 | * A payload object for a {@link KeyCategory}. 25 | * 26 | * @author sgreb@communicode.de 27 | * @author dvonderbey@communicode.de 28 | * @since 0.2.0 29 | */ 30 | public class KeyCategoryPayload { 31 | 32 | @NotBlank 33 | private String name; 34 | 35 | private String parent; 36 | 37 | public KeyCategoryPayload() {} 38 | 39 | public String getName() { 40 | return name.trim(); 41 | } 42 | 43 | public String getParent() { 44 | return parent; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "KeyCategoryPayload{" + "name='" + name + '\'' + '}'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/UserCreationPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.User; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | /** 24 | * A payload object to create a {@link User}. 25 | * 26 | * @author sgreb@communicode.de 27 | * @since 0.5.0 28 | */ 29 | public class UserCreationPayload extends UserPayload { 30 | 31 | @NotBlank 32 | private String password; 33 | 34 | public UserCreationPayload() {} 35 | 36 | public UserCreationPayload(User user) { 37 | super(user); 38 | this.password = user.getPassword(); 39 | } 40 | 41 | public String getPassword() { 42 | return password; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "UserCreationPayload{" + "password='" + password + '\'' + '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/KeyNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.Key; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed a not existing {@link Key}. 24 | * 25 | * @author sgreb@communicode.de 26 | * @since 0.2.0 27 | */ 28 | public class KeyNotFoundException extends RuntimeException { 29 | 30 | /** 31 | * Constructs a {@code KeyNotFoundException}. 32 | */ 33 | public KeyNotFoundException() { 34 | super("key not found"); 35 | } 36 | 37 | /** 38 | * Constructs a {@code KeyNotFoundException} with the specified {@link Key} Hashid. 39 | * 40 | * @param keyHashid the Hashid of the key that has not been found 41 | * @since 0.12.0 42 | */ 43 | public KeyNotFoundException(String keyHashid) { 44 | super("key with ID '" + keyHashid + "' not found"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/TagNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.Tag; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed a not existing {@link Tag}. 24 | * 25 | * @author dvonderbey@communicode.de 26 | * @since 0.18.0 27 | */ 28 | public class TagNotFoundException extends RuntimeException { 29 | 30 | /** 31 | * Constructs a {@code TagNotFoundException}. 32 | */ 33 | public TagNotFoundException() { 34 | super("tag not found"); 35 | } 36 | 37 | /** 38 | * Constructs a {@code TagNotFoundException} with the specified {@link Tag} Hashid. 39 | * 40 | * @param tagHashid the Hashid of the tag that has not been found 41 | * @since 0.12.0 42 | */ 43 | public TagNotFoundException(String tagHashid) { 44 | super("tag with ID '" + tagHashid + "' not found"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/controller/RequestParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.controller; 19 | 20 | /** 21 | * Provides request parameter constants. 22 | * 23 | * @author sgreb@communicode.de 24 | * @since 0.3.0 25 | */ 26 | public final class RequestParameter { 27 | 28 | /** 29 | * The request parameter for the {@value RequestMappings#API} endpoint to get the version of the REST API. 30 | */ 31 | public static final String API_VERSION = "version"; 32 | 33 | /** 34 | * The request parameter for the {@value RequestMappings#API} endpoint to authorize a user. 35 | * 36 | * @since 0.4.0 37 | */ 38 | public static final String API_AUTHORIZE = "authorize"; 39 | 40 | /** 41 | * The request parameter for the {@value RequestMappings#API} endpoint to get information about the current user. 42 | */ 43 | public static final String API_ME = "me"; 44 | 45 | private RequestParameter() {} 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/UserPasswordResetPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.User; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | /** 24 | * A payload object to reset the password of a {@link User} with a specified reset token. 25 | * 26 | * @author sgreb@communicode.de 27 | * @since 0.2.0 28 | */ 29 | public class UserPasswordResetPayload { 30 | 31 | @NotBlank 32 | private String password; 33 | 34 | @NotBlank 35 | private String resetToken; 36 | 37 | public String getPassword() { 38 | return password; 39 | } 40 | 41 | public String getResetToken() { 42 | return resetToken; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "UserPasswordResetPayload{" + 48 | "password='" + password + '\'' + 49 | ", resetToken='" + resetToken + '\'' + 50 | '}'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/UserCredentialPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.User; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | /** 24 | * A payload object to provide the {@link User} credentials consisting of the login and the password. 25 | * 26 | * @author sgreb@communicode.de 27 | * @author dvonderbey@communicode.de 28 | * @since 0.4.0 29 | */ 30 | public class UserCredentialPayload { 31 | 32 | @NotBlank 33 | private String login; 34 | 35 | @NotBlank 36 | private String password; 37 | 38 | public String getLogin() { 39 | return login; 40 | } 41 | 42 | public String getPassword() { 43 | return password; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "UserCredentialPayload{" + 49 | "login='" + login + '\'' + 50 | ", password='" + password + '\'' + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/repository/AuthorityRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.repository; 19 | 20 | import de.communicode.communikey.domain.Authority; 21 | import org.springframework.data.repository.CrudRepository; 22 | 23 | import java.util.Set; 24 | 25 | /** 26 | * A repository for {@link Authority} entities. 27 | * 28 | * @author sgreb@communicode.de 29 | * @since 0.2.0 30 | */ 31 | public interface AuthorityRepository extends CrudRepository { 32 | /** 33 | * Finds all authority entities of the repository. 34 | * 35 | * @return a collection of found authority entities 36 | * @since 0.9.0 37 | */ 38 | @Override 39 | Set findAll(); 40 | 41 | /** 42 | * Finds the authority entity with the specified name. 43 | * 44 | * @param name the name of the authority to find 45 | * @return the found authority entity, {@code null} otherwise 46 | * @since 0.3.0 47 | */ 48 | Authority findOneByName(String name); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/EncryptionJobNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.EncryptionJob; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed a non existing {@link EncryptionJob}. 24 | * 25 | * @author dvonderbey@communicode.de 26 | * @since 0.15.0 27 | */ 28 | public class EncryptionJobNotFoundException extends RuntimeException { 29 | 30 | /** 31 | * Constructs a {@code EncryptionJobNotFoundException}. 32 | */ 33 | public EncryptionJobNotFoundException() { 34 | super("encryption job not found"); 35 | } 36 | 37 | /** 38 | * Constructs an {@code EncryptionJobNotFoundException} with the specified {@link EncryptionJob} token. 39 | * 40 | * @param encryptionJobToken the token of the encryption job that has not been found 41 | */ 42 | public EncryptionJobNotFoundException(String encryptionJobToken) { 43 | super("enryption job with token '" + encryptionJobToken + "' not found"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/KeyCategoryNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.KeyCategory; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed a not existing {@link KeyCategory}. 24 | * 25 | * @author sgreb@communicode.de 26 | * @author dvonderbey@communicode.de 27 | * @since 0.2.0 28 | */ 29 | public class KeyCategoryNotFoundException extends RuntimeException { 30 | 31 | /** 32 | * Constructs a {@code KeyNotFoundException}. 33 | */ 34 | public KeyCategoryNotFoundException() { 35 | super("key category not found"); 36 | } 37 | 38 | /** 39 | * Constructs an {@code KeyCategoryNotFoundException} with the specified {@link KeyCategory} Hashid. 40 | * 41 | * @param keyCategoryHashid the Hashid of the key category that has not been found 42 | */ 43 | public KeyCategoryNotFoundException(String keyCategoryHashid) { 44 | super("key category with ID '" + keyCategoryHashid + "' not found"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/repository/KeyRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.repository; 19 | 20 | import de.communicode.communikey.domain.Key; 21 | import de.communicode.communikey.domain.KeyCategory; 22 | import org.springframework.data.repository.CrudRepository; 23 | import org.springframework.stereotype.Repository; 24 | 25 | import java.util.Set; 26 | 27 | /** 28 | * A repository for {@link Key} entities. 29 | * 30 | * @author sgreb@communicode.de 31 | * @since 0.1.0 32 | */ 33 | @Repository 34 | public interface KeyRepository extends CrudRepository { 35 | /** 36 | * Finds all key entities of the repository. 37 | * 38 | * @return a collection of found key entities 39 | */ 40 | @Override 41 | Set findAll(); 42 | 43 | /** 44 | * Finds all key entities that are in the specified key category. 45 | * 46 | * @param keyCategory the key category the keys should be in 47 | * @return a collection of found key entities 48 | */ 49 | Set findAllByCategory(KeyCategory keyCategory); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/MethodSecurityConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; 22 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 23 | import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; 24 | import org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler; 25 | 26 | /** 27 | * Enables the global method security using the OAuth2 expression handler. 28 | * 29 | * @author sgreb@communicode.de 30 | * @since 0.2.0 31 | */ 32 | @Configuration 33 | @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) 34 | public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration { 35 | 36 | @Override 37 | protected MethodSecurityExpressionHandler createExpressionHandler() { 38 | return new OAuth2MethodSecurityExpressionHandler(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/HashidsConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import de.communicode.communikey.domain.Key; 21 | import org.hashids.Hashids; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | 25 | /** 26 | * Configuration for the {@link Key} {@link Hashids} en- and decoder. 27 | * 28 | *

Provides the {@link Hashids} bean. 29 | * 30 | * @author sgreb@communicode.de 31 | * @since 0.12.0 32 | */ 33 | @Configuration 34 | public class HashidsConfig { 35 | /** 36 | * The Hashids encoder- and decoder bean. 37 | * 38 | *

The salt and minimum hash length must not be changed to prevent the invalidation of already generated and persisted Hashids! 39 | * 40 | * @return the Hashids bean 41 | */ 42 | @Bean 43 | public Hashids hashids() { 44 | final String HASHIDS_SALT = "_et#9mKb4)&);!F(pNs6%wNXfo#'R2tG`PQ`6DN@kR^2U;faXZw?:]LF.39fQvX<"; 45 | final int HASHIDS_MIN_LENGTH = 12; 46 | return new Hashids(HASHIDS_SALT, HASHIDS_MIN_LENGTH); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/UserGroupNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.UserGroup; 21 | 22 | /** 23 | * Thrown to indicate that a method has been passed an not existing {@link UserGroup}. 24 | * 25 | * @author sgreb@communicode.de 26 | * @since 0.2.0 27 | */ 28 | public class UserGroupNotFoundException extends RuntimeException { 29 | 30 | /** 31 | * Constructs a {@code UserGroupNotFoundException} for the specified {@link UserGroup}. 32 | * 33 | * @param name the name of the user group that has not been found 34 | */ 35 | public UserGroupNotFoundException(String name) { 36 | super("user group '" + name + "' not found"); 37 | } 38 | 39 | /** 40 | * Constructs a {@code UserGroupNotFoundException} for the specified {@link UserGroup}. 41 | * 42 | * @param userGroupId the ID of the user group that has not been found 43 | * @since 0.9.0 44 | */ 45 | public UserGroupNotFoundException(Long userGroupId) { 46 | super("user group with ID '" + userGroupId + "' not found"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/UserPublicKeyResetPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.User; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | /** 24 | * A payload object to reset the password of a {@link User} with a specified reset token. 25 | * 26 | * @author sgreb@communicode.de 27 | * @since 0.2.0 28 | */ 29 | public class UserPublicKeyResetPayload { 30 | 31 | @NotBlank 32 | private String publicKey; 33 | 34 | @NotBlank 35 | private String resetToken; 36 | 37 | public UserPublicKeyResetPayload() {} 38 | 39 | public UserPublicKeyResetPayload(String publicKey, String resetToken) { 40 | this.publicKey = publicKey; 41 | this.resetToken = resetToken; 42 | } 43 | 44 | public String getPublicKey() { 45 | return publicKey; 46 | } 47 | 48 | public String getResetToken() { 49 | return resetToken; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "UserPublicKeyResetPayload{" + 55 | "publicKey='" + publicKey + '\'' + 56 | ", resetToken='" + resetToken + '\'' + 57 | '}'; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 22 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 23 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 24 | import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; 25 | 26 | /** 27 | * Configures the websocket server 28 | * 29 | * @author dvonderbey@communicode.de 30 | * @since 0.15.0 31 | */ 32 | @Configuration 33 | @EnableWebSocketMessageBroker 34 | public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { 35 | 36 | @Override 37 | public void registerStompEndpoints(StompEndpointRegistry registry) { 38 | registry.addEndpoint("/wss/registry"); 39 | registry.addEndpoint("/wss/registry").withSockJS(); 40 | } 41 | 42 | @Override 43 | public void configureMessageBroker(MessageBrokerRegistry config) { 44 | config.setApplicationDestinationPrefixes("/app", "/user"); 45 | config.enableSimpleBroker("/topic", "/queue"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/UserEncryptedPasswordNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.domain.Key; 21 | import de.communicode.communikey.domain.User; 22 | import de.communicode.communikey.domain.UserEncryptedPassword; 23 | 24 | /** 25 | * Thrown to indicate that a method has been passed a non existing {@link UserEncryptedPassword}. 26 | * 27 | * @author dvonderbey@communicode.de 28 | * @since 0.15.0 29 | */ 30 | public class UserEncryptedPasswordNotFoundException extends RuntimeException { 31 | 32 | /** 33 | * Constructs a {@code UserEncryptedPasswordNotFoundException}. 34 | */ 35 | public UserEncryptedPasswordNotFoundException() { 36 | super("userEncryptedPassword not found"); 37 | } 38 | 39 | /** 40 | * Constructs a {@code UserEncryptedPasswordNotFoundException} with the specified {@link Key} Hashid and {@link User} name. 41 | * 42 | * @param keyHashid the Hashid of the key that has not been found 43 | * @since 0.12.0 44 | */ 45 | public UserEncryptedPasswordNotFoundException(Long keyHashid, String username) { 46 | super("userEncryptedPassword with ID '" + keyHashid + "' for user '" + username + "' not found"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/TagControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.controller.TagController; 21 | import org.springframework.http.HttpStatus; 22 | import org.springframework.http.ResponseEntity; 23 | import org.springframework.web.bind.annotation.ControllerAdvice; 24 | import org.springframework.web.bind.annotation.ExceptionHandler; 25 | 26 | import java.sql.Timestamp; 27 | import java.util.Calendar; 28 | 29 | /** 30 | * The exception handler for the {@link TagController} that returns an error as response entity. 31 | * 32 | * @author dvonderbey@communicode.de 33 | * @since 0.18.0 34 | */ 35 | @ControllerAdvice 36 | public class TagControllerExceptionHandler extends GlobalControllerExceptionHandler { 37 | 38 | /** 39 | * Handles all exceptions of type {@link TagNotFoundException}. 40 | * 41 | * @param exception the exception to handle 42 | * @return the error as response entity 43 | */ 44 | @ExceptionHandler(TagNotFoundException.class) 45 | public ResponseEntity handleTagNotFoundException(final TagNotFoundException exception) { 46 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/AuthorityControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.controller.AuthorityController; 21 | import org.springframework.http.HttpStatus; 22 | import org.springframework.http.ResponseEntity; 23 | import org.springframework.web.bind.annotation.ControllerAdvice; 24 | import org.springframework.web.bind.annotation.ExceptionHandler; 25 | 26 | import java.sql.Timestamp; 27 | import java.util.Calendar; 28 | 29 | /** 30 | * The exception handler for the {@link AuthorityController} that returns a error as response entity. 31 | * 32 | * @author sgreb@communicode.de 33 | * @since 0.3.0 34 | */ 35 | @ControllerAdvice 36 | public class AuthorityControllerExceptionHandler extends GlobalControllerExceptionHandler { 37 | /** 38 | * Handles all exceptions of type {@link AuthorityNotFoundException}. 39 | * 40 | * @param exception the exception to handle 41 | * @return the error as response entity 42 | */ 43 | @ExceptionHandler(AuthorityNotFoundException.class) 44 | public ResponseEntity handleAuthorityNotFoundException(final AuthorityNotFoundException exception) { 45 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/KeyPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import de.communicode.communikey.domain.Key; 21 | import javax.validation.constraints.NotBlank; 22 | 23 | import javax.validation.constraints.NotNull; 24 | import java.util.Set; 25 | 26 | /** 27 | * A payload object for a {@link Key}. 28 | * 29 | * @author sgreb@communicode.de 30 | * @author dvonderbey@communicode.de 31 | * @since 0.2.0 32 | */ 33 | public class KeyPayload { 34 | 35 | private String categoryId; 36 | 37 | @NotBlank 38 | private String login; 39 | 40 | @NotBlank 41 | private String name; 42 | 43 | private String notes; 44 | 45 | @NotNull 46 | private Set encryptedPasswords; 47 | 48 | public KeyPayload() {} 49 | 50 | /** 51 | * @return the category ID 52 | * @since 0.8.0 53 | */ 54 | public String getCategoryId() { 55 | return this.categoryId; 56 | } 57 | 58 | public String getLogin() { 59 | return login; 60 | } 61 | 62 | public String getName() { 63 | return name.trim(); 64 | } 65 | 66 | public String getNotes() { 67 | return notes; 68 | } 69 | 70 | public Set getEncryptedPasswords() { 71 | return encryptedPasswords; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/CrowdEncryptionControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.controller.CrowdEncryptionController; 21 | import de.communicode.communikey.service.payload.EncryptionJobStatusPayload; 22 | import org.springframework.messaging.handler.annotation.MessageExceptionHandler; 23 | import org.springframework.messaging.simp.annotation.SendToUser; 24 | import org.springframework.web.bind.annotation.ControllerAdvice; 25 | 26 | /** 27 | * The exception handler for the {@link CrowdEncryptionController} that returns a error as response entity. 28 | * 29 | * @author dvonderbey@communicode.de 30 | * @since 0.15.0 31 | */ 32 | @ControllerAdvice 33 | public class CrowdEncryptionControllerExceptionHandler extends GlobalControllerExceptionHandler { 34 | 35 | /** 36 | * Handles all exceptions of type {@link EncryptionJobNotFoundException}. 37 | * 38 | * @param exception the exception to handle 39 | * @return the error as response entity 40 | */ 41 | @MessageExceptionHandler(EncryptionJobNotFoundException.class) 42 | @SendToUser(value="/queue/errors") 43 | public EncryptionJobStatusPayload handleKeyConflictException(EncryptionJobNotFoundException exception) { 44 | return new EncryptionJobStatusPayload("Error: " + exception); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/security/SecurityAuditorAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.security; 19 | 20 | import de.communicode.communikey.config.CommunikeyProperties; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.data.domain.AuditorAware; 23 | import org.springframework.stereotype.Component; 24 | 25 | import static java.util.Objects.requireNonNull; 26 | import static java.util.Optional.ofNullable; 27 | 28 | import java.util.Objects; 29 | import java.util.Optional; 30 | 31 | /** 32 | * Implementation of AuditorAware based on Spring Security. 33 | * 34 | * @author sgreb@communicode.de 35 | * @since 0.2.0 36 | */ 37 | @Component 38 | public class SecurityAuditorAware implements AuditorAware { 39 | 40 | private final CommunikeyProperties communikeyProperties; 41 | 42 | @Autowired 43 | public SecurityAuditorAware(CommunikeyProperties communikeyProperties) { 44 | this.communikeyProperties = requireNonNull(communikeyProperties, "communikeyProperties must not be null!"); 45 | } 46 | 47 | @Override 48 | public Optional getCurrentAuditor() { 49 | String userName = SecurityUtils.getCurrentUserLogin(); 50 | if (userName != null && !Objects.equals(userName, "anonymousUser")) { 51 | return ofNullable(userName); 52 | } 53 | return Optional.empty(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/repository/KeyCategoryRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.repository; 19 | 20 | import de.communicode.communikey.domain.KeyCategory; 21 | import de.communicode.communikey.domain.UserGroup; 22 | import org.springframework.data.repository.CrudRepository; 23 | import org.springframework.stereotype.Repository; 24 | 25 | import java.util.Set; 26 | 27 | /** 28 | * A repository for {@link KeyCategory} entities. 29 | * 30 | * @author sgreb@communicode.de 31 | * @since 0.2.0 32 | */ 33 | @Repository 34 | public interface KeyCategoryRepository extends CrudRepository { 35 | 36 | /** 37 | * Finds all key category entities of the repository. 38 | * 39 | * @return a collection of found key category entities 40 | */ 41 | @Override 42 | Set findAll(); 43 | 44 | /** 45 | * Finds all key category entities where the parent key category is {@code null}. 46 | * 47 | * @return a collection of found key category entities 48 | */ 49 | Set findAllByParentIsNull(); 50 | 51 | /** 52 | * Finds all key category entities which are in the specified usergroup. 53 | * 54 | * @param userGroup the usergroup the key categories should contain 55 | * @return a collection of found key category entities 56 | */ 57 | Set findAllByGroupsContains(UserGroup userGroup); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import com.fasterxml.jackson.databind.MapperFeature; 21 | import com.fasterxml.jackson.databind.ObjectMapper; 22 | import com.fasterxml.jackson.databind.SerializationFeature; 23 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.context.annotation.Configuration; 26 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; 27 | 28 | /** 29 | * Configuration for Jackson to register modules and configure (de)serialization- and mapper features. 30 | * 31 | * @author sgreb@communicode.de 32 | */ 33 | @Configuration 34 | public class JacksonConfig { 35 | 36 | @Bean 37 | public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { 38 | MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(); 39 | ObjectMapper objectMapper = new ObjectMapper(); 40 | 41 | objectMapper 42 | .registerModule(new JavaTimeModule()); 43 | 44 | objectMapper 45 | .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) 46 | .configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true); 47 | 48 | jsonConverter.setObjectMapper(objectMapper); 49 | return jsonConverter; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.1.0 (2016-10-10) 2 | This version represents the MVP. 3 | 4 | ## Features 5 | **Application main class**: `de.communicode.communikey.CommunikeyApplication` 6 | **Application YAML configuration**: `src/main/resources/application.yaml` 7 | 8 | ### Controllers 9 | - [CCKEY-23][jira-cckey-23] Implemented the `de.communicode.communikey.controller.PasswordController` class which provides the following endpoints: 10 | 11 | | Endpoint | Usage | 12 | | --- | --- | 13 | | `passwords` | A list of all saved password entries. | 14 | | `passwords//edit` | A simple form to edit a password with the given `ID`. | 15 | | `passwords/new` | A simple form to create a new password. | 16 | 17 | ### Entities 18 | - [CCKEY-15][jira-cckey-15] Implemented the `de.communicode.communikey.domain.Password` class which consists of the password value and a creation timestamp 19 | 20 | ### Repositories 21 | - [CCKEY-16][jira-cckey-16] Designed the `de.communicode.communikey.repository.PasswordRepository` interface 22 | 23 | ### Services 24 | - [CCKEY-17][jira-cckey-17] Designed the `de.communicode.communikey.service.PasswordService` interface and implemented the `de.communicode.communikey.service.PasswordServiceImpl` class 25 | 26 | | Method Signature | Description | 27 | | --- | --- | 28 | | `+ getAllPasswords() : Iterable` | Gets all `Password` entities of the `PasswordRepository`. | 29 | | `+ getPasswordById(long) : Password` | Gets the `Password` with the given `id`. | 30 | | `+ getPasswordByCreationDate(Timestamp) : Password` | Gets the first `Password` found with the given creation `Timestamp`. | 31 | | `+ deletePassword(Password) : void` | Deletes the given `Password`. | 32 | | `+ modifyPasswordValue(Password, String) : void` | Modifies the value of the given `Password`. | 33 | | `+ savePassword(Password) : Password` | Saves the given `Password` in the `PasswordRepository`. | 34 | 35 | ### UI 36 | - [CCKEY-24][jira-cckey-24] Implemented the prototype web UI Thymeleaf templates and CSS files 37 | 38 | [jira-cckey-15]: https://jira.communicode.de/browse/CCKEY-15 39 | [jira-cckey-16]: https://jira.communicode.de/browse/CCKEY-16 40 | [jira-cckey-17]: https://jira.communicode.de/browse/CCKEY-17 41 | [jira-cckey-23]: https://jira.communicode.de/browse/CCKEY-23 42 | [jira-cckey-24]: https://jira.communicode.de/browse/CCKEY-24 43 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/domain/Authority.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.domain; 19 | 20 | import javax.persistence.Column; 21 | import javax.persistence.Entity; 22 | import javax.persistence.Id; 23 | import javax.persistence.Table; 24 | import javax.validation.constraints.NotNull; 25 | import java.io.Serializable; 26 | 27 | /** 28 | * Represents an authority (security role) used by Spring Security. 29 | * 30 | * @author sgreb@communicode.de 31 | * @since 0.2.0 32 | */ 33 | @Entity 34 | @Table(name = "authorities") 35 | public class Authority extends AbstractEntity implements Serializable { 36 | 37 | private static final long serialVersionUID = 1L; 38 | 39 | @NotNull 40 | @Id 41 | @Column(length = 50) 42 | private String name; 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public void setName(String name) { 49 | this.name = name; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | if (this == o) { 55 | return true; 56 | } 57 | if (o == null || getClass() != o.getClass()) { 58 | return false; 59 | } 60 | 61 | Authority authority = (Authority) o; 62 | return name != null ? name.equals(authority.name) : authority.name == null; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | return name != null ? name.hashCode() : 0; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return "Authority{" + "name='" + name + '\'' + "}"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/controller/PathVariables.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.controller; 19 | 20 | import de.communicode.communikey.domain.EncryptionJob; 21 | import de.communicode.communikey.domain.Key; 22 | import de.communicode.communikey.domain.KeyCategory; 23 | import de.communicode.communikey.domain.Tag; 24 | 25 | /** 26 | * Provides path variables constants. 27 | * 28 | * @author sgreb@communicode.de 29 | * @author dvonderbey@communicode.de 30 | * @since 0.2.0 31 | */ 32 | public final class PathVariables { 33 | 34 | public static final String USER_ACTIVATION_TOKEN = "activation_token"; 35 | public static final String USER_EMAIL = "email"; 36 | public static final String USER_LOGIN = "login"; 37 | 38 | /** 39 | * The Hashid of a {@link Key}. 40 | * 41 | *

Exposed as ID through the API. 42 | * 43 | * @since 0.12.0 44 | */ 45 | public static final String KEY_ID = "keyId"; 46 | 47 | /** 48 | * The Hashid of a {@link KeyCategory}. 49 | * 50 | *

Exposed as ID through the API. 51 | * 52 | * @since 0.13.0 53 | */ 54 | public static final String KEYCATEGORY_ID = "keyCategoryId"; 55 | 56 | /** 57 | * The Token of a {@link EncryptionJob}. 58 | * 59 | * @since 0.15.0 60 | */ 61 | public static final String JOB_TOKEN = "token"; 62 | 63 | /** 64 | * The Hashid of a {@link Tag}. 65 | * 66 | *

Exposed as ID through the API. 67 | * 68 | * @since 0.18.0 69 | */ 70 | public static final String TAG_ID = "tagId"; 71 | 72 | private PathVariables() {} 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/util/ApplicationStartup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config.util; 19 | 20 | import de.communicode.communikey.repository.UserRepository; 21 | import de.communicode.communikey.service.EncryptionJobService; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.context.event.ApplicationReadyEvent; 24 | import org.springframework.context.ApplicationListener; 25 | import org.springframework.stereotype.Component; 26 | import org.springframework.transaction.annotation.Transactional; 27 | 28 | import static java.util.Objects.requireNonNull; 29 | 30 | /** 31 | * This class acts on startup events of the application. 32 | * 33 | * @author dvonderbey@communicode.de 34 | * @since 0.17.2 35 | */ 36 | @Component 37 | public class ApplicationStartup 38 | implements ApplicationListener { 39 | 40 | private final EncryptionJobService encryptionJobService; 41 | private final UserRepository userRepository; 42 | 43 | @Autowired 44 | public ApplicationStartup(EncryptionJobService encryptionJobService, 45 | UserRepository userRepository) { 46 | this.encryptionJobService = requireNonNull(encryptionJobService, "encryptionJobService must not be null!"); 47 | this.userRepository = requireNonNull(userRepository, "userRepository must not be null!"); 48 | } 49 | 50 | @Override 51 | @Transactional 52 | public void onApplicationEvent(final ApplicationReadyEvent event) { 53 | userRepository.findAll() 54 | .forEach(user -> encryptionJobService.createForUser(user)); 55 | return; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/WebSocketSecurityConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.messaging.simp.SimpMessageType; 22 | import org.springframework.security.config.annotation.web.messaging.MessageSecurityMetadataSourceRegistry; 23 | import org.springframework.security.config.annotation.web.socket.AbstractSecurityWebSocketMessageBrokerConfigurer; 24 | 25 | /** 26 | * Configures the security for user authentications and requests to the WSS API. 27 | * 28 | * @author dvonderbey@communicode.de 29 | * @since 0.15.0 30 | */ 31 | @Configuration 32 | public class WebSocketSecurityConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer { 33 | 34 | @Override 35 | protected boolean sameOriginDisabled() { 36 | return true; 37 | } 38 | 39 | @Override 40 | protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) { 41 | messages 42 | .simpTypeMatchers(SimpMessageType.CONNECT, 43 | SimpMessageType.HEARTBEAT, 44 | SimpMessageType.UNSUBSCRIBE, 45 | SimpMessageType.DISCONNECT).permitAll() 46 | .simpDestMatchers("/app/**").authenticated() 47 | .simpSubscribeDestMatchers("/queue/updates/groups**", "/queue/updates/groups/**", 48 | "/queue/updates/users**", "/queue/updates/users/**").hasRole("ADMIN") 49 | .simpSubscribeDestMatchers("/topic/**", "/queue/**", "/app/**", "/user/**").authenticated() 50 | .simpTypeMatchers(SimpMessageType.MESSAGE, SimpMessageType.SUBSCRIBE).denyAll() 51 | .anyMessage().denyAll(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | > **Please read the [contribution guidelines](https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md) before filling out this pull request template**. 4 | 5 | ## Prerequisites 6 | 7 | This section and the instructions in the sections below are only part of this pull request template. Please ensure to **delete this whole section, all pre-filled instructions of the sections below and sections you have not filled out before submitting** to ensure a clear structure and overview. 8 | 9 | Please do your best to provide as much information as possible and use a clear and descriptive title for your enhancement suggestion or bug fix to help maintainers and the community understand and reproduce the behavior, find related pull requests and to merge it faster. 10 | 11 | * **Ensure the pull request has not already been reported by using the [GitHub Pull Request search](https://github.com/communicode/communikey-backend/pulls)** — if it has **and the pull request is still open**, add a comment to the existing pull request instead of opening this new one. If you find a closed pull request that seems to be similar to this one, include a link to it in the [metadata head](#metadata-head) section of this pull request. 12 | * **Ensure the contribution belongs to the correct [communikey repository](https://github.com/communicode?q=communikey).** 13 | * **Ensure to adhere to the [pull request contribution guidelines](https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#pull-requests)**, especially the one for tests and documentations. 14 | 15 | ## Metadata Head 16 | 17 | The metadata head should be added to the top of the pull request as [Markdown text quote](https://help.github.com/articles/basic-writing-and-formatting-syntax) containing the [GitHub issue keyword(s)](https://help.github.com/articles/closing-issues-using-keywords) to link to the related enhancements suggestions (`Closes`) or bug reports (`Fixes`). You can add additional details like dependencies to other pull requests and the order it needs to be merged. 18 | 19 | > Closes ISSUE_ID 20 | Must be merged **after**/**before** ISSUE_ID 21 | 22 | ## Description 23 | 24 | Describe the changes as in many relevant details as possible. If this is a enhancement suggestion add specific use-cases and explain why this feature or improvement would be useful. If this is a bug fix ensure to provide a *before/after* comparison by describing the current behavior and the new behavior. 25 | 26 | ## References 27 | 28 | Add any other references and links which are relevant for this issue. 29 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/UserGroupControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.controller.UserGroupController; 21 | import org.springframework.http.HttpStatus; 22 | import org.springframework.http.ResponseEntity; 23 | import org.springframework.web.bind.annotation.ControllerAdvice; 24 | import org.springframework.web.bind.annotation.ExceptionHandler; 25 | 26 | import java.sql.Timestamp; 27 | import java.util.Calendar; 28 | 29 | /** 30 | * The exception handler for the {@link UserGroupController} that returns a wrapped {@link ErrorResponse} entity. 31 | * 32 | * @author sgreb@communicode.de 33 | * @since 0.2.0 34 | */ 35 | @ControllerAdvice 36 | public class UserGroupControllerExceptionHandler extends GlobalControllerExceptionHandler { 37 | 38 | /** 39 | * Handles all exceptions of type {@link UserGroupNotFoundException}. 40 | * 41 | * @param exception the exception to handle 42 | * @return the error as response entity 43 | */ 44 | @ExceptionHandler(UserGroupNotFoundException.class) 45 | public ResponseEntity handleUserGroupNotFoundException(final UserGroupNotFoundException exception) { 46 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 47 | } 48 | 49 | /** 50 | * Handles all exceptions of type {@link UserGroupConflictException}. 51 | * 52 | * @param exception the exception to handle 53 | * @return the error as response entity 54 | */ 55 | @ExceptionHandler(UserGroupConflictException.class) 56 | public ResponseEntity handleUserGroupConflictException(final UserGroupConflictException exception) { 57 | return createErrorResponse(HttpStatus.CONFLICT, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/KeyCategoryControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.controller.KeyCategoryController; 21 | import org.springframework.http.HttpStatus; 22 | import org.springframework.http.ResponseEntity; 23 | import org.springframework.web.bind.annotation.ControllerAdvice; 24 | import org.springframework.web.bind.annotation.ExceptionHandler; 25 | 26 | import java.sql.Timestamp; 27 | import java.util.Calendar; 28 | 29 | /** 30 | * The exception handler for the {@link KeyCategoryController} that returns a error as response entity. 31 | * 32 | * @author sgreb@communicode.de 33 | * @since 0.2.0 34 | */ 35 | @ControllerAdvice 36 | public class KeyCategoryControllerExceptionHandler extends GlobalControllerExceptionHandler { 37 | 38 | /** 39 | * Handles all exceptions of type {@link KeyCategoryConflictException}. 40 | * 41 | * @param exception the exception to handle 42 | * @return the error as response entity 43 | */ 44 | @ExceptionHandler(KeyCategoryConflictException.class) 45 | public ResponseEntity handleKeyCategoryConflictException(final KeyCategoryConflictException exception) { 46 | return createErrorResponse(HttpStatus.CONFLICT, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 47 | } 48 | 49 | /** 50 | * Handles all exceptions of type {@link KeyCategoryNotFoundException}. 51 | * 52 | * @param exception the exception to handle 53 | * @return the error as response entity 54 | */ 55 | @ExceptionHandler(KeyCategoryNotFoundException.class) 56 | public ResponseEntity handleKeyCategoryNotFoundException(final KeyCategoryNotFoundException exception) { 57 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/CorsFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import java.io.IOException; 21 | 22 | import javax.servlet.Filter; 23 | import javax.servlet.FilterChain; 24 | import javax.servlet.FilterConfig; 25 | import javax.servlet.ServletException; 26 | import javax.servlet.ServletRequest; 27 | import javax.servlet.ServletResponse; 28 | import javax.servlet.http.HttpServletRequest; 29 | import javax.servlet.http.HttpServletResponse; 30 | 31 | import com.google.common.net.HttpHeaders; 32 | import org.apache.logging.log4j.LogManager; 33 | import org.apache.logging.log4j.Logger; 34 | import org.springframework.stereotype.Component; 35 | 36 | @Component 37 | public class CorsFilter implements Filter { 38 | 39 | private static final Logger log = LogManager.getLogger(); 40 | 41 | public CorsFilter() { 42 | log.debug("Initialize CORS filter"); 43 | } 44 | 45 | @Override 46 | public void init(FilterConfig filterConfig) throws ServletException { 47 | // No configuration necessary 48 | } 49 | 50 | @Override 51 | public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { 52 | 53 | HttpServletRequest request = (HttpServletRequest) req; 54 | HttpServletResponse response = (HttpServletResponse) res; 55 | 56 | response.setHeader("Access-Control-Allow-Origin", response.getHeader(HttpHeaders.ORIGIN)); 57 | response.setHeader("Access-Control-Allow-Credentials", "true"); 58 | response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS"); 59 | response.setHeader("Access-Control-Max-Age", "-1"); 60 | response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, Authorization"); 61 | response.setHeader("Access-Control-Expose-Headers", "Location"); 62 | 63 | chain.doFilter(req, res); 64 | } 65 | 66 | @Override 67 | public void destroy() { 68 | // Handled by Spring 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/util/DefaultProfileUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config.util; 19 | 20 | import com.google.common.collect.Maps; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.core.env.Environment; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Utility class to load a Spring profile to be used as default when the {@code spring.profiles.active} is not set in the environment or as command line 28 | * argument. 29 | * 30 | *

If the value is not available in {@code application.yml} then the {@code dev} profile will be used as default. 31 | * 32 | * @author sgreb@communicode.de 33 | * @since 0.2.0 34 | */ 35 | public final class DefaultProfileUtil { 36 | 37 | private static final String SPRING_PROFILE_DEFAULT = "spring.profiles.default"; 38 | 39 | public static final String COMMUNIKEY_PROFILE_DEVELOPMENT = "dev"; 40 | public static final String COMMUNIKEY_PROFILE_TEST = "test"; 41 | public static final String COMMUNIKEY_PROFILE_INTEGRATION_TEST = "integration-test"; 42 | public static final String COMMUNIKEY_PROFILE_PRODUCTION = "prod"; 43 | 44 | private DefaultProfileUtil() {} 45 | 46 | /** 47 | * Set the default profile to use when no profile is configured. 48 | * 49 | * @param app the Spring application 50 | */ 51 | public static void addDefaultProfile(SpringApplication app) { 52 | Map defProperties = Maps.newConcurrentMap(); 53 | defProperties.put(SPRING_PROFILE_DEFAULT, COMMUNIKEY_PROFILE_DEVELOPMENT); 54 | app.setDefaultProperties(defProperties); 55 | } 56 | 57 | /** 58 | * Get the profiles that are applied else get default profiles. 59 | * 60 | * @param env the environment 61 | */ 62 | public static String[] getActiveProfiles(Environment env) { 63 | String[] profiles = env.getActiveProfiles(); 64 | if (profiles.length == 0) { 65 | return env.getDefaultProfiles(); 66 | } 67 | return profiles; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/payload/UserPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service.payload; 19 | 20 | import static de.communicode.communikey.config.SecurityConfig.EMAIL_REGEX; 21 | 22 | import de.communicode.communikey.domain.User; 23 | import javax.validation.constraints.NotBlank; 24 | 25 | import javax.validation.constraints.Pattern; 26 | 27 | /** 28 | * A payload object for a {@link User}. 29 | * 30 | * @author sgreb@communicode.de 31 | * @since 0.2.0 32 | */ 33 | public class UserPayload { 34 | 35 | private Long id; 36 | 37 | private String login; 38 | 39 | @NotBlank 40 | @Pattern(regexp = EMAIL_REGEX, message = "not a well-formed email address") 41 | private String email; 42 | 43 | @NotBlank 44 | private String firstName; 45 | 46 | @NotBlank 47 | private String lastName; 48 | 49 | public UserPayload() {} 50 | 51 | public UserPayload(User user) { 52 | this.id = user.getId(); 53 | this.login = user.getLogin(); 54 | this.email = user.getEmail(); 55 | this.firstName = user.getFirstName(); 56 | this.lastName = user.getLastName(); 57 | } 58 | 59 | public Long getId() { 60 | return id; 61 | } 62 | 63 | public void setId(Long id) { 64 | this.id = id; 65 | } 66 | 67 | public String getLogin() { 68 | return login; 69 | } 70 | 71 | public void setLogin(String login) { 72 | this.login = login; 73 | } 74 | 75 | public String getEmail() { 76 | return email.trim(); 77 | } 78 | 79 | public String getFirstName() { 80 | return firstName.trim(); 81 | } 82 | 83 | public String getLastName() { 84 | return lastName.trim(); 85 | } 86 | 87 | @Override 88 | public String toString() { 89 | return "UserPayload{" + 90 | "id=" + id + 91 | ", login='" + login + '\'' + 92 | ", email='" + email + '\'' + 93 | ", firstName='" + firstName + '\'' + 94 | ", lastName='" + lastName + '\'' + 95 | '}'; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/repository/EncryptionJobRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.repository; 19 | 20 | import de.communicode.communikey.domain.EncryptionJob; 21 | import de.communicode.communikey.domain.Key; 22 | import de.communicode.communikey.domain.User; 23 | import org.springframework.data.repository.CrudRepository; 24 | import org.springframework.stereotype.Repository; 25 | import org.springframework.transaction.annotation.Transactional; 26 | 27 | import java.util.Set; 28 | 29 | /** 30 | * A repository for {@link EncryptionJob} entities. 31 | * 32 | * @author dvonderbey@communicode.de 33 | * @since 0.15.0 34 | */ 35 | @Repository 36 | public interface EncryptionJobRepository extends CrudRepository { 37 | 38 | /** 39 | * Finds all encryption job entities of the repository. 40 | * 41 | * @return a collection of found encryption job entities 42 | */ 43 | @Override 44 | Set findAll(); 45 | 46 | /** 47 | * Finds the encryption job with the specified token 48 | * 49 | * @param token the token 50 | * @return the encryption job 51 | */ 52 | EncryptionJob findByToken(String token); 53 | 54 | /** 55 | * Finds the encryption job with the specified user and token 56 | * 57 | * @param user the user for whom the job is there 58 | * @param key the key contained in the job 59 | * @return the encryption job 60 | */ 61 | EncryptionJob findByUserAndKey(User user, Key key); 62 | 63 | /** 64 | * Deletes every encryption job of the specified key. 65 | * 66 | * @param key The key of which the encryption jobs should be deleted 67 | */ 68 | @Transactional 69 | void deleteByKey(Key key); 70 | 71 | /** 72 | * Deletes the encryption job with the specified token 73 | * 74 | * @param token The token of the encryption job 75 | */ 76 | @Transactional 77 | void deleteByToken(String token); 78 | 79 | /** 80 | * Deletes all encryption job of the specified user 81 | * 82 | * @param user The user of the encryption job 83 | */ 84 | @Transactional 85 | void removeAllByUser(User user); 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/service/AuthorityService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.service; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | import static java.util.Optional.ofNullable; 22 | 23 | import de.communicode.communikey.domain.Authority; 24 | import de.communicode.communikey.exception.AuthorityNotFoundException; 25 | import de.communicode.communikey.repository.AuthorityRepository; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.stereotype.Service; 28 | 29 | import java.util.HashSet; 30 | import java.util.Set; 31 | 32 | /** 33 | * The REST API service to process {@link Authority}s via a {@link AuthorityRepository}. 34 | * 35 | * @author sgreb@communicode.de 36 | * @since 0.3.0 37 | */ 38 | @Service 39 | public class AuthorityService { 40 | 41 | private final AuthorityRepository authorityRepository; 42 | 43 | @Autowired 44 | public AuthorityService(AuthorityRepository authorityRepository) { 45 | this.authorityRepository = requireNonNull(authorityRepository, "authorityRepository must not be null!"); 46 | } 47 | 48 | /** 49 | * Gets the authority with the specified name. 50 | * 51 | * @param authorityName the name of the authority to get 52 | * @return the authority 53 | * @throws AuthorityNotFoundException if the authority with the specified name has not been found 54 | */ 55 | public Authority get(String authorityName) throws AuthorityNotFoundException { 56 | return validate(authorityName); 57 | } 58 | 59 | /** 60 | * Gets all authorities. 61 | * 62 | * @return a collection of all authorities 63 | */ 64 | public Set getAll() { 65 | return new HashSet<>(authorityRepository.findAll()); 66 | } 67 | 68 | /** 69 | * Validates a authority. 70 | * 71 | * @param authorityName the name of the authority to validate 72 | * @return the key if validated 73 | * @throws AuthorityNotFoundException if the authority with the specified name has not been found 74 | */ 75 | public Authority validate(String authorityName) throws AuthorityNotFoundException { 76 | return ofNullable(authorityRepository.findOneByName(authorityName)).orElseThrow(() -> new AuthorityNotFoundException(authorityName)); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/integration-test/java/de/communicode/communikey/api/ApiRootIt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package de.communicode.communikey.api; 20 | 21 | import static de.communicode.communikey.CommunikeyApplication.COMMUNIKEY_REST_API_VERSION; 22 | import static io.restassured.RestAssured.given; 23 | import static org.hamcrest.CoreMatchers.equalTo; 24 | 25 | import de.communicode.communikey.IntegrationBaseTest; 26 | import de.communicode.communikey.controller.RequestMappings; 27 | import de.communicode.communikey.controller.RequestParameter; 28 | import org.junit.Test; 29 | import org.springframework.http.HttpStatus; 30 | 31 | /** 32 | * Integration tests for the REST API root endpoints. 33 | * 34 | * @author sgreb@communicode.de 35 | * @since 0.4.0 36 | */ 37 | public class ApiRootIt extends IntegrationBaseTest { 38 | 39 | @Test 40 | public void testGetVersionAsAdmin() { 41 | given() 42 | .auth().oauth2(adminUserOAuth2AccessToken) 43 | .param(RequestParameter.API_VERSION) 44 | .when() 45 | .get(RequestMappings.API) 46 | .then() 47 | .statusCode(HttpStatus.OK.value()) 48 | .body("version", equalTo(COMMUNIKEY_REST_API_VERSION)); 49 | } 50 | 51 | @Test 52 | public void testGetVersionAsUser() { 53 | given() 54 | .auth().oauth2(userOAuth2AccessToken) 55 | .param(RequestParameter.API_VERSION) 56 | .when() 57 | .get(RequestMappings.API) 58 | .then() 59 | .statusCode(HttpStatus.OK.value()) 60 | .body("version", equalTo(COMMUNIKEY_REST_API_VERSION)); 61 | } 62 | 63 | @Test 64 | public void testIsPrivilegedAsAdmin() { 65 | given() 66 | .auth().oauth2(adminUserOAuth2AccessToken) 67 | .param(RequestParameter.API_ME) 68 | .when() 69 | .get(RequestMappings.API) 70 | .then() 71 | .statusCode(HttpStatus.OK.value()) 72 | .body("privileged", equalTo(true)); 73 | } 74 | 75 | @Test 76 | public void testIsPrivilegedAsUser() { 77 | given() 78 | .auth().oauth2(userOAuth2AccessToken) 79 | .param(RequestParameter.API_ME) 80 | .when() 81 | .get(RequestMappings.API) 82 | .then() 83 | .statusCode(HttpStatus.OK.value()) 84 | .body("privileged", equalTo(false)); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/integration-test/java/de/communicode/communikey/api/AuthorityApiIt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package de.communicode.communikey.api; 20 | 21 | import static io.restassured.RestAssured.given; 22 | import static org.hamcrest.CoreMatchers.equalTo; 23 | import static org.hamcrest.CoreMatchers.not; 24 | 25 | import de.communicode.communikey.IntegrationBaseTest; 26 | import de.communicode.communikey.controller.RequestMappings; 27 | import de.communicode.communikey.domain.Authority; 28 | import de.communicode.communikey.security.AuthoritiesConstants; 29 | import org.junit.Test; 30 | import org.springframework.http.HttpStatus; 31 | 32 | /** 33 | * Integration tests for the {@link Authority} REST API. 34 | * 35 | * @author sgreb@communicode.de 36 | * @since 0.4.0 37 | */ 38 | public class AuthorityApiIt extends IntegrationBaseTest { 39 | 40 | @Test 41 | public void testGetAuthorityAsAdmin() { 42 | given() 43 | .auth().oauth2(adminUserOAuth2AccessToken) 44 | .pathParam("authorityName", AuthoritiesConstants.ADMIN) 45 | .when() 46 | .get(RequestMappings.AUTHORITIES + RequestMappings.AUTHORITIES_NAME) 47 | .then() 48 | .statusCode(HttpStatus.OK.value()) 49 | .assertThat().extract().body().as(Authority.class).getName().equals(AuthoritiesConstants.ADMIN); 50 | } 51 | 52 | @Test 53 | public void testGetAuthorityAsUser() { 54 | given() 55 | .auth().oauth2(userOAuth2AccessToken) 56 | .pathParam("authorityName", AuthoritiesConstants.ADMIN) 57 | .when() 58 | .get(RequestMappings.AUTHORITIES + RequestMappings.AUTHORITIES_NAME) 59 | .then() 60 | .statusCode(HttpStatus.FORBIDDEN.value()); 61 | } 62 | 63 | @Test 64 | public void testGetAllAuthoritiesAsAdmin() { 65 | given() 66 | .auth().oauth2(adminUserOAuth2AccessToken) 67 | .when() 68 | .get(RequestMappings.AUTHORITIES) 69 | .then() 70 | .statusCode(HttpStatus.OK.value()) 71 | .body("size()", not(equalTo(0))); 72 | } 73 | 74 | @Test 75 | public void testGetAllAuthoritiesAsUser() { 76 | given() 77 | .auth().oauth2(userOAuth2AccessToken) 78 | .when() 79 | .get(RequestMappings.AUTHORITIES) 80 | .then() 81 | .statusCode(HttpStatus.FORBIDDEN.value()); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/RestViewConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import com.fasterxml.jackson.annotation.JsonView; 21 | import de.communicode.communikey.domain.Authority; 22 | import de.communicode.communikey.security.AuthoritiesConstants; 23 | import de.communicode.communikey.service.view.AuthoritiesRestView; 24 | import org.springframework.core.MethodParameter; 25 | import org.springframework.http.MediaType; 26 | import org.springframework.http.converter.json.MappingJacksonValue; 27 | import org.springframework.http.server.ServerHttpRequest; 28 | import org.springframework.http.server.ServerHttpResponse; 29 | import org.springframework.security.core.Authentication; 30 | import org.springframework.security.core.GrantedAuthority; 31 | import org.springframework.security.core.context.SecurityContextHolder; 32 | import org.springframework.web.bind.annotation.ControllerAdvice; 33 | import org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice; 34 | 35 | import java.util.Optional; 36 | import java.util.function.Predicate; 37 | 38 | /** 39 | * Configuration for {@link JsonView} annotated entity attributes to allow {@link Authority} based JSON response (de)serialization. 40 | * 41 | * @author sgreb@communicode.de 42 | * @author tkabus@communicode.de 43 | * @since 0.2.0 44 | */ 45 | @ControllerAdvice 46 | public class RestViewConfiguration extends AbstractMappingJacksonResponseBodyAdvice { 47 | 48 | @Override 49 | protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, 50 | ServerHttpResponse response) { 51 | Predicate checkForAdmin = authority -> authority.equals(AuthoritiesConstants.ADMIN); 52 | 53 | Class viewClass = Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication()) 54 | .map(Authentication::getAuthorities) 55 | .filter(authorities -> authorities.stream() 56 | .map(GrantedAuthority::getAuthority) 57 | .anyMatch(checkForAdmin)) 58 | .>map(isTrue -> AuthoritiesRestView.Admin.class) 59 | .orElse(AuthoritiesRestView.User.class); 60 | bodyContainer.setSerializationView(viewClass); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import org.springframework.beans.factory.annotation.Value; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | import org.springframework.core.io.Resource; 25 | import org.springframework.data.jpa.repository.config.EnableJpaAuditing; 26 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 27 | import org.springframework.jdbc.datasource.init.DataSourceInitializer; 28 | import org.springframework.jdbc.datasource.init.DatabasePopulator; 29 | import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; 30 | 31 | import javax.sql.DataSource; 32 | 33 | import static java.util.Objects.requireNonNull; 34 | 35 | /** 36 | * Initializes the OAuth2 database schema and enables the JPA repository auditing. 37 | * 38 | * @author sgreb@communicode.de 39 | * @since 0.2.0 40 | */ 41 | @Configuration 42 | @EnableJpaRepositories("de.communicode.communikey.repository") 43 | @EnableJpaAuditing(auditorAwareRef = "securityAuditorAware") 44 | public class DataSourceConfig { 45 | 46 | private DataSource dataSource; 47 | 48 | @Value("classpath:schema.sql") 49 | private Resource schemaScript; 50 | 51 | @Autowired 52 | DataSourceConfig(DataSource dataSource) { 53 | requireNonNull(dataSource, "dataSource must not be null!"); 54 | } 55 | 56 | /** 57 | * The bean to initialize the database. 58 | * 59 | * @param dataSource the datasource bean 60 | * @return the data source initializer bean 61 | */ 62 | @Bean 63 | DataSourceInitializer dataSourceInitializer(DataSource dataSource) { 64 | DataSourceInitializer initializer = new DataSourceInitializer(); 65 | initializer.setDataSource(dataSource); 66 | initializer.setDatabasePopulator(databasePopulator()); 67 | return initializer; 68 | } 69 | 70 | /** 71 | * Populates the database with schema scripts. 72 | * 73 | *

Currently runs the SQL script for 74 | *

    75 | *
  • OAuth2
  • 76 | *
77 | * 78 | * @return the database populator object 79 | */ 80 | private DatabasePopulator databasePopulator() { 81 | ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); 82 | populator.addScript(schemaScript); 83 | return populator; 84 | } 85 | } -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/repository/UserEncryptedPasswordRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.repository; 19 | 20 | import de.communicode.communikey.domain.Key; 21 | import de.communicode.communikey.domain.User; 22 | import de.communicode.communikey.domain.UserEncryptedPassword; 23 | import org.springframework.data.repository.CrudRepository; 24 | import org.springframework.stereotype.Repository; 25 | import org.springframework.transaction.annotation.Transactional; 26 | 27 | import java.util.Set; 28 | 29 | /** 30 | * A repository for {@link UserEncryptedPassword} entities. 31 | * 32 | * @author dvonderbey@communicode.de 33 | * @since 0.15.0 34 | */ 35 | @Repository 36 | public interface UserEncryptedPasswordRepository extends CrudRepository { 37 | /** 38 | * Finds all key entities of the repository. 39 | * 40 | * @return a collection of found key entities 41 | */ 42 | @Override 43 | Set findAll(); 44 | 45 | /** 46 | * Finds all UserEncryptedPassword entities of the 47 | * repository with the specified key. 48 | * 49 | * @param owner the user that owns the passwords 50 | * @param key the key of the password 51 | * @return the found UserEncryptedPassword entity 52 | */ 53 | UserEncryptedPassword findOneByOwnerAndKey(User owner, Key key); 54 | 55 | /** 56 | * Finds all UserEncryptedPassword entities of the 57 | * repository with the specified key. 58 | * 59 | * @param owner the user that owns the passwords 60 | * @return a collection of found UserEncryptedPassword entities 61 | */ 62 | Set findAllByOwner(User owner); 63 | 64 | /** 65 | * Finds all UserEncryptedPassword entities of the repository with the specified key. 66 | * 67 | * @param key the key 68 | * @return a collection of found UserEncryptedPassword entities 69 | */ 70 | Set findAllByKey(Key key); 71 | 72 | /** 73 | * Deletes all user encrypted passwords owned by 74 | * the specified user. 75 | * 76 | * @param owner the user that owns the password 77 | */ 78 | @Transactional 79 | void removeAllByOwner(User owner); 80 | 81 | /** 82 | * Deletes all user encrypted passwords that reference 83 | * the specified key. 84 | * 85 | * @param key the key 86 | */ 87 | @Transactional 88 | void deleteByKey(Key key); 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/security/RestUserDetailsService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.security; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | import static java.util.Optional.ofNullable; 22 | 23 | import de.communicode.communikey.domain.User; 24 | import de.communicode.communikey.exception.UserNotActivatedException; 25 | import de.communicode.communikey.exception.UserNotFoundException; 26 | import de.communicode.communikey.repository.UserRepository; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | import org.springframework.security.core.GrantedAuthority; 29 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 30 | import org.springframework.security.core.userdetails.UserDetails; 31 | import org.springframework.security.core.userdetails.UserDetailsService; 32 | import org.springframework.stereotype.Component; 33 | import org.springframework.transaction.annotation.Transactional; 34 | 35 | import java.util.List; 36 | import java.util.Optional; 37 | import java.util.stream.Collectors; 38 | 39 | /** 40 | * The user details service which maps {@link User} entities to Springs {@link org.springframework.security.core.userdetails.User} entity. 41 | * 42 | * @author sgreb@communicode.de 43 | * @since 0.2.0 44 | */ 45 | @Component("userDetailsService") 46 | public class RestUserDetailsService implements UserDetailsService { 47 | 48 | private final UserRepository userRepository; 49 | 50 | @Autowired 51 | public RestUserDetailsService(UserRepository userRepository) { 52 | this.userRepository = requireNonNull(userRepository, "userRepository must not be null!"); 53 | } 54 | 55 | @Override 56 | @Transactional 57 | public UserDetails loadUserByUsername(final String login) { 58 | Optional userFromDatabase = ofNullable(userRepository.findOneWithAuthoritiesByLogin(login)); 59 | return userFromDatabase.map(user -> { 60 | if (!user.isActivated()) { 61 | throw new UserNotActivatedException(login); 62 | } 63 | List grantedAuthorities = user.getAuthorities().stream() 64 | .map(authority -> new SimpleGrantedAuthority(authority.getName())) 65 | .collect(Collectors.toList()); 66 | return new org.springframework.security.core.userdetails.User(login, user.getPassword(), grantedAuthorities); 67 | }).orElseThrow(() -> new UserNotFoundException(login)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/domain/UserEncryptedPassword.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.domain; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIdentityInfo; 21 | import com.fasterxml.jackson.annotation.JsonIdentityReference; 22 | import com.fasterxml.jackson.annotation.ObjectIdGenerators; 23 | 24 | import javax.persistence.*; 25 | import javax.validation.constraints.NotNull; 26 | import javax.validation.constraints.NotBlank; 27 | import java.io.Serializable; 28 | 29 | /** 30 | * Represents a key. 31 | * 32 | * @author dvonderbey@communicode.de 33 | * @since 0.15.0 34 | */ 35 | @Entity 36 | @Table(name = "user_encrypted_passwords") 37 | public class UserEncryptedPassword extends AbstractEntity implements Serializable { 38 | 39 | private static final long serialVersionUID = 1; 40 | 41 | @Id 42 | @GeneratedValue(strategy = GenerationType.IDENTITY) 43 | private Long id; 44 | 45 | @ManyToOne 46 | @JoinColumn(name = "key_id") 47 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") 48 | @JsonIdentityReference(alwaysAsId = true) 49 | private Key key; 50 | 51 | @ManyToOne 52 | @JoinColumn(name = "owner_user_id", nullable = false) 53 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") 54 | @JsonIdentityReference(alwaysAsId = true) 55 | private User owner; 56 | 57 | @NotNull 58 | @NotBlank 59 | @Lob 60 | @Column(nullable = false) 61 | private String password; 62 | 63 | public Long getId() { 64 | return id; 65 | } 66 | 67 | public void setId(Long id) { 68 | this.id = id; 69 | } 70 | 71 | public Key getKey() { 72 | return key; 73 | } 74 | 75 | public void setKey(Key key) { 76 | this.key = key; 77 | } 78 | 79 | public User getOwner() { 80 | return owner; 81 | } 82 | 83 | public void setOwner(User owner) { 84 | this.owner = owner; 85 | } 86 | 87 | public String getPassword() { 88 | return password; 89 | } 90 | 91 | public void setPassword(String password) { 92 | this.password = password; 93 | } 94 | 95 | @Override 96 | public String toString() { 97 | return "UserEncryptedPassword{" + 98 | "id=" + id + 99 | ", key=" + key.getId() + 100 | ", owner=" + owner.getId() + 101 | '}'; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/domain/AbstractEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.domain; 19 | 20 | import com.fasterxml.jackson.annotation.JsonView; 21 | import de.communicode.communikey.service.view.AuthoritiesRestView; 22 | import org.springframework.data.annotation.CreatedBy; 23 | import org.springframework.data.annotation.CreatedDate; 24 | import org.springframework.data.annotation.LastModifiedBy; 25 | import org.springframework.data.annotation.LastModifiedDate; 26 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; 27 | 28 | import javax.persistence.Column; 29 | import javax.persistence.EntityListeners; 30 | import javax.persistence.MappedSuperclass; 31 | 32 | import java.io.Serializable; 33 | import java.time.Instant; 34 | 35 | /** 36 | * Base abstract class for entities which holds creation- and modification attributes. 37 | * 38 | * @author sgreb@communicode.de 39 | * @since 0.2.0 40 | */ 41 | @MappedSuperclass 42 | @EntityListeners(AuditingEntityListener.class) 43 | public abstract class AbstractEntity implements Serializable { 44 | 45 | private static final long serialVersionUID = 1; 46 | 47 | @CreatedBy 48 | @Column(name = "created_by", length = 50, updatable = false) 49 | @JsonView(AuthoritiesRestView.Admin.class) 50 | private String createdBy; 51 | 52 | @CreatedDate 53 | @Column(name = "created_date", nullable = false) 54 | @JsonView(AuthoritiesRestView.Admin.class) 55 | private Instant createdDate = Instant.now(); 56 | 57 | @LastModifiedBy 58 | @Column(name = "last_modified_by", length = 50) 59 | @JsonView(AuthoritiesRestView.Admin.class) 60 | private String lastModifiedBy; 61 | 62 | @LastModifiedDate 63 | @Column(name = "last_modified_date") 64 | @JsonView(AuthoritiesRestView.Admin.class) 65 | private Instant lastModifiedDate = Instant.now(); 66 | 67 | public String getCreatedBy() { 68 | return createdBy; 69 | } 70 | 71 | public void setCreatedBy(String createdBy) { 72 | this.createdBy = createdBy; 73 | } 74 | 75 | public Instant getCreatedDate() { 76 | return createdDate; 77 | } 78 | 79 | public void setCreatedDate(Instant createdDate) { 80 | this.createdDate = createdDate; 81 | } 82 | 83 | public String getLastModifiedBy() { 84 | return lastModifiedBy; 85 | } 86 | 87 | public void setLastModifiedBy(String lastModifiedBy) { 88 | this.lastModifiedBy = lastModifiedBy; 89 | } 90 | 91 | public Instant getLastModifiedDate() { 92 | return lastModifiedDate; 93 | } 94 | 95 | public void setLastModifiedDate(Instant lastModifiedDate) { 96 | this.lastModifiedDate = lastModifiedDate; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/CommunikeyApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey; 19 | 20 | import static de.communicode.communikey.config.util.DefaultProfileUtil.COMMUNIKEY_PROFILE_DEVELOPMENT; 21 | import static de.communicode.communikey.config.util.DefaultProfileUtil.COMMUNIKEY_PROFILE_PRODUCTION; 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import de.communicode.communikey.config.CommunikeyProperties; 25 | import de.communicode.communikey.config.util.DefaultProfileUtil; 26 | import org.apache.logging.log4j.LogManager; 27 | import org.apache.logging.log4j.Logger; 28 | import org.springframework.beans.factory.annotation.Autowired; 29 | import org.springframework.boot.SpringApplication; 30 | import org.springframework.boot.autoconfigure.SpringBootApplication; 31 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 32 | import org.springframework.core.env.Environment; 33 | 34 | import javax.annotation.PostConstruct; 35 | 36 | import java.util.Arrays; 37 | import java.util.Collection; 38 | 39 | /** 40 | * A simple centralized, cross-platform credential manager. 41 | * 42 | *

This is the application boot class. 43 | * 44 | * @author sgreb@communicode.de 45 | * @since 0.1.0 46 | */ 47 | @SpringBootApplication 48 | @EnableConfigurationProperties(CommunikeyProperties.class) 49 | public class CommunikeyApplication { 50 | 51 | private static final Logger log = LogManager.getLogger(); 52 | 53 | private final Environment env; 54 | public static final String COMMUNIKEY_REST_API_VERSION = "0.2.0"; 55 | 56 | @Autowired 57 | public CommunikeyApplication(Environment env) { 58 | this.env = requireNonNull(env, "env must not be null!"); 59 | } 60 | 61 | /** 62 | * Initializes the communikey application. 63 | */ 64 | @PostConstruct 65 | public void bootstrap() { 66 | Collection activeProfiles = Arrays.asList(env.getActiveProfiles()); 67 | if (activeProfiles.contains(COMMUNIKEY_PROFILE_DEVELOPMENT) && activeProfiles.contains(COMMUNIKEY_PROFILE_PRODUCTION)) { 68 | log.error("Application misconfiguration detected, it should not run with both the 'dev' and 'prod' profiles at the same time!"); 69 | } 70 | } 71 | 72 | /** 73 | * Runs the application. 74 | * 75 | * @param args the command line arguments 76 | */ 77 | public static void main(String[] args) { 78 | SpringApplication app = new SpringApplication(CommunikeyApplication.class); 79 | DefaultProfileUtil.addDefaultProfile(app); 80 | Environment env = app.run(args).getEnvironment(); 81 | log.info("Application '{}' is running! Active Profile(s): {}", env.getProperty("spring.application.name"), env.getActiveProfiles()); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/controller/AuthorityController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.controller; 19 | 20 | import static de.communicode.communikey.controller.RequestMappings.AUTHORITIES; 21 | import static de.communicode.communikey.controller.RequestMappings.AUTHORITIES_NAME; 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import de.communicode.communikey.domain.Authority; 25 | import de.communicode.communikey.exception.AuthorityNotFoundException; 26 | import de.communicode.communikey.security.AuthoritiesConstants; 27 | import de.communicode.communikey.service.AuthorityService; 28 | import org.springframework.beans.factory.annotation.Autowired; 29 | import org.springframework.http.HttpStatus; 30 | import org.springframework.http.ResponseEntity; 31 | import org.springframework.security.access.annotation.Secured; 32 | import org.springframework.web.bind.annotation.GetMapping; 33 | import org.springframework.web.bind.annotation.PathVariable; 34 | import org.springframework.web.bind.annotation.RequestMapping; 35 | import org.springframework.web.bind.annotation.RestController; 36 | 37 | import java.util.Set; 38 | 39 | /** 40 | * The REST API controller to process {@link Authority} entities. 41 | * 42 | *

Mapped to the "{@value RequestMappings#AUTHORITIES}" endpoint. 43 | * 44 | * @author sgreb@communicode.de 45 | * @since 0.3.0 46 | */ 47 | @RestController 48 | @RequestMapping(AUTHORITIES) 49 | public class AuthorityController { 50 | 51 | private final AuthorityService authorityService; 52 | 53 | @Autowired 54 | public AuthorityController(AuthorityService authorityService) { 55 | this.authorityService = requireNonNull(authorityService, "authorityService must not be null!"); 56 | } 57 | 58 | /** 59 | * Gets the authority with the specified name. 60 | * 61 | *

This endpoint is mapped to "{@value RequestMappings#AUTHORITIES}{@value RequestMappings#AUTHORITIES_NAME}". 62 | * 63 | * @param authorityName the name of the authority to get 64 | * @return the authority as response entity 65 | * @throws AuthorityNotFoundException if the authority with the specified name has not been found 66 | */ 67 | @GetMapping(value = AUTHORITIES_NAME) 68 | @Secured(AuthoritiesConstants.ADMIN) 69 | ResponseEntity get(@PathVariable String authorityName) throws AuthorityNotFoundException { 70 | return new ResponseEntity<>(authorityService.get(authorityName), HttpStatus.OK); 71 | } 72 | 73 | /** 74 | * Gets all authorities. 75 | * 76 | *

This endpoint is mapped to "{@value RequestMappings#AUTHORITIES}". 77 | * 78 | * @return a collection of all authorities as response entity 79 | */ 80 | @GetMapping 81 | @Secured(AuthoritiesConstants.ADMIN) 82 | ResponseEntity> getAll() { 83 | return new ResponseEntity<>(authorityService.getAll(), HttpStatus.OK); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Enhancement Suggestions 3 | about: Submit an enhancement suggestion for new features or minor improvements to existing functionality 4 | 5 | --- 6 | 7 | 8 | 9 | > **Please read the [contribution guidelines](https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md) before filling out this issue template**. 10 | 11 | ## Prerequisites 12 | 13 | This section and the instructions in the sections below are only part of this issue template. Please ensure to **delete this whole section, all pre-filled instructions of the sections below and sections you have not filled out before submitting** to ensure a clear structure and overview. 14 | 15 | Please do your best to provide as much information as possible and use a clear and descriptive title for your enhancement suggestion to help maintainers and the community understand and reproduce the behavior, find related reports and to resolve the ticket faster. 16 | 17 | * **Ensure the issue has not already been reported by using the [GitHub Issues search](https://github.com/communicode/communikey-backend/issues)** — if it has **and the issue is still open**, add a comment to the existing issue instead of opening this new one. If you find a closed issue that seems to be similar to this one, include a link to the original issue in the [metadata head](#metadata-head) section of this issue. 18 | * **Ensure the contribution belongs to the correct [communikey repository](https://github.com/communicode?q=communikey).** 19 | * If your feature request 20 | * **Ensure the issue is reproducible** — try to use the [latest version](https://github.com/communicode/communikey-backend/releases/latest) and [`develop`](https://github.com/communicode/communikey-backend/tree/develop) branch. 21 | 22 | ## Metadata Head 23 | 24 | The metadata head can be added to the top of the issue as [Markdown text quote](https://help.github.com/articles/basic-writing-and-formatting-syntax) containing the ID of other related issues. 25 | 26 | > Related issues: 27 | 28 | ## Description 29 | 30 | Describe the enhancement in many relevant details as possible. 31 | 32 | ### Benefits 33 | 34 | Add specific use-cases and explain why this feature or improvement would be useful and maybe include references to related known problems or bug reports. 35 | 36 | ### Possible Drawbacks 37 | 38 | Describe possible negative impacts regarding e.g. functionality or usability. 39 | 40 | ### Alternative Solutions 41 | 42 | If you've considered alternative features or solutions please describe it clearly and concise. 43 | 44 | ## Example 45 | 46 | Provide a [MCVE - The Minimal, Complete, and Verifiable Example](https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#mcve) 47 | 48 | **This is a optional section, but it can drastically increase the speed at which this issue can be processed since it takes away the time-consuming reconstruction to reproduce the enhancement.** 49 | 50 | The recommended way is to upload it as [Gist](https://gist.github.com) or new repository to GitHub, but of course you can [attach it to this issue](https://help.github.com/articles/file-attachments-on-issues-and-pull-requests), use any free file hosting service or paste the code in [Markdown code blocks](https://help.github.com/articles/basic-writing-and-formatting-syntax) into this issue. 51 | 52 | ## Additional Context 53 | 54 | Add any other context, screenshots or screencasts which are relevant for this issue. 55 | 56 | ## References 57 | 58 | Add any other references and links which are relevant for this issue. 59 | 60 | ## Potential Solution 61 | 62 | Maybe include references to other projects where this enhancement already exists. 63 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/ErrorResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.google.common.collect.Lists; 22 | import org.springframework.http.HttpStatus; 23 | 24 | import java.sql.Timestamp; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * Represents a error response. 30 | * 31 | * @author sgreb@communicode.de 32 | * @since 0.2.0 33 | */ 34 | @JsonInclude(JsonInclude.Include.NON_NULL) 35 | public class ErrorResponse { 36 | 37 | private Timestamp timestamp; 38 | private int status; 39 | private String reason; 40 | private String error; 41 | private List errors; 42 | 43 | /** 44 | * Constructs a new error response with the specified {@link HttpStatus} an a timestamp. 45 | * 46 | * @param httpStatus the HTTP status of the error 47 | * @param timestamp the timestamp of the error 48 | * @param error the error about this error 49 | */ 50 | public ErrorResponse(HttpStatus httpStatus, Timestamp timestamp, String error) { 51 | status = httpStatus.value(); 52 | reason = httpStatus.getReasonPhrase(); 53 | this.timestamp = new Timestamp(timestamp.getTime()); 54 | this.error = error; 55 | } 56 | 57 | /** 58 | * Constructs a new error response with the specified {@link HttpStatus}, a timestamp and a list of all errors. 59 | * 60 | * @param httpStatus the HTTP status of the error 61 | * @param timestamp the timestamp of the error 62 | * @param errors the list of errors 63 | */ 64 | public ErrorResponse(HttpStatus httpStatus, Timestamp timestamp, List errors) { 65 | status = httpStatus.value(); 66 | reason = httpStatus.getReasonPhrase(); 67 | this.timestamp = new Timestamp(timestamp.getTime()); 68 | this.errors = errors; 69 | } 70 | 71 | public String getError() { 72 | return error; 73 | } 74 | 75 | public List getErrors() { 76 | return errors; 77 | } 78 | 79 | public String getReason() { 80 | return reason; 81 | } 82 | 83 | public int getStatus() { 84 | return status; 85 | } 86 | 87 | public Timestamp getTimestamp() { 88 | return new Timestamp(timestamp.getTime()); 89 | } 90 | 91 | public void setError(String error) { 92 | this.error = error; 93 | } 94 | 95 | public void setErrors(List errors) { 96 | this.errors = errors; 97 | } 98 | 99 | public void setReason(String reason) { 100 | this.reason = reason; 101 | } 102 | 103 | public void setStatus(int status) { 104 | this.status = status; 105 | } 106 | 107 | public void setTimestamp(Timestamp timestamp) { 108 | this.timestamp = new Timestamp(timestamp.getTime()); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /assets/communikey-logo-light.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/domain/Tag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.domain; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIdentityInfo; 21 | import com.fasterxml.jackson.annotation.JsonIdentityReference; 22 | import com.fasterxml.jackson.annotation.JsonIgnore; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | import com.fasterxml.jackson.annotation.ObjectIdGenerators; 25 | 26 | import javax.validation.constraints.NotBlank; 27 | import javax.persistence.Column; 28 | import javax.persistence.Entity; 29 | import javax.persistence.GeneratedValue; 30 | import javax.persistence.GenerationType; 31 | import javax.persistence.Id; 32 | import javax.persistence.JoinColumn; 33 | import javax.persistence.ManyToOne; 34 | import javax.persistence.Table; 35 | import java.io.Serializable; 36 | 37 | /** 38 | * Represents a key. 39 | * 40 | * @author dvonderbey@communicode.de 41 | * @since 0.18.0 42 | */ 43 | @Entity 44 | @Table(name = "\"tags\"") 45 | public class Tag extends AbstractEntity implements Serializable { 46 | 47 | private static final long serialVersionUID = 1; 48 | 49 | @Id 50 | @GeneratedValue(strategy = GenerationType.IDENTITY) 51 | @JsonIgnore 52 | private Long id; 53 | 54 | @Column 55 | @JsonProperty("id") 56 | private String hashid; 57 | 58 | @NotBlank 59 | @Column(nullable = false) 60 | private String name; 61 | 62 | @NotBlank 63 | @Column(nullable = false) 64 | private String color; 65 | 66 | @ManyToOne 67 | @JoinColumn(name = "creator_user_id", nullable = false) 68 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") 69 | @JsonIdentityReference(alwaysAsId = true) 70 | private User creator; 71 | 72 | public Long getId() { 73 | return id; 74 | } 75 | 76 | public void setId(Long id) { 77 | this.id = id; 78 | } 79 | 80 | /** 81 | * @return the Hashid 82 | */ 83 | public String getHashid() { 84 | return hashid; 85 | } 86 | 87 | /** 88 | * @param hashid the Hashid 89 | */ 90 | public void setHashid(String hashid) { 91 | this.hashid = hashid; 92 | } 93 | 94 | public String getName() { 95 | return name; 96 | } 97 | 98 | public void setName(String name) { 99 | this.name = name; 100 | } 101 | 102 | public String getColor() { 103 | return color; 104 | } 105 | 106 | public void setColor(String color) { 107 | this.color = color; 108 | } 109 | 110 | public User getCreator() { 111 | return creator; 112 | } 113 | 114 | public void setCreator(User creator) { 115 | this.creator = creator; 116 | } 117 | 118 | @Override 119 | public String toString() { 120 | return "Tag{" + 121 | "id=" + id + 122 | ", name='" + name + '\'' + 123 | ", creator=" + creator + 124 | '}'; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/controller/CrowdEncryptionController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.controller; 19 | 20 | import de.communicode.communikey.domain.EncryptionJob; 21 | import de.communicode.communikey.security.SecurityUtils; 22 | import de.communicode.communikey.service.EncryptionJobService; 23 | import de.communicode.communikey.service.payload.EncryptionJobPayload; 24 | import de.communicode.communikey.service.payload.EncryptionJobStatusPayload; 25 | 26 | import javax.validation.Valid; 27 | import static java.util.Objects.requireNonNull; 28 | 29 | import org.springframework.beans.factory.annotation.Autowired; 30 | import org.springframework.messaging.handler.annotation.DestinationVariable; 31 | import org.springframework.messaging.handler.annotation.MessageMapping; 32 | import org.springframework.messaging.handler.annotation.Payload; 33 | import org.springframework.messaging.simp.annotation.SendToUser; 34 | import org.springframework.messaging.simp.annotation.SubscribeMapping; 35 | import org.springframework.stereotype.Controller; 36 | import org.springframework.transaction.annotation.Transactional; 37 | 38 | import static de.communicode.communikey.controller.RequestMappings.JOBS_FULFILL; 39 | import static de.communicode.communikey.controller.PathVariables.JOB_TOKEN; 40 | import static de.communicode.communikey.controller.RequestMappings.QUEUE_JOBS; 41 | import static de.communicode.communikey.controller.RequestMappings.QUEUE_REPLY; 42 | 43 | /** 44 | * The WSS controller to process {@link EncryptionJob} services. 45 | * 46 | * @author dvonderbey@communicode.de 47 | * @since 0.15.0 48 | */ 49 | @Controller 50 | public class CrowdEncryptionController { 51 | 52 | private final EncryptionJobService encryptionJobService; 53 | 54 | @Autowired 55 | public CrowdEncryptionController(EncryptionJobService encryptionJobService) { 56 | this.encryptionJobService = requireNonNull(encryptionJobService, "encryptionJobService must not be null!"); 57 | } 58 | 59 | /** 60 | * Sends the user all his encryption jobs when subscribing. 61 | * 62 | *

This endpoint is mapped to "{@value RequestMappings#QUEUE_JOBS}". 63 | * 64 | */ 65 | @SubscribeMapping(value = QUEUE_JOBS) 66 | public void subscribe() { 67 | encryptionJobService.advertiseJobsToUser(SecurityUtils.getCurrentUserLogin()); 68 | } 69 | 70 | /** 71 | * Handles a job fulfillment from the client to create a user encrypted password. 72 | * 73 | *

This endpoint is mapped to "{@value RequestMappings#JOBS_FULFILL}". 74 | * 75 | * @param jobToken the token of the encryption job 76 | * @param payload the fulfillment payload 77 | * @return the encryption job fulfillment result 78 | * 79 | */ 80 | @MessageMapping(value = JOBS_FULFILL) 81 | @SendToUser(value = QUEUE_REPLY) 82 | @Transactional 83 | public EncryptionJobStatusPayload fulfill(@DestinationVariable(value = JOB_TOKEN) String jobToken, @Payload @Valid EncryptionJobPayload payload) { 84 | return encryptionJobService.fulfill(jobToken, payload); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/domain/EncryptionJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.domain; 19 | 20 | import java.io.Serializable; 21 | 22 | import javax.persistence.Id; 23 | import javax.persistence.Column; 24 | import javax.persistence.Entity; 25 | import javax.persistence.OneToOne; 26 | import javax.persistence.JoinColumn; 27 | import javax.persistence.GenerationType; 28 | import javax.persistence.GeneratedValue; 29 | import javax.persistence.Lob; 30 | import javax.persistence.Table; 31 | 32 | import com.fasterxml.jackson.annotation.JsonIgnore; 33 | import com.fasterxml.jackson.annotation.JsonIdentityInfo; 34 | import com.fasterxml.jackson.annotation.JsonIdentityReference; 35 | import com.fasterxml.jackson.annotation.ObjectIdGenerators; 36 | import de.communicode.communikey.security.SecurityUtils; 37 | 38 | /** 39 | * Represents an encryption job. 40 | * 41 | * @author dvonderbey@communicode.de 42 | * @since 0.15.0 43 | */ 44 | @Entity 45 | @Table(name = "encryption_jobs") 46 | public class EncryptionJob extends AbstractEntity implements Serializable { 47 | 48 | private static final long serialVersionUID = 1; 49 | 50 | @Id 51 | @GeneratedValue(strategy = GenerationType.IDENTITY) 52 | @JsonIgnore 53 | private Long id; 54 | 55 | @Column(unique=true) 56 | private String token; 57 | 58 | @OneToOne 59 | @JoinColumn 60 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") 61 | @JsonIdentityReference(alwaysAsId = true) 62 | private Key key; 63 | 64 | @OneToOne 65 | @JoinColumn 66 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") 67 | @JsonIdentityReference(alwaysAsId = true) 68 | @JsonIgnore 69 | private User user; 70 | 71 | @Column 72 | @Lob 73 | private String publicKey; 74 | 75 | public EncryptionJob() {} 76 | 77 | public EncryptionJob(Key key, User user) { 78 | this.token = SecurityUtils.generateRandomJobToken(); 79 | this.key = key; 80 | this.user = user; 81 | this.publicKey = user.getPublicKey(); 82 | } 83 | 84 | public static long getSerialVersionUID() { 85 | return serialVersionUID; 86 | } 87 | 88 | public Long getId() { 89 | return id; 90 | } 91 | 92 | public void setId(Long id) { 93 | this.id = id; 94 | } 95 | 96 | public String getToken() { 97 | return token; 98 | } 99 | 100 | public void setToken(String token) { 101 | this.token = token; 102 | } 103 | 104 | public Key getKey() { 105 | return key; 106 | } 107 | 108 | public void setKey(Key key) { 109 | this.key = key; 110 | } 111 | 112 | public User getUser() { 113 | return user; 114 | } 115 | 116 | public void setUser(User user) { 117 | this.user = user; 118 | } 119 | 120 | public String getPublicKey() { 121 | return publicKey; 122 | } 123 | 124 | public void setPublicKey(String publicKey) { 125 | this.publicKey = publicKey; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 |

6 | 7 | 8 |

9 | 10 | # communikey 11 | 12 | A simple, centralized, teambased, cross-platform credential manager using GPG encryption. 13 | 14 | ## Prerequisites 15 | 16 | You will need the following things setup & ready for communikey-backend to work: 17 | 18 | - [Java8/OpenJdk8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) 19 | - [Maven](https://maven.apache.org/install.html) 20 | - [Mysql](https://dev.mysql.com/doc/en/installing.html) 21 | 22 | If you need a detailed guide on how to setup a new user & database follow this [link](https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql) 23 | 24 | ## Getting Started 25 | 26 | These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. 27 | 28 | - Clone the project using your favorable way of cloning a github project. 29 | 30 | - Setup a database preferably named "communikey", with a password & username of your choice. See [prerequisites](#prerequisites) for detailed notes. 31 | 32 | - Edit **application-dev.yml** in the **/src/main/resources** folder to reflect your new database, password & username you just created. 33 | 34 | - Move into the project root folder and start it with maven 35 | 36 | - ``` mvn spring-boot run ``` 37 | 38 | - *Please ensure that port 8080 is free, since its used by the application*. 39 | 40 | ## Running tests 41 | 42 | - Move into the project root folder and run the following command 43 | 44 | - ``` mvn integration-tests ``` 45 | 46 | ## Versioning 47 | 48 | We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/communicode/communikey-backend/tags). 49 | 50 | ## Built With 51 | 52 | * [Spring Boot](https://projects.spring.io/spring-boot/) - The application framework used 53 | * [Maven](https://maven.apache.org/) - Dependency Management 54 | 55 | ## Contributing 56 | 57 | Read the [contributing guide][gh-contrib] to learn about the development process and how to propose [enhancement suggestions][gh-contrib-enhancements] and [report bugs][gh-contrib-bug-reports], how to [submit pull requests][gh-contrib-pr] and the project's [styleguides][gh-contrib-styleguides], [branch organization][gh-contrib-branch-org] and [versioning][gh-contrib-versioning] model. 58 | 59 | The guide also includes information about [minimal, complete, and verifiable examples][gh-contrib-mcve] and other ways to contribute to the project like [improving existing issues][gh-contrib-other-improve-issues] and [giving feedback on issues and pull requests][gh-contrib-other-feedback]. 60 | 61 | ## License 62 | 63 | This project is licensed under the GPLv3 license see the [LICENSE.md](LICENSE.md) file for details. 64 | 65 | [gh-contrib]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md 66 | [gh-contrib-branch-org]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#branch-organization 67 | [gh-contrib-bug-reports]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#bug-reports 68 | [gh-contrib-enhancements]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#enhancement-suggestions 69 | [gh-contrib-mcve]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#mcve 70 | [gh-contrib-other-feedback]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#give-feedback-on-issues-and-pull-requests 71 | [gh-contrib-other-improve-issues]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#improve-issues 72 | [gh-contrib-pr]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#pull-requests 73 | [gh-contrib-styleguides]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#styleguides 74 | [gh-contrib-versioning]: https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#versioning 75 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/KeyControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.controller.KeyController; 21 | import org.springframework.http.HttpStatus; 22 | import org.springframework.http.ResponseEntity; 23 | import org.springframework.web.bind.annotation.ControllerAdvice; 24 | import org.springframework.web.bind.annotation.ExceptionHandler; 25 | 26 | import java.sql.Timestamp; 27 | import java.util.Calendar; 28 | 29 | /** 30 | * The exception handler for the {@link KeyController} that returns a error as response entity. 31 | * 32 | * @author sgreb@communicode.de 33 | * @since 0.2.0 34 | */ 35 | @ControllerAdvice 36 | public class KeyControllerExceptionHandler extends GlobalControllerExceptionHandler { 37 | 38 | /** 39 | * Handles all exceptions of type {@link KeyConflictException}. 40 | * 41 | * @param exception the exception to handle 42 | * @return the error as response entity 43 | */ 44 | @ExceptionHandler(KeyConflictException.class) 45 | public ResponseEntity handleKeyConflictException(KeyConflictException exception) { 46 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 47 | } 48 | 49 | /** 50 | * Handles all exceptions of type {@link KeyNotFoundException}. 51 | * 52 | * @param exception the exception to handle 53 | * @return the error as response entity 54 | */ 55 | @ExceptionHandler(KeyNotFoundException.class) 56 | public ResponseEntity handleKeyNotFoundException(KeyNotFoundException exception) { 57 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 58 | } 59 | 60 | /** 61 | * Handles all exceptions of type {@link UserEncryptedPasswordNotFoundException}. 62 | * 63 | * @param exception the exception to handle 64 | * @return the error as response entity 65 | */ 66 | @ExceptionHandler(UserEncryptedPasswordNotFoundException.class) 67 | public ResponseEntity handleKeyNotFoundException(UserEncryptedPasswordNotFoundException exception) { 68 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 69 | } 70 | 71 | /** 72 | * Handles all exceptions of type {@link HashidNotValidException}. 73 | * 74 | * @param exception the exception to handle 75 | * @return the error as response entity 76 | */ 77 | @ExceptionHandler(HashidNotValidException.class) 78 | public ResponseEntity handleHashidNotValidException(HashidNotValidException exception) { 79 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 80 | } 81 | 82 | /** 83 | * Handles all exceptions of type {@link KeyNotAccessibleByUserException}. 84 | * 85 | * @param exception the exception to handle 86 | * @return the error as response entity 87 | */ 88 | @ExceptionHandler(KeyNotAccessibleByUserException.class) 89 | public ResponseEntity handleKeyNotAccessibleByUserException(KeyNotAccessibleByUserException exception) { 90 | return createErrorResponse(HttpStatus.FORBIDDEN, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/exception/UserControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.exception; 19 | 20 | import de.communicode.communikey.controller.UserController; 21 | import org.springframework.http.HttpStatus; 22 | import org.springframework.http.ResponseEntity; 23 | import org.springframework.web.bind.annotation.ControllerAdvice; 24 | import org.springframework.web.bind.annotation.ExceptionHandler; 25 | 26 | import java.sql.Timestamp; 27 | import java.util.Calendar; 28 | 29 | /** 30 | * The exception handler for the {@link UserController} that returns a error as response entity. 31 | * 32 | * @author sgreb@communicode.de 33 | * @since 0.2.0 34 | */ 35 | 36 | @ControllerAdvice 37 | public class UserControllerExceptionHandler extends GlobalControllerExceptionHandler { 38 | 39 | /** 40 | * Handles all exceptions of type {@link ResetTokenNotFoundException}. 41 | * 42 | * @param exception the exception to handle 43 | * @return the error as response entity 44 | */ 45 | @ExceptionHandler(ResetTokenNotFoundException.class) 46 | public ResponseEntity handleResetTokenNotFoundException(final ResetTokenNotFoundException exception) { 47 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 48 | } 49 | 50 | /** 51 | * Handles all exceptions of type {@link ActivationTokenNotFoundException}. 52 | * 53 | * @param exception the exception to handle 54 | * @return the error as response entity 55 | */ 56 | @ExceptionHandler(ActivationTokenNotFoundException.class) 57 | public ResponseEntity handleActivationTokenNotFoundException(final ActivationTokenNotFoundException exception) { 58 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 59 | } 60 | 61 | /** 62 | * Handles all exceptions of type {@link UserNotActivatedException}. 63 | * 64 | * @param exception the exception to handle 65 | * @return the error as response entity 66 | */ 67 | @ExceptionHandler(UserNotActivatedException.class) 68 | public ResponseEntity handleUserNotActivatedException(final UserNotActivatedException exception) { 69 | return createErrorResponse(HttpStatus.UNAUTHORIZED, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 70 | } 71 | 72 | /** 73 | * Handles all exceptions of type {@link UserNotFoundException}. 74 | * 75 | * @param exception the exception to handle 76 | * @return the error as response entity 77 | */ 78 | @ExceptionHandler(UserNotFoundException.class) 79 | public ResponseEntity handleUserNotFoundException(final UserNotFoundException exception) { 80 | return createErrorResponse(HttpStatus.NOT_FOUND, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 81 | } 82 | 83 | /** 84 | * Handles all exceptions of type {@link UserConflictException}. 85 | * 86 | * @param exception the exception to handle 87 | * @return the error as response entity 88 | */ 89 | @ExceptionHandler(UserConflictException.class) 90 | public ResponseEntity handleUserConflictException(final UserConflictException exception) { 91 | return createErrorResponse(HttpStatus.CONFLICT, new Timestamp(Calendar.getInstance().getTimeInMillis()), exception.getMessage()); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bugs.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report a bug that is caused by the code in this repository 4 | 5 | --- 6 | 7 | 8 | 9 | > **Please read the [contribution guidelines](https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md) before filling out this issue template**. 10 | 11 | ## Prerequisites 12 | 13 | This section and the instructions in the sections below are only part of this issue template. Please ensure to **delete this whole section, all pre-filled instructions of the sections below and sections you have not filled out before submitting** to ensure a clear structure and overview. 14 | 15 | Please do your best to provide as much information as possible and use a clear and descriptive title for your bug report to help maintainers and the community understand and reproduce the behavior, find related reports and to resolve the ticket faster. 16 | 17 | * **Ensure the issue has not already been reported by using the [GitHub Issues search](https://github.com/communicode/communikey-backend/issues)** — if it has **and the issue is still open**, add a comment to the existing issue instead of opening this new one. If you find a closed issue that seems to be similar to this one, include a link to the original issue(s) in the [metadata head](#metadata-head) section of this issue. 18 | * **Ensure the contribution belongs to the correct [communikey repository](https://github.com/communicode?q=communikey).** 19 | * **Ensure the issue is reproducible** — try to use the [latest version](https://github.com/communicode/communikey-backend/releases/latest) and [`develop`](https://github.com/communicode/communikey-backend/tree/develop) branch. 20 | 21 | ## Metadata Head 22 | 23 | The metadata head can be added to the top of the issue as [Markdown text quote](https://help.github.com/articles/basic-writing-and-formatting-syntax) containing the the ID of other related issues. 24 | 25 | > Related issues: 26 | 27 | ## Description 28 | 29 | Describe the bug as in many relevant details as possible with a clear and concise description. Ensure to fill in the [steps to reproduce](#steps-to-reproduce) it. 30 | 31 | ### Steps to Reproduce 32 | 33 | 1. Step One 34 | 2. Step Two 35 | 3. ... 36 | 37 | ### Expected Behavior 38 | 39 | What you expect to happen? 40 | 41 | ### Actual Behavior 42 | 43 | What actually happens? 44 | 45 | ## Example 46 | 47 | Provide a [MCVE - The Minimal, Complete, and Verifiable Example](https://github.com/communicode/communikey-backend/blob/develop/CONTRIBUTING.md#mcve) 48 | 49 | **This is a optional section, but it can drastically increase the speed at which this issue can be processed since it takes away the time-consuming reconstruction to reproduce the bug.** 50 | 51 | The recommended way is to upload it as [Gist](https://gist.github.com) or new repository to GitHub, but of course you can [attach it to this issue](https://help.github.com/articles/file-attachments-on-issues-and-pull-requests), use any free file hosting service or paste the code in [Markdown code blocks](https://help.github.com/articles/basic-writing-and-formatting-syntax) into this issue. 52 | 53 | ## Environment and Versions 54 | 55 | * What is the version of communikey you are running? 56 | * What is the name and the version of your OS? 57 | * Have you tried to reproduce it on different OS environments and if yes is the behavior the same for all? 58 | * If the problem is related to [Java](https://www.java.com) please provide the Java version you're running. 59 | * Are you using any additional CLI arguments for Java or Gradle? 60 | * What is the version of [Gradle](https://gradle.org) you are running? 61 | 62 | ## Stack Trace and Error Messages 63 | 64 | ``` 65 | Paste the full stack trace, error messages or the logfile here ... 66 | ``` 67 | 68 | ... or [attach them as files](https://help.github.com/articles/file-attachments-on-issues-and-pull-requests) to this issue. 69 | 70 | ## Additional Context 71 | 72 | Add any other context, screenshots or screencasts which are relevant for this issue. 73 | 74 | ## References 75 | 76 | Add any other references and links which are relevant for this issue. 77 | 78 | ## Potential Solution 79 | 80 | Maybe include the lines of code that you have identified as causing the bug or references to other projects where this bug has already been reported. 81 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.config; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.context.annotation.Bean; 24 | import org.springframework.context.annotation.Configuration; 25 | import org.springframework.security.authentication.AuthenticationManager; 26 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 27 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 28 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 29 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 30 | import org.springframework.security.config.http.SessionCreationPolicy; 31 | import org.springframework.security.core.userdetails.UserDetailsService; 32 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 33 | import org.springframework.security.crypto.password.PasswordEncoder; 34 | 35 | import javax.annotation.PostConstruct; 36 | 37 | /** 38 | * Configures the security for user authentications and requests to the REST API. 39 | * 40 | *

Provides the {@link #passwordEncoder()} bean. 41 | * 42 | * @author sgreb@communicode.de 43 | * @since 0.2.0 44 | */ 45 | @Configuration 46 | @EnableWebSecurity 47 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 48 | 49 | private final AuthenticationManagerBuilder authenticationManagerBuilder; 50 | private final UserDetailsService userDetailsService; 51 | 52 | public static final String APP_ID = "communikey"; 53 | public static final String EMAIL_REGEX = "^([^-_.@\\s0-9]){1,}([a-z._-]{1,})@communicode\\.de$"; 54 | 55 | @Autowired 56 | public SecurityConfig(AuthenticationManagerBuilder authenticationManagerBuilder, UserDetailsService userDetailsService) { 57 | this.authenticationManagerBuilder = requireNonNull(authenticationManagerBuilder, "authenticationManagerBuilder must not be null!"); 58 | this.userDetailsService = requireNonNull(userDetailsService, "userDetailsService must not be null!"); 59 | } 60 | 61 | @PostConstruct 62 | public void init() throws Exception { 63 | authenticationManagerBuilder 64 | .userDetailsService(userDetailsService) 65 | .passwordEncoder(passwordEncoder()); 66 | } 67 | 68 | @Override 69 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 70 | auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); 71 | } 72 | 73 | @Override 74 | public void configure(HttpSecurity http) throws Exception { 75 | http 76 | .httpBasic().realmName(APP_ID) 77 | .and() 78 | .sessionManagement() 79 | .sessionCreationPolicy(SessionCreationPolicy.STATELESS) 80 | .and() 81 | .requestMatchers().antMatchers("/oauth/authorize") 82 | .and() 83 | .authorizeRequests() 84 | .antMatchers("/oauth/authorize").denyAll() 85 | .and() 86 | .csrf().disable(); 87 | } 88 | 89 | @Override 90 | @Bean 91 | public AuthenticationManager authenticationManagerBean() throws Exception { 92 | return super.authenticationManagerBean(); 93 | } 94 | 95 | /** 96 | * The password encoder bean for password encryption. 97 | * 98 | * @return the {@link BCryptPasswordEncoder} bean 99 | */ 100 | @Bean 101 | public PasswordEncoder passwordEncoder() { 102 | return new BCryptPasswordEncoder(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.repository; 19 | 20 | import de.communicode.communikey.domain.Authority; 21 | import de.communicode.communikey.domain.UserGroup; 22 | import org.springframework.data.jpa.repository.EntityGraph; 23 | import de.communicode.communikey.domain.User; 24 | import org.springframework.data.repository.CrudRepository; 25 | import org.springframework.stereotype.Repository; 26 | 27 | import java.util.Set; 28 | 29 | /** 30 | * A repository for {@link User} entities. 31 | * 32 | * @author sgreb@communicode.de 33 | * @since 0.2.0 34 | */ 35 | @Repository 36 | public interface UserRepository extends CrudRepository { 37 | /** 38 | * Finds all user entities of the repository. 39 | * 40 | * @return a collection of found user entities 41 | * @since 0.9.0 42 | */ 43 | @Override 44 | Set findAll(); 45 | 46 | /** 47 | * Finds all user entities with a specific authority of the repository. 48 | * 49 | * @param authority the authority the users should be in 50 | * @return a collection of found user entities 51 | * @since 0.15.0 52 | */ 53 | Set findAllByAuthorities(Authority authority); 54 | 55 | /** 56 | * Finds all user entities with a specific usergroup. 57 | * 58 | * @param userGroup the userGroup the users should be in 59 | * @return a collection of found user entities 60 | * @since 0.15.0 61 | */ 62 | Set findAllByGroupsContains(UserGroup userGroup); 63 | 64 | /** 65 | * Finds the user entity with the specified activation token. 66 | * 67 | * @param activationToken the activation token of the user to find 68 | * @return the user entity if found, {@code null} otherwise 69 | */ 70 | User findOneByActivationToken(String activationToken); 71 | 72 | /** 73 | * Finds the user entity with the specified reset token. 74 | * 75 | * @param resetToken the reset token of the user to find 76 | * @return the user entity if found, {@code null} otherwise 77 | */ 78 | User findOneByResetToken(String resetToken); 79 | 80 | /** 81 | * Finds the user entity with the specified publicKeyResetToken. 82 | * 83 | * @param publicKeyResetToken the publicKeyResetToken of the user to find 84 | * @return the user entity if found, {@code null} otherwise 85 | */ 86 | User findOneByPublicKeyResetToken(String publicKeyResetToken); 87 | 88 | /** 89 | * Finds the user entity with the specified email. 90 | * 91 | * @param email the email of the user to find 92 | * @return the found user entity, {@code null} otherwise 93 | */ 94 | User findOneByEmail(String email); 95 | 96 | /** 97 | * Finds the user entity with the specified login. 98 | * 99 | * @param login the login of the user to find 100 | * @return the found user entity, {@code null} otherwise 101 | */ 102 | User findOneByLogin(String login); 103 | 104 | /** 105 | * Finds the user entity with the specified ID including its granted authorities. 106 | * 107 | * @param id the ID of the user to find 108 | * @return the found user entity 109 | */ 110 | @EntityGraph(attributePaths = "authorities") 111 | User findOneWithAuthoritiesById(Long id); 112 | 113 | /** 114 | * Finds the user entity with the specified email including its granted authorities. 115 | * 116 | * @param email the email of the user to find 117 | * @return the user entity if found, {@code null} otherwise 118 | */ 119 | @EntityGraph(attributePaths = "authorities") 120 | User findOneWithAuthoritiesByEmail(String email); 121 | 122 | /** 123 | * Finds the user entity with the specified login including its granted authorities. 124 | * 125 | * @param login the login of the user to find 126 | * @return the user entity if found, {@code null} otherwise 127 | */ 128 | @EntityGraph(attributePaths = "authorities") 129 | User findOneWithAuthoritiesByLogin(String login); 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/domain/UserGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey.domain; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIdentityInfo; 21 | import com.fasterxml.jackson.annotation.JsonIdentityReference; 22 | import com.fasterxml.jackson.annotation.JsonView; 23 | import com.fasterxml.jackson.annotation.ObjectIdGenerators; 24 | import com.google.common.collect.Sets; 25 | import de.communicode.communikey.service.view.AuthoritiesRestView; 26 | 27 | import javax.validation.constraints.NotBlank; 28 | import javax.persistence.Column; 29 | import javax.persistence.Entity; 30 | import javax.persistence.FetchType; 31 | import javax.persistence.GeneratedValue; 32 | import javax.persistence.GenerationType; 33 | import javax.persistence.Id; 34 | import javax.persistence.JoinColumn; 35 | import javax.persistence.JoinTable; 36 | import javax.persistence.ManyToMany; 37 | import javax.persistence.Table; 38 | 39 | import java.io.Serializable; 40 | import java.util.Set; 41 | 42 | /** 43 | * Represents a user group. 44 | * 45 | * @author sgreb@communicode.de 46 | * @since 0.2.0 47 | */ 48 | @Entity 49 | @Table(name = "user_groups") 50 | public class UserGroup extends AbstractEntity implements Serializable { 51 | 52 | private static final long serialVersionUID = 1; 53 | 54 | @Id 55 | @GeneratedValue(strategy = GenerationType.IDENTITY) 56 | @JsonView(AuthoritiesRestView.Admin.class) 57 | private Long id; 58 | 59 | @NotBlank 60 | @Column(unique = true, nullable = false) 61 | private String name; 62 | 63 | @ManyToMany(fetch = FetchType.LAZY) 64 | @JoinTable( 65 | name = "user_groups_users", 66 | joinColumns = @JoinColumn(name = "user_group_id", referencedColumnName = "id"), 67 | inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")}) 68 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") 69 | @JsonIdentityReference(alwaysAsId = true) 70 | @JsonView(AuthoritiesRestView.Admin.class) 71 | private final Set users = Sets.newConcurrentHashSet(); 72 | 73 | @ManyToMany(fetch = FetchType.LAZY, mappedBy = "groups") 74 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") 75 | @JsonIdentityReference(alwaysAsId = true) 76 | @JsonView(AuthoritiesRestView.Admin.class) 77 | private final Set categories = Sets.newConcurrentHashSet(); 78 | 79 | public Long getId() { 80 | return id; 81 | } 82 | 83 | public void setId(Long id) { 84 | this.id = id; 85 | } 86 | 87 | public String getName() { 88 | return name; 89 | } 90 | 91 | public void setName(String name) { 92 | this.name = name; 93 | } 94 | 95 | public boolean addUser(User user) { 96 | return users.add(user); 97 | } 98 | 99 | public boolean addUsers(Set user) { 100 | return users.addAll(user); 101 | } 102 | 103 | public boolean removeUser(User user) { 104 | return users.remove(user); 105 | } 106 | 107 | public boolean removeUsers(Set users) { 108 | return this.users.removeAll(users); 109 | } 110 | 111 | public void removeAllUser() { 112 | users.clear(); 113 | } 114 | 115 | public Set getUsers() { 116 | return Sets.newConcurrentHashSet(users); 117 | } 118 | 119 | public boolean addCategory(KeyCategory keyCategory) { 120 | return categories.add(keyCategory); 121 | } 122 | 123 | public boolean addCategories(Set keyCategories) { 124 | return categories.addAll(keyCategories); 125 | } 126 | 127 | public boolean removeCategory(KeyCategory keyCategory) { 128 | return categories.remove(keyCategory); 129 | } 130 | 131 | public boolean removeCategories(Set keyCategories) { 132 | return categories.removeAll(keyCategories); 133 | } 134 | 135 | public void removeAllCategories() { 136 | categories.clear(); 137 | } 138 | 139 | public Set getCategories() { 140 | return Sets.newConcurrentHashSet(categories); 141 | } 142 | 143 | @Override 144 | public String toString() { 145 | return "UserGroup{" +"id=" + id + 146 | ", name='" + name + '\'' + 147 | ", users=" + users + 148 | ", categories=" + categories + 149 | '}'; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/de/communicode/communikey/ApplicationDataBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of communikey. 3 | * Copyright (C) 2016-2018 communicode AG 4 | * 5 | * communikey is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package de.communicode.communikey; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | import static java.util.stream.Collectors.toSet; 22 | 23 | import de.communicode.communikey.config.CommunikeyProperties; 24 | import de.communicode.communikey.domain.Authority; 25 | import de.communicode.communikey.repository.AuthorityRepository; 26 | import de.communicode.communikey.repository.KeyCategoryRepository; 27 | import de.communicode.communikey.repository.UserRepository; 28 | import de.communicode.communikey.security.AuthoritiesConstants; 29 | import de.communicode.communikey.security.SecurityUtils; 30 | import org.springframework.beans.factory.annotation.Autowired; 31 | import org.springframework.context.event.ContextRefreshedEvent; 32 | import de.communicode.communikey.domain.User; 33 | import org.springframework.context.event.EventListener; 34 | import org.springframework.security.crypto.password.PasswordEncoder; 35 | import org.springframework.stereotype.Component; 36 | 37 | import java.util.Objects; 38 | import java.util.Set; 39 | import java.util.stream.Stream; 40 | 41 | @Component 42 | public class ApplicationDataBootstrap { 43 | 44 | private final UserRepository userRepository; 45 | private final KeyCategoryRepository keyCategoryRepository; 46 | private final PasswordEncoder passwordEncoder; 47 | private final AuthorityRepository authorityRepository; 48 | private final CommunikeyProperties communikeyProperties; 49 | 50 | private final Authority roleUser = new Authority(); 51 | private final Authority roleAdmin = new Authority(); 52 | private final User rootUser = new User(); 53 | 54 | @Autowired 55 | public ApplicationDataBootstrap(final UserRepository userRepository, final PasswordEncoder passwordEncoder, final AuthorityRepository authorityRepository, 56 | final CommunikeyProperties communikeyProperties, final KeyCategoryRepository keyCategoryRepository) { 57 | this.userRepository = requireNonNull(userRepository, "userRepository must not be null!"); 58 | this.passwordEncoder = requireNonNull(passwordEncoder, "passwordEncoder must not be null!"); 59 | this.authorityRepository = requireNonNull(authorityRepository, "authorityRepository must not be null!"); 60 | this.communikeyProperties = requireNonNull(communikeyProperties, "communikeyProperties must not be null!"); 61 | this.keyCategoryRepository = requireNonNull(keyCategoryRepository, "keyCategoryRepository must not be null!"); 62 | } 63 | 64 | @EventListener(ContextRefreshedEvent.class) 65 | public final void initialize() { 66 | this.initializeAuthorities(); 67 | this.initializeUser(); 68 | } 69 | 70 | private void initializeAuthorities() { 71 | if (!this.authorityRepository.existsById(AuthoritiesConstants.USER)) { 72 | this.roleUser.setName(AuthoritiesConstants.USER); 73 | this.authorityRepository.save(roleUser); 74 | } 75 | if (!this.authorityRepository.existsById(AuthoritiesConstants.ADMIN)) { 76 | this.roleAdmin.setName(AuthoritiesConstants.ADMIN); 77 | this.authorityRepository.save(roleAdmin); 78 | } 79 | } 80 | 81 | private void initializeUser() { 82 | if (Objects.isNull(this.userRepository.findOneByLogin(this.communikeyProperties.getSecurity().getRoot().getLogin()))) { 83 | this.rootUser.setEmail(communikeyProperties.getSecurity().getRoot().getEmail()); 84 | this.rootUser.setLogin(communikeyProperties.getSecurity().getRoot().getLogin()); 85 | this.rootUser.setFirstName(communikeyProperties.getSecurity().getRoot().getFirstName()); 86 | this.rootUser.setLastName(communikeyProperties.getSecurity().getRoot().getLastName()); 87 | this.rootUser.setPassword(passwordEncoder.encode(communikeyProperties.getSecurity().getRoot().getPassword())); 88 | this.rootUser.setActivationToken(SecurityUtils.generateRandomActivationToken()); 89 | this.rootUser.setPublicKey(communikeyProperties.getSecurity().getRoot().getPublicKey()); 90 | this.rootUser.setActivated(true); 91 | final Set authorities = Stream.of(AuthoritiesConstants.ADMIN, AuthoritiesConstants.USER) 92 | .map(authorityRepository::findOneByName) 93 | .collect(toSet()); 94 | this.rootUser.addAuthorities(authorities); 95 | 96 | this.userRepository.save(rootUser); 97 | } 98 | } 99 | } 100 | --------------------------------------------------------------------------------