Skip to content

Commit

Permalink
Merge pull request #10 from nkjmlab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yuu-nkjm authored Jun 12, 2023
2 parents 9c9697c + a94d633 commit f89ef79
Show file tree
Hide file tree
Showing 18 changed files with 483 additions and 454 deletions.
2 changes: 2 additions & 0 deletions go-fullbuild.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@echo off
setlocal
cd /d %~dp0
jps -lm|grep org.nkjmlab.go. | gawk "{print $1}" | xargs -r -n1 taskkill /F /T /PID
call mvn clean install -DskipTests=true -f sorm4j
call mvn clean install -DskipTests=true -f nkjmlab-utils
call mvn clean install dependency:copy-dependencies -DoutputDirectory=target/lib -f nkjmlab-go-webapp
endlocal
10 changes: 5 additions & 5 deletions nkjmlab-go-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.nkjmlab</groupId>
<artifactId>nkjmlab-go-webapp</artifactId>
<version>0.10.0</version>
<version>0.10.2</version>
<description>Go Web Application</description>
<url>https://github.com/nkjmlab/nkjmlab-go-webapp</url>
<licenses>
Expand All @@ -20,12 +20,12 @@
</developer>
</developers>
<scm>
<connection>scm:git:[email protected]:yuu-nkjmb/nkjmlab-go-webapp.git</connection>
<url>https://github.com/yuu-nkjm/nkjmlab-go-webapp</url>
<connection>scm:git:[email protected]:nkjmlab/nkjmlab-go.git</connection>
<url>https://github.com/nkjmlab/nkjmlab-go</url>
<tag>HEAD</tag>
</scm>
<properties>
<nkjmlab-utils-version>0.9.4</nkjmlab-utils-version>
<nkjmlab-utils-version>0.9.5</nkjmlab-utils-version>
<sorm4j-version>1.4.16</sorm4j-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<downloadSources>true</downloadSources>
Expand Down Expand Up @@ -97,7 +97,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.12.0</version>
<version>2.13.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DataSourceManager {

private static final int DEFAULT_TIMEOUT_SECONDS = 30;

private H2LocalDataSourceFactory factory;
private final H2LocalDataSourceFactory factory;

public DataSourceManager() {
FileDatabaseConfigJson fileDbConf = getFileDbConfig();
Expand All @@ -32,6 +32,21 @@ public DataSourceManager() {
log.info("server jdbcUrl={}", factory.getServerModeJdbcUrl());
}

private static FileDatabaseConfigJson getFileDbConfig() {
try {
return JacksonMapper.getDefaultMapper()
.toObject(ResourceUtils.getResourceAsFile("/conf/h2.json"),
FileDatabaseConfigJson.Builder.class)
.build();
} catch (Exception e) {
log.warn("Try to load h2.json.default");
return JacksonMapper.getDefaultMapper()
.toObject(ResourceUtils.getResourceAsFile("/conf/h2.json.default"),
FileDatabaseConfigJson.Builder.class)
.build();
}
}

public DataSource createHikariInMemoryDataSource() {
return createHikariDataSource(factory.getInMemoryModeJdbcUrl(), factory.getUsername(),
factory.getPassword());
Expand Down Expand Up @@ -76,20 +91,6 @@ private static JdbcConnectionPool createH2DataSource(String url, String user, St
return ds;
}

private static FileDatabaseConfigJson getFileDbConfig() {
try {
return JacksonMapper.getDefaultMapper()
.toObject(ResourceUtils.getResourceAsFile("/conf/h2.json"),
FileDatabaseConfigJson.Builder.class)
.build();
} catch (Exception e) {
log.warn("Try to load h2.json.default");
return JacksonMapper.getDefaultMapper()
.toObject(ResourceUtils.getResourceAsFile("/conf/h2.json.default"),
FileDatabaseConfigJson.Builder.class)
.build();
}
}

public H2LocalDataSourceFactory getFactory() {
return factory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.nkjmlab.go.javalin;

import java.util.Set;
import org.nkjmlab.go.javalin.auth.GoAuthService;
import org.nkjmlab.go.javalin.jsonrpc.GoAuthService;
import org.nkjmlab.go.javalin.model.relation.UsersTable;
import org.nkjmlab.go.javalin.model.relation.UsersTable.User;
import io.javalin.http.Context;
Expand All @@ -11,11 +11,11 @@

public class GoAccessManager implements AccessManager {

public enum UserRole implements RouteRole {
public enum AccessRole implements RouteRole {

BEFORE_LOGIN, GUEST, STUDENT, ADMIN;

static final UserRole[] LOGIN_ROLES = new UserRole[] {GUEST, STUDENT, ADMIN};
static final AccessRole[] LOGIN_ROLES = new AccessRole[] {GUEST, STUDENT, ADMIN};

}

Expand All @@ -27,26 +27,26 @@ public GoAccessManager(UsersTable usersTable, GoAuthService authService) {
this.authService = authService;
}

UserRole toUserRole(UsersTable usersTable, String sessionId) {
AccessRole toUserRole(UsersTable usersTable, String sessionId) {
if (!authService.isSignin(sessionId)) {
return UserRole.BEFORE_LOGIN;
return AccessRole.BEFORE_LOGIN;
}

User u = authService.toSigninSession(sessionId)
.map(login -> usersTable.selectByPrimaryKey(login.userId())).orElse(null);
if (u == null) {
return UserRole.BEFORE_LOGIN;
return AccessRole.BEFORE_LOGIN;
}
if (u.isAdmin()) {
return UserRole.ADMIN;
return AccessRole.ADMIN;
}
if (u.isStudent()) {
return UserRole.STUDENT;
return AccessRole.STUDENT;
}
if (u.isGuest()) {
return UserRole.GUEST;
return AccessRole.GUEST;
}
return UserRole.BEFORE_LOGIN;
return AccessRole.BEFORE_LOGIN;
}


Expand Down
Loading

0 comments on commit f89ef79

Please sign in to comment.