Skip to content
This repository was archived by the owner on Apr 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
1b81ae1
test
griffinht May 15, 2021
2e7ea88
add js debug mechanism - html can be edited, compiled js will resolve…
griffinht May 17, 2021
ec619b2
add login endpoint
griffinht May 17, 2021
b206e12
improve login
griffinht May 17, 2021
a45cbdb
bcrypt
griffinht May 17, 2021
2ff04f2
even more log in functionality
griffinht May 17, 2021
6e7ba47
add dummy password
griffinht May 17, 2021
6d0a5f8
probably fix memory leak
griffinht May 17, 2021
1fb1de0
rework, start to add register
griffinht May 17, 2021
053bd6c
fix header thing
griffinht May 17, 2021
5690d3c
maybe add existing temp user registration
griffinht May 17, 2021
b23464a
probably didn't add logout
griffinht May 17, 2021
bfdd987
rework db sessions
griffinht May 18, 2021
e0d51b3
change validation
griffinht May 18, 2021
e2b05e6
refactor http cookie
griffinht May 18, 2021
7ea88f0
refactor login
griffinht May 18, 2021
cc20868
add expiration for database
griffinht May 18, 2021
aa65451
fix npe, probably rework debug
griffinht May 18, 2021
01b91a8
remember me
griffinht May 18, 2021
e0ed28d
start to rework db - exception handling
griffinht May 18, 2021
183b4a5
rework db again
griffinht May 18, 2021
3ed9126
fix order
griffinht May 18, 2021
8d0a9c9
add clear cookie
griffinht May 18, 2021
0198545
fix logout
griffinht May 18, 2021
633801d
rename
griffinht May 18, 2021
b81bddb
fix cookie being overwritten
griffinht May 18, 2021
7ce86f2
tiny change
griffinht May 19, 2021
9b40cd3
remove verbose log message
griffinht May 19, 2021
dd4d719
remove unused ManualConfig.java
griffinht May 19, 2021
d3cef0d
refactor
griffinht May 19, 2021
5f4ba4f
refactor names again
griffinht May 20, 2021
183144e
start to rework state
griffinht May 21, 2021
8b7eed6
add intellij build configuration
griffinht May 22, 2021
46ea78e
fix dependency
griffinht May 22, 2021
768c4b4
fix package
griffinht May 22, 2021
f047e8c
start to add unit tests
griffinht May 22, 2021
a2c6334
add equals
griffinht May 22, 2021
91cfab3
remove unused method
griffinht May 22, 2021
cf60b90
add jmh
griffinht May 22, 2021
8dfdc2f
rework gradle files
griffinht May 22, 2021
c7e8f1a
move extra gradle stuff
griffinht May 22, 2021
e391b11
remove
griffinht May 23, 2021
c9b652f
duplicate registration usernames are handled
griffinht May 23, 2021
da4ecc6
start to rework exceptions
griffinht May 23, 2021
1931c64
rework form
griffinht May 23, 2021
eb258cd
exceptions are printed to console
griffinht May 23, 2021
e8fed96
add NotFoundException
griffinht May 23, 2021
cf931ec
exceptions are logged again
griffinht May 23, 2021
42cddad
more exceptions
griffinht May 23, 2021
56c6e38
move around classes and methods
griffinht May 23, 2021
8192898
start to rework query/request
griffinht May 23, 2021
85d8e25
implemented Route
griffinht May 23, 2021
9dd91a7
compiles
griffinht May 23, 2021
5419d44
clean up
griffinht May 23, 2021
1f4526c
fix path
griffinht May 23, 2021
580acda
fix registering while logged in
griffinht May 23, 2021
54acb1f
improve login
griffinht May 23, 2021
9187277
add proper database exceptions, needs testing
griffinht May 24, 2021
c0f45a7
update CHANGELOG.md
griffinht May 24, 2021
fdd1730
simplify login
griffinht May 24, 2021
4809f7d
better exception handling in HttpAuthenticator
griffinht May 24, 2021
923e361
add exceptions to HttpHandler
griffinht May 24, 2021
d6d8763
more exception handling
griffinht May 24, 2021
34a7840
move authentication to HttpUserSession
griffinht May 24, 2021
17e001f
start to rework http cookie
griffinht May 24, 2021
aa26cac
start to refactor all the cookies
griffinht May 25, 2021
b707953
use AuthenticationResult instead of exceptions
griffinht May 25, 2021
23d1feb
add tons of interfaces for database, idk if this is good
griffinht May 25, 2021
bd34f04
compiles
griffinht May 25, 2021
148cea2
remove unused AuthenticationException.java
griffinht May 25, 2021
0380576
refactor to switch
griffinht May 25, 2021
046baf9
remove FailedException.java, replace with DatabaseException
griffinht May 25, 2021
6928ae4
better exceptions and logging for db
griffinht May 25, 2021
ea8f6ec
start to add nullable, documentation
griffinht May 26, 2021
761e866
probably improve javadoc, still need to figure out a style/format
griffinht May 26, 2021
bc59e73
javadoc, unexpected exceptions throw runtime exceptions
griffinht May 26, 2021
4d0b82a
missed one
griffinht May 26, 2021
1011ccf
spacing and stuff
griffinht May 26, 2021
62202f5
start to implement nullable properly, improve login assertions
griffinht May 26, 2021
4ca4dd6
nullable is properly handled
griffinht May 26, 2021
a37610e
fix logins not verified :/, remove debug, assertions are used properly
griffinht May 26, 2021
470697f
fix assertions
griffinht May 26, 2021
8db6deb
getters can throw
griffinht May 26, 2021
b641d3f
start to improve toString of ScribbleshareRoom
griffinht May 26, 2021
9b1bdcd
change #toString formatting
griffinht May 26, 2021
e016539
fix HttpAuthenticator passing along unauthenticated requests
griffinht May 26, 2021
d406743
disable verbose console output
griffinht May 26, 2021
46d0d1a
fix duplicate log
griffinht May 26, 2021
d8730bb
fix npe
griffinht May 26, 2021
8e271fa
toString for authentication package
griffinht May 26, 2021
aaed473
add DebugString, start to refactor toString methods
griffinht May 26, 2021
ef082a6
refactor with slick factory method
griffinht May 26, 2021
107a345
change to queue, put symbols in variables
griffinht May 26, 2021
f46eccf
improve DebugString formatting
griffinht May 26, 2021
9f3ce1c
toString for pretty much all of scribbleshare-commoons
griffinht May 27, 2021
644eeba
remove unused classw
griffinht May 27, 2021
f0029ff
add toString to protocol
griffinht May 27, 2021
34b42fd
fix super.toString()
griffinht May 27, 2021
85516f5
add FormHandler
griffinht May 27, 2021
8bcafec
more handler stuff
griffinht May 27, 2021
aafecec
FileRequestHandler
griffinht May 27, 2021
8896b21
move stuff around
griffinht May 27, 2021
b5ddb55
change HttpAuthenticator to the right thing
griffinht May 27, 2021
1a2e19b
add explicit boolean returns to prevent no response
griffinht May 27, 2021
3e285c6
clean up HttpUtils
griffinht May 27, 2021
b62fa2d
move package
griffinht May 28, 2021
a826a59
move FileRequestHandler
griffinht May 28, 2021
4f8c540
tiny change
griffinht May 28, 2021
d918565
simplified exception
griffinht May 28, 2021
f36af40
oops
griffinht May 28, 2021
0eee55a
fix npe
griffinht May 28, 2021
13c716e
fix logs instead of throws
griffinht May 28, 2021
e5bbc4c
start to add login api
griffinht May 28, 2021
3dfd4c9
add register api
griffinht May 28, 2021
c405997
fix authenticator allowing unauthenticated requests
griffinht May 28, 2021
49ac5ad
improve log, headers are actually sent
griffinht May 28, 2021
8c03ad4
add some csrf protection i think
griffinht May 28, 2021
2f09f2f
add origin check
griffinht May 28, 2021
01a7d17
microoptimization
griffinht May 28, 2021
9f3c443
quieted down logging a bit
griffinht May 28, 2021
58d7c14
add uri check to pipeline
griffinht May 28, 2021
b2f92eb
probably rework bad origin checking
griffinht May 29, 2021
903cff3
fix the build command not actually being run :/
griffinht May 29, 2021
c07f7b1
fix production port
griffinht May 29, 2021
f09de92
simplify logging
griffinht May 29, 2021
660079e
rework handlers
griffinht May 29, 2021
b1693d9
improve cors or something
griffinht May 29, 2021
a11c53d
logging
griffinht May 29, 2021
9a3c877
finally add slf4j impl
griffinht May 30, 2021
18290ab
rework origin and logging
griffinht May 30, 2021
8384cac
fix login causing postgres warnings
griffinht May 30, 2021
30a9437
rework js for multi stuff
griffinht May 30, 2021
2e58c10
rework auth
griffinht May 30, 2021
0430225
generics lol
griffinht May 30, 2021
956fb60
simplified interfaces
griffinht May 30, 2021
38d8d67
probably fix login, logout, register
griffinht May 30, 2021
c923b4f
fix headers not being sent
griffinht May 30, 2021
87dae65
probably fix cookies
griffinht May 31, 2021
ae4afad
start to redo http
griffinht May 31, 2021
a534505
fix nothing being sent
griffinht May 31, 2021
8e6fcb0
start to add auto log in
griffinht May 31, 2021
4ca60a5
start to refactor with modular http stuff
griffinht Jun 27, 2021
1bd0c71
simplify and rename
griffinht Jul 17, 2021
47e069f
more package fixes
griffinht Jul 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
build

