diff --git a/config/database/hsql/apopulate-schemas.sql b/config/database/hsql/apopulate-schemas.sql deleted file mode 100644 index 9521e30b..00000000 --- a/config/database/hsql/apopulate-schemas.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO COLLABORATOR (id, email, creation_date) VALUES (1, 'test@wisemapping.org', CURDATE()); INSERT INTO USER (colaborator_id, firstname, lastname, password, activation_code, activation_date, allow_send_email,authentication_type) VALUES (1, 'Test', 'User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', 1237, CURDATE(), 1,'D'); INSERT INTO COLLABORATOR (id, email, creation_date) VALUES (2, 'admin@wisemapping.org', CURDATE()); INSERT INTO USER (colaborator_id, firstname, lastname, password, activation_code, activation_date, allow_send_email,authentication_type) VALUES (2, 'Admin', 'User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', 1237, CURDATE(), 1,'D'); COMMIT; SHUTDOWN; \ No newline at end of file diff --git a/config/database/hsql/create-schemas.sql b/config/database/hsql/create-schemas.sql deleted file mode 100644 index 3dfd10a3..00000000 --- a/config/database/hsql/create-schemas.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE TABLE COLLABORATOR ( id INTEGER NOT NULL IDENTITY, email VARCHAR(255) NOT NULL UNIQUE, creation_date DATE ); CREATE TABLE USER ( colaborator_id INTEGER NOT NULL IDENTITY, authentication_type CHAR(1) NOT NULL, authenticator_uri VARCHAR(255) NULL, firstname VARCHAR(255) NOT NULL, lastname VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, activation_code BIGINT NOT NULL, activation_date DATE, allow_send_email CHAR(1) NOT NULL, locale VARCHAR(5), google_sync BOOLEAN, sync_code VARCHAR(255), google_token VARCHAR(255), FOREIGN KEY (colaborator_id) REFERENCES COLLABORATOR (id) ); CREATE TABLE MINDMAP ( id INTEGER NOT NULL IDENTITY, title VARCHAR(255) NOT NULL, description VARCHAR(255), xml LONGVARBINARY NOT NULL, public BOOLEAN NOT NULL, creation_date DATETIME, edition_date DATETIME, creator_id INTEGER NOT NULL, last_editor_id INTEGER NOT NULL --FOREIGN KEY(creator_id) REFERENCES USER(colaborator_id) ); CREATE TABLE LABEL ( id INTEGER NOT NULL PRIMARY KEY IDENTITY, title VARCHAR(30), creator_id INTEGER NOT NULL, parent_label_id INTEGER, color VARCHAR(7) NOT NULL, iconName VARCHAR(50) NOT NULL --FOREIGN KEY (creator_id) REFERENCES USER (colaborator_id) ); CREATE TABLE R_LABEL_MINDMAP ( mindmap_id INTEGER NOT NULL, label_id INTEGER NOT NULL, PRIMARY KEY (mindmap_id, label_id), FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id), FOREIGN KEY (label_id) REFERENCES LABEL (id) ON DELETE CASCADE ON UPDATE NO ACTION ); CREATE TABLE MINDMAP_HISTORY ( id INTEGER NOT NULL IDENTITY, xml LONGVARBINARY NOT NULL, mindmap_id INTEGER NOT NULL, creation_date DATETIME, editor_id INTEGER NOT NULL, FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id) ); CREATE TABLE COLLABORATION_PROPERTIES ( id INTEGER NOT NULL IDENTITY, starred BOOLEAN NOT NULL, mindmap_properties VARCHAR(512) ); CREATE TABLE COLLABORATION ( id INTEGER NOT NULL IDENTITY, colaborator_id INTEGER NOT NULL, properties_id INTEGER NOT NULL, mindmap_id INTEGER NOT NULL, role_id INTEGER NOT NULL, FOREIGN KEY (colaborator_id) REFERENCES COLLABORATOR (id), FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id), FOREIGN KEY (properties_id) REFERENCES COLLABORATION_PROPERTIES (id) ); CREATE TABLE ACCESS_AUDITORY ( id INTEGER NOT NULL IDENTITY, user_id INTEGER NOT NULL, login_date DATE, FOREIGN KEY (user_id) REFERENCES USER (colaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION ); COMMIT; \ No newline at end of file diff --git a/config/database/hsql/drop-schemas.sql b/config/database/hsql/drop-schemas.sql deleted file mode 100644 index 77bf9e7b..00000000 --- a/config/database/hsql/drop-schemas.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS ACCESS_AUDITORY; DROP TABLE IF EXISTS COLLABORATION; DROP TABLE IF EXISTS COLLABORATION_PROPERTIES; DROP TABLE IF EXISTS MINDMAP_HISTORY; DROP TABLE IF EXISTS R_LABEL_MINDMAP; DROP TABLE IF EXISTS LABEL; DROP TABLE IF EXISTS MINDMAP; DROP TABLE IF EXISTS USER; DROP TABLE IF EXISTS COLLABORATOR; COMMIT; \ No newline at end of file diff --git a/config/database/migration/5.0->6.0.sql b/config/database/migration/5.0->6.0.sql new file mode 100644 index 00000000..585ec37d --- /dev/null +++ b/config/database/migration/5.0->6.0.sql @@ -0,0 +1,5 @@ +RENAME TABLE USER TO ACCOUNT; +RENAME TABLE LABEL TO MINDMAP_LABEL; + +ALTER TABLE COLLABORATION +RENAME COLUMN colaboration_id to collaboration_id diff --git a/config/database/mysql/apopulate-schemas.sql b/config/database/mysql/apopulate-schemas.sql deleted file mode 100644 index f5e38020..00000000 --- a/config/database/mysql/apopulate-schemas.sql +++ /dev/null @@ -1 +0,0 @@ -# # Command: mysql -u root -p < apopulate_schemas.sql # INSERT INTO COLLABORATOR (id, email, creation_date) VALUES (1, 'test@wisemapping.org', CURRENT_DATE()); INSERT INTO USER (colaborator_id, firstname, lastname, password, activation_code, activation_date, allow_send_email,authentication_type) VALUES (1, 'Test', 'User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', 1237, CURRENT_DATE(), 1,'D'); INSERT INTO COLLABORATOR (id, email, creation_date) VALUES (2, 'admin@wisemapping.org', CURRENT_DATE()); INSERT INTO USER (colaborator_id, firstname, lastname, password, activation_code, activation_date, allow_send_email,authentication_type) VALUES (2, 'Admin', 'User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', 1237, CURRENT_DATE(), 1,'D'); COMMIT; \ No newline at end of file diff --git a/config/database/mysql/app-mysql.yaml b/config/database/mysql/app-mysql.yaml new file mode 100644 index 00000000..be89a7db --- /dev/null +++ b/config/database/mysql/app-mysql.yaml @@ -0,0 +1,14 @@ + +spring: + datasource: + url: jdbc:mysql://localhost:3306/wisemapping?useUnicode=yes&characterEncoding=UTF-8 + driver-class-name: com.mysql.cj.jdbc.Driver + password: password + username: wisemapping + jpa: + properties: + hibernate: + dialect: org.hibernate.dialect.MySQLDialect + sql: + init: + platform: mysql \ No newline at end of file diff --git a/config/database/mysql/create-database.sql b/config/database/mysql/create-database.sql index edadeef9..940c5af7 100644 --- a/config/database/mysql/create-database.sql +++ b/config/database/mysql/create-database.sql @@ -1 +1,12 @@ -# # Command: mysql -u root -p < create_database.sql # DROP DATABASE IF EXISTS wisemapping; CREATE DATABASE IF NOT EXISTS wisemapping CHARACTER SET = 'utf8' COLLATE = 'utf8_unicode_ci'; GRANT ALL ON wisemapping.* TO 'wisemapping'@'localhost'; SET PASSWORD FOR 'wisemapping'@'localhost' = PASSWORD('password'); \ No newline at end of file +# +# Command: mysql -u root -p < create-database.sql +# +DROP DATABASE IF EXISTS wisemapping; + +CREATE DATABASE IF NOT EXISTS wisemapping + CHARACTER SET = 'utf8' + COLLATE = 'utf8_unicode_ci'; + +CREATE USER 'wisemapping'@'%' IDENTIFIED BY 'password'; +GRANT ALL PRIVILEGES ON wisemapping.* TO 'wisemapping'@'%' WITH GRANT OPTION; +FLUSH PRIVILEGES; \ No newline at end of file diff --git a/config/database/mysql/create-schemas.sql b/config/database/mysql/create-schemas.sql deleted file mode 100644 index f9e609bf..00000000 --- a/config/database/mysql/create-schemas.sql +++ /dev/null @@ -1 +0,0 @@ -# # Command: mysql -u root -p < create_schemas.sql # USE wisemapping; CREATE TABLE COLLABORATOR ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, email VARCHAR(255) CHARACTER SET utf8 NOT NULL UNIQUE, creation_date DATE ) CHARACTER SET utf8; CREATE TABLE USER ( colaborator_id INTEGER NOT NULL PRIMARY KEY, authentication_type CHAR(1) CHARACTER SET utf8 NOT NULL, authenticator_uri VARCHAR(255) CHARACTER SET utf8, firstname VARCHAR(255) CHARACTER SET utf8 NOT NULL, lastname VARCHAR(255) CHARACTER SET utf8 NOT NULL, password VARCHAR(255) CHARACTER SET utf8 NOT NULL, activation_code BIGINT(20) NOT NULL, activation_date DATE, allow_send_email CHAR(1) CHARACTER SET utf8 NOT NULL DEFAULT 0, locale VARCHAR(5), google_sync BOOL, sync_code VARCHAR(255), google_token VARCHAR(255), FOREIGN KEY (colaborator_id) REFERENCES COLLABORATOR (id) ON DELETE CASCADE ON UPDATE NO ACTION ) CHARACTER SET utf8; CREATE TABLE MINDMAP ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, title VARCHAR(255) CHARACTER SET utf8 NOT NULL, description VARCHAR(255) CHARACTER SET utf8 NOT NULL, xml MEDIUMBLOB NOT NULL, public BOOL NOT NULL DEFAULT 0, creation_date DATETIME, edition_date DATETIME, creator_id INTEGER NOT NULL, last_editor_id INTEGER NOT NULL, FOREIGN KEY (creator_id) REFERENCES USER (colaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION ) CHARACTER SET utf8; CREATE TABLE LABEL ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, title VARCHAR(30) CHARACTER SET utf8 NOT NULL, creator_id INTEGER NOT NULL, parent_label_id INTEGER, color VARCHAR(7) NOT NULL, iconName VARCHAR(50) NOT NULL, FOREIGN KEY (creator_id) REFERENCES USER (colaborator_id), FOREIGN KEY (parent_label_id) REFERENCES LABEL (id) ON DELETE CASCADE ON UPDATE NO ACTION ) CHARACTER SET utf8; CREATE TABLE R_LABEL_MINDMAP ( mindmap_id INTEGER NOT NULL, label_id INTEGER NOT NULL, PRIMARY KEY (mindmap_id, label_id), FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id), FOREIGN KEY (label_id) REFERENCES LABEL (id) ON DELETE CASCADE ON UPDATE NO ACTION ) CHARACTER SET utf8; CREATE TABLE MINDMAP_HISTORY (id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, xml MEDIUMBLOB NOT NULL, mindmap_id INTEGER NOT NULL, creation_date DATETIME, editor_id INTEGER NOT NULL, FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id) ON DELETE CASCADE ON UPDATE NO ACTION ) CHARACTER SET utf8; CREATE TABLE COLLABORATION_PROPERTIES ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, starred BOOL NOT NULL DEFAULT 0, mindmap_properties VARCHAR(512) CHARACTER SET utf8 ) CHARACTER SET utf8; CREATE TABLE COLLABORATION ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, colaborator_id INTEGER NOT NULL, properties_id INTEGER NOT NULL, mindmap_id INTEGER NOT NULL, role_id INTEGER NOT NULL, UNIQUE KEY UC_ROLE (mindmap_id,colaborator_id), FOREIGN KEY (colaborator_id) REFERENCES COLLABORATOR (id), FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id) ON DELETE CASCADE ON UPDATE NO ACTION, FOREIGN KEY (properties_id) REFERENCES COLLABORATION_PROPERTIES (id) ON DELETE CASCADE ON UPDATE NO ACTION ) CHARACTER SET utf8; CREATE TABLE ACCESS_AUDITORY ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, login_date DATE, user_id INTEGER NOT NULL, FOREIGN KEY (user_id) REFERENCES USER (colaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION ) CHARACTER SET utf8; COMMIT; \ No newline at end of file diff --git a/config/database/mysql/drop-schemas.sql b/config/database/mysql/drop-schemas.sql deleted file mode 100644 index 6be70e14..00000000 --- a/config/database/mysql/drop-schemas.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS ACCESS_AUDITORY; DROP TABLE IF EXISTS COLLABORATION; DROP TABLE IF EXISTS COLLABORATION_PROPERTIES; DROP TABLE IF EXISTS MINDMAP_HISTORY; DROP TABLE IF EXISTS LABEL; DROP TABLE IF EXISTS MINDMAP; DROP TABLE IF EXISTS R_LABEL_MINDMAP DROP TABLE IF EXISTS USER; DROP TABLE IF EXISTS COLLABORATOR; COMMIT; \ No newline at end of file diff --git a/config/database/postgres/create-database.sql b/config/database/postgres/create-database.sql deleted file mode 100644 index 3a1305f2..00000000 --- a/config/database/postgres/create-database.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE DATABASE wisemapping; -CREATE USER wisemapping WITH PASSWORD 'password'; - -GRANT ALL PRIVILEGES ON DATABASE wisemapping TO wisemapping; \ No newline at end of file diff --git a/config/database/postgres/drop-schemas.sql b/config/database/postgres/drop-schemas.sql deleted file mode 100644 index 6b49abbe..00000000 --- a/config/database/postgres/drop-schemas.sql +++ /dev/null @@ -1,10 +0,0 @@ -DROP TABLE IF EXISTS ACCESS_AUDITORY; -DROP TABLE IF EXISTS COLLABORATION; -DROP TABLE IF EXISTS COLLABORATION_PROPERTIES; -DROP TABLE IF EXISTS MINDMAP_HISTORY; -DROP TABLE IF EXISTS R_LABEL_MINDMAP; -DROP TABLE IF EXISTS "LABEL"; -DROP TABLE IF EXISTS MINDMAP; -DROP TABLE IF EXISTS "USER"; -DROP TABLE IF EXISTS COLLABORATOR; -COMMIT; \ No newline at end of file diff --git a/config/database/postgresql/app-postgresql.yaml b/config/database/postgresql/app-postgresql.yaml new file mode 100644 index 00000000..5f69c5cd --- /dev/null +++ b/config/database/postgresql/app-postgresql.yaml @@ -0,0 +1,14 @@ + +spring: + datasource: + url: jdbc:postgresql://localhost/wisemapping + driver-class-name: org.postgresql.Driver + password: password + username: wisemapping + jpa: + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQLDialect + sql: + init: + platform: postgresql \ No newline at end of file diff --git a/config/database/postgresql/create-database.sql b/config/database/postgresql/create-database.sql new file mode 100644 index 00000000..8d231264 --- /dev/null +++ b/config/database/postgresql/create-database.sql @@ -0,0 +1,7 @@ + +CREATE DATABASE wisemapping; +CREATE USER wisemapping WITH PASSWORD 'password'; +GRANT ALL PRIVILEGES ON DATABASE wisemapping TO wisemapping; + +GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO wisemapping; +GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO wisemapping; diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..d824f268 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +version: '3' + +services: + wise-api: + container_name: wise-api + image: wise-api:latest + build: + context: ./wise-api + dockerfile: Dockerfile + ports: + - "8080:8080" + wise-ui: + container_name: wise-ui + image: wise-ui:latest + build: + context: ./wise-ui + dockerfile: Dockerfile + depends_on: + - wise-api + ports: + - "80:80" \ No newline at end of file diff --git a/pom.xml b/pom.xml deleted file mode 100644 index f6a2477d..00000000 --- a/pom.xml +++ /dev/null @@ -1,159 +0,0 @@ - - - - 5.1.0-SNAPSHOT - ${project.basedir}/wise-webapps - 17 - 17 - - - - scm:git:git@bitbucket.org:wisemapping/wisemapping-open-source.git - - - 4.0.0 - org.wisemapping - wisemapping - WiseMapping Project - 5.1.0-SNAPSHOT - pom - - - - WiseMapping Public License Version 1.0 - http://www.wisemapping.org/wisemapping-public-license-version-1-0-wpl - A business-friendly OSS license - - - - - - maven2-repository.dev.java.net - Java.net Maven 2 Repository - http://download.java.net/maven/2/ - default - - - - - WiseMapping - http://www.wisemapping.org/ - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.12 - - - exec-maven-plugin - org.codehaus.mojo - 3.0.0 - - - org.apache.maven.plugins - maven-surefire-plugin - 2.16 - - - org.apache.maven.plugins - maven-resources-plugin - 3.3.1 - - - org.apache.maven.plugins - maven-site-plugin - 3.1 - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.4 - - - org.apache.maven.plugins - maven-dependency-plugin - 2.10 - - - net.alchim31.maven - yuicompressor-maven-plugin - 1.1 - - - org.apache.maven.plugins - maven-antrun-plugin - 1.7 - - - org.codehaus.mojo - native2ascii-maven-plugin - 1.0-beta-1 - - - com.github.searls - jasmine-maven-plugin - 1.3.1.5 - - - org.apache.maven.plugins - maven-release-plugin - 2.5 - - - - - - org.apache.maven.plugins - maven-resources-plugin - - UTF-8 - - - - org.apache.maven.plugins - maven-compiler-plugin - - UTF-8 - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.2.2 - - - distribution/assembly/standalone-editor.xml - - - - - - - - - www.wisemapping.org - scp://www.wisemapping.org/docs/project/ - - - - - - wise-ui - wise-webapp - - - - - diff --git a/wise-api/Dockerfile b/wise-api/Dockerfile new file mode 100644 index 00000000..47f86cb7 --- /dev/null +++ b/wise-api/Dockerfile @@ -0,0 +1,7 @@ +FROM amazoncorretto:17.0.10 +LABEL maintainer="Paulo Gustavo Veiga " + +VOLUME /tmp +COPY target/wisemapping-api.jar wisemapping-api.jar + +ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /wisemapping-api.jar ${0} ${@}"] \ No newline at end of file diff --git a/wise-webapp/doc/REST Services.md b/wise-api/doc/REST Services.md similarity index 100% rename from wise-webapp/doc/REST Services.md rename to wise-api/doc/REST Services.md diff --git a/wise-api/pom.xml b/wise-api/pom.xml new file mode 100644 index 00000000..312bf974 --- /dev/null +++ b/wise-api/pom.xml @@ -0,0 +1,232 @@ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.3 + + + org.wisemapping + wise-api + 5.1.0-SNAPSHOT + + WiseMapping API + https://www.wisemapping.org + + + 5.1.0-SNAPSHOT + 21 + 21 + + + + + org.apache.velocity + velocity + 1.7 + compile + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + org.springframework + spring-test + 6.1.3 + test + + + + org.junit.jupiter + junit-jupiter-api + 5.9.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.9.2 + test + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-mail + + + com.intellij + annotations + 12.0 + compile + + + org.postgresql + postgresql + 42.5.4 + + + jakarta.xml.bind + jakarta.xml.bind-api + 4.0.0 + + + + + org.hibernate.validator + hibernate-validator + 8.0.1.Final + + + jakarta.mail + jakarta.mail-api + 2.1.2 + + + com.mysql + mysql-connector-j + 8.1.0 + + + org.eclipse.angus + jakarta.mail + 2.0.2 + + + org.apache.logging.log4j + log4j-core + 2.20.0 + + + + commons-validator + commons-validator + 1.7 + + + + + com.zaxxer + HikariCP + 5.1.0 + + + + + org.hsqldb + hsqldb + 2.7.1 + runtime + + + + com.fasterxml.jackson.core + jackson-databind + 2.15.1 + + + + jakarta.transaction + jakarta.transaction-api + 2.0.1 + + + + commons-io + commons-io + 2.11.0 + + + + org.apache.httpcomponents + fluent-hc + 4.5.14 + + + + org.springframework.security + spring-security-test + 6.2.1 + test + + + + + io.jsonwebtoken + jjwt-api + 0.11.5 + + + io.jsonwebtoken + jjwt-impl + 0.11.5 + + + io.jsonwebtoken + jjwt-jackson + 0.11.5 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + repackage + + repackage + + + wisemapping-api + + + + + + + + + + + + + + spring-snapshots + https://repo.spring.io/snapshot + + + spring-milestones + https://repo.spring.io/milestone + + + \ No newline at end of file diff --git a/wise-api/src/main/java/com/wisemapping/Application.java b/wise-api/src/main/java/com/wisemapping/Application.java new file mode 100644 index 00000000..9909ddda --- /dev/null +++ b/wise-api/src/main/java/com/wisemapping/Application.java @@ -0,0 +1,27 @@ +package com.wisemapping; + +import com.wisemapping.config.common.CommonConfig; +import com.wisemapping.config.rest.RestAppConfig; +import com.wisemapping.config.rest.WebConfig; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.security.web.firewall.StrictHttpFirewall; + +public class Application { + + public static void main(String[] args) { + new SpringApplicationBuilder() + .parent(CommonConfig.class).web(WebApplicationType.NONE) + .child(RestAppConfig.class, WebConfig.class).web(WebApplicationType.SERVLET) +// .sibling(MvcAppConfig.class).web(WebApplicationType.SERVLET) + .run(args); + } + + @Bean + public StrictHttpFirewall httpFirewall() { + StrictHttpFirewall firewall = new StrictHttpFirewall(); + firewall.setAllowSemicolon(true); + return firewall; + } +} diff --git a/wise-api/src/main/java/com/wisemapping/config/common/CommonConfig.java b/wise-api/src/main/java/com/wisemapping/config/common/CommonConfig.java new file mode 100644 index 00000000..d068f10c --- /dev/null +++ b/wise-api/src/main/java/com/wisemapping/config/common/CommonConfig.java @@ -0,0 +1,48 @@ +package com.wisemapping.config.common; + +import com.wisemapping.dao.LabelManagerImpl; +import com.wisemapping.model.Account; +import com.wisemapping.security.AuthenticationProvider; +import com.wisemapping.security.Utils; +import com.wisemapping.service.MindmapServiceImpl; +import com.wisemapping.util.VelocityEngineUtils; +import jakarta.servlet.http.HttpServletRequest; +import org.jetbrains.annotations.NotNull; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Import; +import org.springframework.web.servlet.LocaleResolver; +import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; + +import java.util.Locale; + +@ComponentScan(basePackageClasses = {AuthenticationProvider.class, MindmapServiceImpl.class, LabelManagerImpl.class, VelocityEngineUtils.class}) +@Import({JPAConfig.class, SecurityConfig.class}) +@EnableAutoConfiguration +public class CommonConfig { + @Bean + public LocaleResolver localeResolver() { + return new AcceptHeaderLocaleResolver() { + @Override + public Locale resolveLocale(@NotNull HttpServletRequest request) { + final Account user = Utils.getUser(); + Locale result; + if (user != null && user.getLocale() != null) { + String locale = user.getLocale(); + final String locales[] = locale.split("_"); + + Locale.Builder builder = new Locale.Builder().setLanguage(locales[0]); + if (locales.length > 1) { + builder.setVariant(locales[1]); + } + result = builder.build(); + } else { + result = super.resolveLocale(request); + } + return result; + } + }; + } +} + diff --git a/wise-api/src/main/java/com/wisemapping/config/common/JPAConfig.java b/wise-api/src/main/java/com/wisemapping/config/common/JPAConfig.java new file mode 100644 index 00000000..87796cdf --- /dev/null +++ b/wise-api/src/main/java/com/wisemapping/config/common/JPAConfig.java @@ -0,0 +1,16 @@ +package com.wisemapping.config.common; + +import com.wisemapping.dao.MindmapManagerImpl; +import com.wisemapping.model.Account; +import com.wisemapping.service.MindmapServiceImpl; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + + +@Configuration +@EnableJpaRepositories(basePackageClasses={MindmapServiceImpl.class, MindmapManagerImpl.class}) +@EntityScan(basePackageClasses= Account.class) +public class JPAConfig { + +} diff --git a/wise-api/src/main/java/com/wisemapping/config/common/SecurityConfig.java b/wise-api/src/main/java/com/wisemapping/config/common/SecurityConfig.java new file mode 100644 index 00000000..74a17f01 --- /dev/null +++ b/wise-api/src/main/java/com/wisemapping/config/common/SecurityConfig.java @@ -0,0 +1,76 @@ +package com.wisemapping.config.common; + +import com.wisemapping.security.*; +import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; +import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.crypto.password.PasswordEncoder; + +@Configuration +@EnableWebSecurity +@EnableMethodSecurity( + securedEnabled = true, + jsr250Enabled = true) +public class SecurityConfig { + + @Autowired + private ReadSecurityAdvise readAdvice; + + @Autowired + private UpdateSecurityAdvise updateAdvice; + + @Autowired + private UserDetailsService userDetailsService; + + @Bean + protected MethodSecurityExpressionHandler createExpressionHandler() { + DefaultMethodSecurityExpressionHandler expressionHandler = + new DefaultMethodSecurityExpressionHandler(); + + final MapAccessPermissionEvaluation permissionEvaluator = new MapAccessPermissionEvaluation(readAdvice, updateAdvice); + expressionHandler.setPermissionEvaluator(permissionEvaluator); + return expressionHandler; + } + + @Bean + public PasswordEncoder passwordEncoder() { + return DefaultPasswordEncoderFactories.createDelegatingPasswordEncoder(); + } + + @Bean + public AuthenticationProvider googleAuthenticationProvider() { + return new GoogleAuthenticationProvider(userDetailsService); + + } + + @Bean + public AuthenticationProvider dbAuthenticationProvider() { + final com.wisemapping.security.AuthenticationProvider provider = + new com.wisemapping.security.AuthenticationProvider(); + provider.setEncoder(passwordEncoder()); + provider.setUserDetailsService(userDetailsService); + return provider; + } + + @Bean + public AuthenticationManager authenticationManager(@NotNull HttpSecurity http) + throws Exception { + final AuthenticationManagerBuilder builder = http.getSharedObject(AuthenticationManagerBuilder.class); + builder.userDetailsService(userDetailsService) + .passwordEncoder(passwordEncoder()); + + builder.authenticationProvider(dbAuthenticationProvider()); + builder.authenticationProvider(googleAuthenticationProvider()); + + return builder.build(); + } +} diff --git a/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java b/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java new file mode 100644 index 00000000..15b99e2c --- /dev/null +++ b/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java @@ -0,0 +1,70 @@ +package com.wisemapping.config.rest; + +import com.wisemapping.filter.JwtAuthenticationFilter; +import com.wisemapping.rest.MindmapController; +import jakarta.servlet.http.HttpServletResponse; +import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher; +import org.springframework.web.servlet.handler.HandlerMappingIntrospector; + +import static org.springframework.security.config.Customizer.withDefaults; + + +@SpringBootApplication(scanBasePackageClasses = {MindmapController.class, JwtAuthenticationFilter.class}) +@EnableWebSecurity +public class RestAppConfig { + + @Value("${app.api.http-basic-enabled:false}") + private boolean enableHttpBasic; + + @Autowired + private JwtAuthenticationFilter jwtAuthenticationFilter; + + @Bean + MvcRequestMatcher.Builder mvc(HandlerMappingIntrospector introspector) { + return new MvcRequestMatcher.Builder(introspector); + } + + @Bean + SecurityFilterChain apiSecurityFilterChain(@NotNull final HttpSecurity http, @NotNull final MvcRequestMatcher.Builder mvc) throws Exception { + http + .securityMatcher("/**") + .addFilterAfter(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) + .authorizeHttpRequests(auth -> auth + .requestMatchers(mvc.pattern("/error")).permitAll() + .requestMatchers(mvc.pattern("/api/restful/authenticate")).permitAll() + .requestMatchers(mvc.pattern("/api/restful/users/")).permitAll() + .requestMatchers(mvc.pattern("/api/restful/app/config")).permitAll() + .requestMatchers(mvc.pattern("/api/restful/maps/*/document/xml-pub")).permitAll() + .requestMatchers(mvc.pattern("/api/restful/users/resetPassword")).permitAll() + .requestMatchers(mvc.pattern("/api/restful/oauth2/googlecallback")).permitAll() + .requestMatchers(mvc.pattern("/api/restful/oauth2/confirmaccountsync")).permitAll() + .requestMatchers(mvc.pattern("/api/restful/admin/**")).hasAnyRole("ADMIN") + .requestMatchers(mvc.pattern("/**")).hasAnyRole("USER", "ADMIN") + .anyRequest().authenticated() + ) + .logout(logout -> logout.permitAll() + .logoutSuccessHandler((request, response, authentication) -> { + response.setStatus(HttpServletResponse.SC_OK); + })) + .csrf(AbstractHttpConfigurer::disable) + .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)); + + // Http basic is mainly used by automation tests. + if (enableHttpBasic) { + http.httpBasic(withDefaults()); + } + + return http.build(); + } +} diff --git a/wise-api/src/main/java/com/wisemapping/config/rest/WebConfig.java b/wise-api/src/main/java/com/wisemapping/config/rest/WebConfig.java new file mode 100644 index 00000000..86adf932 --- /dev/null +++ b/wise-api/src/main/java/com/wisemapping/config/rest/WebConfig.java @@ -0,0 +1,27 @@ +package com.wisemapping.config.rest; + +import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +@EnableWebMvc +public class WebConfig implements WebMvcConfigurer { + @Value("${app.security.corsAllowedOrigins:}") + private String corsAllowedOrigins; + + @Override + public void addCorsMappings(@NotNull CorsRegistry registry) { + if (!corsAllowedOrigins.isEmpty()) { + registry.addMapping("/api/**") + .exposedHeaders("*") + .allowedHeaders("*") + .allowedMethods("*") + .allowedOrigins(corsAllowedOrigins) + .maxAge(3600); + } + } +} \ No newline at end of file diff --git a/wise-api/src/main/java/com/wisemapping/dao/LabelManager.java b/wise-api/src/main/java/com/wisemapping/dao/LabelManager.java new file mode 100644 index 00000000..8a6f1c6d --- /dev/null +++ b/wise-api/src/main/java/com/wisemapping/dao/LabelManager.java @@ -0,0 +1,26 @@ +package com.wisemapping.dao; + +import com.wisemapping.model.MindmapLabel; +import com.wisemapping.model.Account; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public interface LabelManager { + + void addLabel(@NotNull final MindmapLabel label); + + void saveLabel(@NotNull final MindmapLabel label); + + @NotNull + List getAllLabels(@NotNull final Account user); + + @Nullable + MindmapLabel getLabelById(int id, @NotNull final Account user); + + @Nullable + MindmapLabel getLabelByTitle(@NotNull final String title, @NotNull final Account user); + + void removeLabel(@NotNull final MindmapLabel label); +} diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/LabelManagerImpl.java b/wise-api/src/main/java/com/wisemapping/dao/LabelManagerImpl.java similarity index 50% rename from wise-webapp/src/main/java/com/wisemapping/dao/LabelManagerImpl.java rename to wise-api/src/main/java/com/wisemapping/dao/LabelManagerImpl.java index 92f39492..ae6b7616 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/LabelManagerImpl.java +++ b/wise-api/src/main/java/com/wisemapping/dao/LabelManagerImpl.java @@ -17,14 +17,13 @@ */ package com.wisemapping.dao; -import com.wisemapping.model.Label; -import com.wisemapping.model.User; -import jakarta.annotation.Resource; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.query.SelectionQuery; +import com.wisemapping.model.MindmapLabel; +import com.wisemapping.model.Account; +import jakarta.persistence.EntityManager; +import jakarta.persistence.TypedQuery; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import java.util.List; @@ -32,60 +31,55 @@ import java.util.List; @Repository("labelManager") public class LabelManagerImpl implements LabelManager { - @Resource - private SessionFactory sessionFactory; + @Autowired + private EntityManager entityManager; @Override - public void addLabel(@NotNull final Label label) { + public void addLabel(@NotNull final MindmapLabel label) { saveLabel(label); } @Override - public void saveLabel(@NotNull final Label label) { - getSession().persist(label); - } - - private Session getSession() { - return sessionFactory.getCurrentSession(); + public void saveLabel(@NotNull final MindmapLabel label) { + entityManager.persist(label); } @NotNull @Override - public List