# IntelliJ IDEA
.idea

# Gradle
.gradle
build

# Gradle binaries
# These are not needed for building the project with Docker
# These would be needed to build the projct without Docker, so instead just install Gradle on your system
gradle
# just install gradle lol
gradle/wrapper
gradlew
gradlew.bat
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Canvas manipulation

did a bunch of commits on master

### v0.6
## v0.6
Rework project architecture

### v0.6.0
Expand All @@ -154,4 +154,13 @@ Typescript refactor

### v0.6.1
Fix build system
- Rework rollup with typescript and environment variables
- Rework rollup with typescript and environment variables

## v0.7
HTTP improvements

### v0.7.0
Rework authentication
- Robust exception handling
- Password based authentication schemes
- Log in, log out, registration pages
8 changes: 4 additions & 4 deletions scribbleshare-app/Dockerfile → app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ FROM node:15 AS scribbleshare-frontend-build

WORKDIR /usr/src/app

COPY scribbleshare-frontend .
COPY frontend .

RUN npm install
RUN chmod +x build.sh \
build.sh
RUN chmod +x build.sh
RUN ./build.sh


#
Expand All @@ -25,7 +25,7 @@ WORKDIR /usr/app
COPY --from=scribbleshare-frontend-build /usr/src/app/build ./html

# Copy jar (should already be built with gradle shadowJar)
COPY scribbleshare-backend/build/libs/scribbleshare-backend-all.jar scribbleshare-backend.jar
COPY backend/build/libs/scribbleshare-backend-all.jar scribbleshare-backend.jar

HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD curl --fail http://localhost:80/healthcheck || exit 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ plugins {
id 'com.github.johnrengelman.shadow' version '6.1.0'
}

repositories {
mavenCentral()
}

dependencies {
implementation project(':scribbleshare-commons')
implementation project(':commons')
}

// https://github.com/johnrengelman/shadow/issues/609#issuecomment-795983873
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import io.netty.channel.ChannelFuture;
import net.stzups.scribbleshare.Scribbleshare;
import net.stzups.scribbleshare.backend.data.database.ScribbleshareBackendDatabase;
import net.stzups.scribbleshare.backend.data.database.implementations.PostgresDatabase;
import net.stzups.scribbleshare.backend.server.BackendHttpServerInitializer;
import net.stzups.scribbleshare.data.database.ScribbleshareDatabase;
import net.stzups.scribbleshare.data.database.implementations.PostgresDatabase;

public class ScribbleshareBackend extends Scribbleshare implements AutoCloseable {
private final ScribbleshareBackendConfig config;
Expand Down Expand Up @@ -33,7 +33,7 @@ public static void main(String[] args) throws Exception {
}
}

public ScribbleshareDatabase getDatabase() {
public ScribbleshareBackendDatabase getDatabase() {
return database;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.stzups.scribbleshare.backend;

import net.stzups.netty.http.handler.handlers.FileRequestHandler;
import net.stzups.scribbleshare.ScribbleshareConfig;
import net.stzups.scribbleshare.backend.server.http.HttpServerHandler;

public interface ScribbleshareBackendConfig extends ScribbleshareConfig, HttpServerHandler.Config {
public interface ScribbleshareBackendConfig extends ScribbleshareConfig, FileRequestHandler.Config {

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package net.stzups.scribbleshare.backend;

import net.stzups.config.ConfigKey;
import net.stzups.config.OptionalConfigKey;
import net.stzups.scribbleshare.ScribbleshareConfigImplementation;
import net.stzups.scribbleshare.config.ConfigKey;
import net.stzups.scribbleshare.config.OptionalConfigKey;

public class ScribbleshareBackendConfigImplementation extends ScribbleshareConfigImplementation implements ScribbleshareBackendConfig {
private static final ConfigKey<String> HTML_ROOT = new OptionalConfigKey<>("html.root", "html");
private static final ConfigKey<String> MIME_TYPES_FILE_PATH = new OptionalConfigKey<>("mimetypes.path", "mime.types");
private static final ConfigKey<Integer> HTTP_CACHE_SECONDS = new OptionalConfigKey<>("http.cache.seconds", 0);
private static final ConfigKey<String> DEBUG_JS_ROOT = new OptionalConfigKey<>("debug.js.root", "");

@Override
public String getHttpRoot() {
Expand All @@ -24,4 +25,9 @@ public String getMimeTypesFilePath() {
return getString(MIME_TYPES_FILE_PATH);
}

@Override
public String getDebugJsRoot() {
return getString(DEBUG_JS_ROOT);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package net.stzups.scribbleshare.backend.data;

import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import net.stzups.netty.http.exception.exceptions.BadRequestException;
import net.stzups.netty.http.exception.exceptions.InternalServerException;
import net.stzups.netty.http.exception.exceptions.UnauthorizedException;
import net.stzups.scribbleshare.backend.data.database.databases.PersistentHttpSessionDatabase;
import net.stzups.scribbleshare.data.database.databases.HttpSessionDatabase;
import net.stzups.scribbleshare.data.database.databases.UserDatabase;
import net.stzups.scribbleshare.data.database.exception.DatabaseException;
import net.stzups.scribbleshare.data.objects.User;
import net.stzups.scribbleshare.data.objects.authentication.AuthenticationResult;
import net.stzups.scribbleshare.data.objects.authentication.UserSession;
import net.stzups.scribbleshare.data.objects.authentication.http.HttpConfig;
import net.stzups.scribbleshare.data.objects.authentication.http.HttpSessionCookie;
import net.stzups.scribbleshare.data.objects.authentication.http.HttpUserSession;
import net.stzups.util.DebugString;

import java.sql.Timestamp;
import java.time.Duration;
import java.time.Instant;

public class PersistentHttpUserSession extends UserSession {
private static final Duration MAX_AGE = Duration.ofDays(90);

public static final String LOGIN_PATH = "/";

public PersistentHttpUserSession(HttpConfig config, HttpUserSession httpSession, HttpResponse response) {
super(httpSession.getUser());
new PersistentHttpUserSessionCookie(getId(), generateToken()).setCookie(config, response);
}

public PersistentHttpUserSession(long id, Timestamp creation, Timestamp expiration, long userId, ByteBuf byteBuf) {
super(id, creation, expiration, userId, byteBuf);
}

public AuthenticationResult validate(HttpSessionCookie cookie) {
if (!Instant.now().isBefore(getCreated().toInstant().plus(MAX_AGE)))
return AuthenticationResult.STALE;

return validate(cookie.getToken());
}

@Override
public String toString() {
return DebugString.get(PersistentHttpUserSession.class, super.toString())
.toString();
}

/** get and expire persistent http user session */

public static<T extends PersistentHttpSessionDatabase> PersistentHttpUserSession getSession(T database, FullHttpRequest request, HttpResponse response) throws UnauthorizedException, InternalServerException {
PersistentHttpUserSessionCookie cookie = PersistentHttpUserSessionCookie.getCookie(request);
if (cookie == null) {
return null;
}

PersistentHttpUserSession session;
try {
session = database.getPersistentHttpUserSession(cookie);

if (session == null) {
throw new UnauthorizedException("No " + PersistentHttpUserSession.class + " for " + cookie);
}

database.expirePersistentHttpUserSession(session);
PersistentHttpUserSessionCookie.clearCookie(response);
} catch (DatabaseException e) {
throw new InternalServerException(e);
}

AuthenticationResult result = session.validate(cookie);
if (result != AuthenticationResult.SUCCESS) {
throw new UnauthorizedException("Validating " + cookie + " for " + session + " resulted in " + result);
}

return session;
}

/** logs in if not authenticated, or null if no auth */
public static<T extends HttpSessionDatabase & PersistentHttpSessionDatabase & UserDatabase> HttpUserSession logIn(HttpConfig config, T database, FullHttpRequest request, HttpResponse response) throws UnauthorizedException, InternalServerException, BadRequestException {
PersistentHttpUserSession session = getSession(database, request, response);
if (session == null) {
return null;
}

User user;
try {
user = database.getUser(session.getUser());
} catch (DatabaseException e) {
throw new InternalServerException(e);
}
if (user == null) {
throw new InternalServerException("User somehow does not exist " + user);
}

HttpUserSession s = new HttpUserSession(config, user, response);
return createHttpSession(config, database, user, headers);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.stzups.scribbleshare.backend.data;

import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.cookie.Cookie;
import net.stzups.netty.http.HttpUtils;
import net.stzups.netty.http.exception.exceptions.BadRequestException;
import net.stzups.scribbleshare.data.objects.authentication.http.HttpConfig;
import net.stzups.scribbleshare.data.objects.authentication.http.HttpSessionCookie;
import net.stzups.scribbleshare.data.objects.exceptions.DeserializationException;
import net.stzups.util.DebugString;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

public class PersistentHttpUserSessionCookie extends HttpSessionCookie {
private static final String COOKIE_NAME = "persistent_session";
private static final Duration MAX_AGE = Duration.ofDays(90);

PersistentHttpUserSessionCookie(ByteBuf byteBuf) throws DeserializationException {
super(byteBuf);
}

PersistentHttpUserSessionCookie(long id, byte[] token) {
super(id, token);
}

/* @Override
protected static void setCookie(HttpConfig config, DefaultCookie cookie) {

}*/

public void setCookie(HttpConfig config, HttpHeaders headers) {
Cookie cookie = getCookie(config, COOKIE_NAME);
cookie.setMaxAge(MAX_AGE.get(ChronoUnit.SECONDS)); //persistent cookie
cookie.setPath("/login");//todo
HttpUtils.setCookie(headers, cookie);
}

public static PersistentHttpUserSessionCookie getCookie(HttpRequest request) throws BadRequestException {
ByteBuf byteBuf = HttpSessionCookie.getCookie(request, COOKIE_NAME);
if (byteBuf != null) {
try {
return new PersistentHttpUserSessionCookie(byteBuf);
} catch (DeserializationException e) {
throw new BadRequestException("Malformed cookie", e);
} finally {
byteBuf.release();
}
}

return null;
}

public static void clearCookie(HttpResponse response) {
HttpSessionCookie.clearCookie(COOKIE_NAME, response);
}

@Override
public String toString() {
return DebugString.get(PersistentHttpUserSessionCookie.class, super.toString())
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.stzups.scribbleshare.backend.data.database;

import net.stzups.scribbleshare.backend.data.database.databases.PersistentHttpSessionDatabase;
import net.stzups.scribbleshare.data.database.ScribbleshareDatabase;

public interface ScribbleshareBackendDatabase extends ScribbleshareDatabase, PersistentHttpSessionDatabase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.stzups.scribbleshare.backend.data.database.databases;

import net.stzups.scribbleshare.backend.data.PersistentHttpUserSession;
import net.stzups.scribbleshare.backend.data.PersistentHttpUserSessionCookie;
import net.stzups.scribbleshare.data.database.exception.DatabaseException;
import net.stzups.scribbleshare.data.objects.authentication.http.HttpSessionCookie;
import org.jetbrains.annotations.Nullable;

public interface PersistentHttpSessionDatabase {
/**
* @param cookie {@link HttpSessionCookie} of {@link PersistentHttpUserSession}
* @return null if {@link PersistentHttpUserSession} does not exist
*/
@Nullable
PersistentHttpUserSession getPersistentHttpUserSession(PersistentHttpUserSessionCookie cookie) throws DatabaseException;

void addPersistentHttpUserSession(PersistentHttpUserSession persistentHttpSession) throws DatabaseException;

/**
* Expire existing {@link PersistentHttpUserSession}
* todo fail silently or loudly if the persistent http user session does not exist?
*/
void expirePersistentHttpUserSession(PersistentHttpUserSession persistentHttpUserSession) throws DatabaseException;
}
Loading