From bbd7754385463e38fc4594fa78ae2085ec177876 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:58:22 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20password=E3=82=92UserDetail?= =?UTF-8?q?=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/e2eTest/resources/oauth2/user.sql | 10 +++- ...iV1AccountsIdFollowPost フォローできる.sql | 6 +- ...でフォロワーがfollowers投稿を取得できる.sql | 10 ++-- ...証でフォロワーがpublic投稿を取得できる.sql | 11 ++-- ...でフォロワーがunlisted投稿を取得できる.sql | 14 ++--- ...稿はattachmentにDocumentとして画像が存在する.sql | 5 +- ...イになっている投稿はinReplyToが存在する.sql | 7 +-- ...でfollowers投稿を取得しようとすると404.sql | 5 +- .../sql/note/匿名でpublic投稿を取得できる.sql | 8 +-- .../note/匿名でunlisted投稿を取得できる.sql | 7 +-- src/intTest/resources/sql/test-post.sql | 2 +- src/intTest/resources/sql/test-user.sql | 4 +- src/intTest/resources/sql/test-user2.sql | 5 +- .../hideout/core/domain/model/actor/Actor.kt | 30 +++++++--- .../domain/model/userdetails/UserDetail.kt | 8 +++ .../model/userdetails/UserDetailRepository.kt | 7 +++ .../exposed/UserResultRowMapper.kt | 1 - .../exposedrepository/ActorRepositoryImpl.kt | 5 +- .../ExposedTimelineRepository.kt | 10 ++-- .../UserDetailRepositoryImpl.kt | 60 +++++++++++++++++++ .../oauth2/UserDetailsServiceImpl.kt | 13 +++- .../core/service/user/UserServiceImpl.kt | 10 +++- .../resources/db/migration/V1__Init_DB.sql | 2 +- src/test/kotlin/utils/UserBuilder.kt | 2 - 24 files changed, 164 insertions(+), 78 deletions(-) create mode 100644 src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetailRepository.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt diff --git a/src/e2eTest/resources/oauth2/user.sql b/src/e2eTest/resources/oauth2/user.sql index 15aa977f..50c52058 100644 --- a/src/e2eTest/resources/oauth2/user.sql +++ b/src/e2eTest/resources/oauth2/user.sql @@ -1,7 +1,7 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) +insert into actors (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (1730415786666758144, 'test-user', 'localhost', 'Im test user.', 'THis account is test user.', - '$2a$10$/mWC/n7nC7X3l9qCEOKnredxne2zewoqEsJWTOdlKfg2zXKJ0F9Em', 'http://localhost/users/test-user/inbox', + 'http://localhost/users/test-user/inbox', 'http://localhost/users/test-user/outbox', 'http://localhost/users/test-user', '-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAi4mifRg6huAIn6DXk3Vn @@ -44,3 +44,7 @@ Ja15+ZWbOA4vJA9pOh3x4XM= ', 1701398248417, 'http://localhost/users/test-user#pubkey', 'http://localhost/users/test-user/following', 'http://localhost/users/test-users/followers', null); + +insert into user_details (actor_id, password, auto_accept_follow_request, auto_accept_followee_follow_request) +values ( 1730415786666758144 + , '$2a$10$/mWC/n7nC7X3l9qCEOKnredxne2zewoqEsJWTOdlKfg2zXKJ0F9Em', true, true) diff --git a/src/intTest/resources/sql/accounts/apiV1AccountsIdFollowPost フォローできる.sql b/src/intTest/resources/sql/accounts/apiV1AccountsIdFollowPost フォローできる.sql index 53ea2830..a749a39a 100644 --- a/src/intTest/resources/sql/accounts/apiV1AccountsIdFollowPost フォローできる.sql +++ b/src/intTest/resources/sql/accounts/apiV1AccountsIdFollowPost フォローできる.sql @@ -1,7 +1,6 @@ -insert into "USERS" (id, name, domain, screen_name, description, password, inbox, outbox, url, public_key, private_key, - created_at, key_id, following, followers, instance) +insert into "actors" (id, name, domain, screen_name, description, inbox, outbox, url, public_key, private_key, + created_at, key_id, following, followers, instance) VALUES (3733363, 'follow-test-user-1', 'example.com', 'follow-test-user-1-name', '', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/follow-test-user-1/inbox', 'https://example.com/users/follow-test-user-1/outbox', 'https://example.com/users/follow-test-user-1', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -9,7 +8,6 @@ VALUES (3733363, 'follow-test-user-1', 'example.com', 'follow-test-user-1-name', 'https://example.com/users/follow-test-user-1#pubkey', 'https://example.com/users/follow-test-user-1/following', 'https://example.com/users/follow-test-user-1/followers', null), (37335363, 'follow-test-user-2', 'example.com', 'follow-test-user-2-name', '', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/follow-test-user-2/inbox', 'https://example.com/users/follow-test-user-2/outbox', 'https://example.com/users/follow-test-user-2', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', diff --git a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがfollowers投稿を取得できる.sql b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがfollowers投稿を取得できる.sql index d3076eb1..87509d2d 100644 --- a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがfollowers投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがfollowers投稿を取得できる.sql @@ -1,7 +1,6 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (8, 'test-user8', 'example.com', 'Im test-user8.', 'THis account is test-user8.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user8/inbox', 'https://example.com/users/test-user8/outbox', 'https://example.com/users/test-user8', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -9,10 +8,9 @@ VALUES (8, 'test-user8', 'example.com', 'Im test-user8.', 'THis account is test- 'https://example.com/users/test-user8#pubkey', 'https://example.com/users/test-user8/following', 'https://example.com/users/test-user8/followers', null); -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (9, 'test-user9', 'follower.example.com', 'Im test-user9.', 'THis account is test-user9.', - null, 'https://follower.example.com/users/test-user9/inbox', 'https://follower.example.com/users/test-user9/outbox', 'https://follower.example.com/users/test-user9', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -21,10 +19,10 @@ VALUES (9, 'test-user9', 'follower.example.com', 'Im test-user9.', 'THis account 'https://follower.example.com/users/test-user9/following', 'https://follower.example.com/users/test-user9/followers', null); -insert into relationships (user_id, target_user_id, following, blocking, muting, follow_request, +insert into relationships (actor_id, target_actor_id, following, blocking, muting, follow_request, ignore_follow_request) VALUES (9, 8, true, false, false, false, false); -insert into POSTS (ID, USER_ID, OVERVIEW, TEXT, CREATED_AT, VISIBILITY, URL, REPLY_ID, REPOST_ID, SENSITIVE, AP_ID) +insert into POSTS (ID, ACTOR_ID, OVERVIEW, TEXT, CREATED_AT, VISIBILITY, URL, REPLY_ID, REPOST_ID, SENSITIVE, AP_ID) VALUES (1239, 8, null, 'test post', 12345680, 2, 'https://example.com/users/test-user8/posts/1239', null, null, false, 'https://example.com/users/test-user8/posts/1239'); diff --git a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがpublic投稿を取得できる.sql b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがpublic投稿を取得できる.sql index 82d37cc0..b4a0201d 100644 --- a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがpublic投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがpublic投稿を取得できる.sql @@ -1,7 +1,6 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (4, 'test-user4', 'example.com', 'Im test user4.', 'THis account is test user4.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user4/inbox', 'https://example.com/users/test-user4/outbox', 'https://example.com/users/test-user4', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -9,10 +8,10 @@ VALUES (4, 'test-user4', 'example.com', 'Im test user4.', 'THis account is test 'https://example.com/users/test-user4#pubkey', 'https://example.com/users/test-user4/following', 'https://example.com/users/test-user4/followers', null); -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (5, 'test-user5', 'follower.example.com', 'Im test user5.', 'THis account is test user5.', - null, + 'https://follower.example.com/users/test-user5/inbox', 'https://follower.example.com/users/test-user5/outbox', 'https://follower.example.com/users/test-user5', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -21,11 +20,11 @@ VALUES (5, 'test-user5', 'follower.example.com', 'Im test user5.', 'THis account 'https://follower.example.com/users/test-user5/following', 'https://follower.example.com/users/test-user5/followers', null); -insert into relationships (user_id, target_user_id, following, blocking, muting, follow_request, +insert into relationships (actor_id, target_actor_id, following, blocking, muting, follow_request, ignore_follow_request) VALUES (5, 4, true, false, false, false, false); -insert into POSTS (ID, "USER_ID", OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, +insert into POSTS (ID, "actor_ID", OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) VALUES (1237, 4, null, 'test post', 12345680, 0, 'https://example.com/users/test-user4/posts/1237', null, null, false, 'https://example.com/users/test-user4/posts/1237'); diff --git a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがunlisted投稿を取得できる.sql b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがunlisted投稿を取得できる.sql index cce85d78..a90569a1 100644 --- a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがunlisted投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがunlisted投稿を取得できる.sql @@ -1,7 +1,6 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (6, 'test-user6', 'example.com', 'Im test-user6.', 'THis account is test-user6.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user6/inbox', 'https://example.com/users/test-user6/outbox', 'https://example.com/users/test-user6', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -9,10 +8,9 @@ VALUES (6, 'test-user6', 'example.com', 'Im test-user6.', 'THis account is test- 'https://example.com/users/test-user6#pubkey', 'https://example.com/users/test-user6/following', 'https://example.com/users/test-user6/followers', null); -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (7, 'test-user7', 'follower.example.com', 'Im test-user7.', 'THis account is test-user7.', - null, 'https://follower.example.com/users/test-user7/inbox', 'https://follower.example.com/users/test-user7/outbox', 'https://follower.example.com/users/test-user7', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -21,11 +19,11 @@ VALUES (7, 'test-user7', 'follower.example.com', 'Im test-user7.', 'THis account 'https://follower.example.com/users/test-user7/following', 'https://follower.example.com/users/test-user7/followers', null); -insert into relationships (user_id, target_user_id, following, blocking, muting, follow_request, +insert into relationships (actor_id, target_actor_id, following, blocking, muting, follow_request, ignore_follow_request) VALUES (7, 6, true, false, false, false, false); -insert into POSTS (ID, "USER_ID", OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, +insert into POSTS (ID, "actor_ID", OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) VALUES (1238, 6, null, 'test post', 12345680, 1, 'https://example.com/users/test-user6/posts/1238', null, null, false, 'https://example.com/users/test-user6/posts/1238'); diff --git a/src/intTest/resources/sql/note/メディア付き投稿はattachmentにDocumentとして画像が存在する.sql b/src/intTest/resources/sql/note/メディア付き投稿はattachmentにDocumentとして画像が存在する.sql index efe290a5..499595c8 100644 --- a/src/intTest/resources/sql/note/メディア付き投稿はattachmentにDocumentとして画像が存在する.sql +++ b/src/intTest/resources/sql/note/メディア付き投稿はattachmentにDocumentとして画像が存在する.sql @@ -1,7 +1,6 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (11, 'test-user11', 'example.com', 'Im test-user11.', 'THis account is test-user11.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user11/inbox', 'https://example.com/users/test-user11/outbox', 'https://example.com/users/test-user11', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -9,7 +8,7 @@ VALUES (11, 'test-user11', 'example.com', 'Im test-user11.', 'THis account is te 'https://example.com/users/test-user11#pubkey', 'https://example.com/users/test-user11/following', 'https://example.com/users/test-user11/followers', null); -insert into POSTS (ID, "USER_ID", OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, +insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) VALUES (1242, 11, null, 'test post', 12345680, 0, 'https://example.com/users/test-user11/posts/1242', null, null, false, 'https://example.com/users/test-user11/posts/1242'); diff --git a/src/intTest/resources/sql/note/リプライになっている投稿はinReplyToが存在する.sql b/src/intTest/resources/sql/note/リプライになっている投稿はinReplyToが存在する.sql index 30455c5c..76182d59 100644 --- a/src/intTest/resources/sql/note/リプライになっている投稿はinReplyToが存在する.sql +++ b/src/intTest/resources/sql/note/リプライになっている投稿はinReplyToが存在する.sql @@ -1,7 +1,6 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (10, 'test-user10', 'example.com', 'Im test-user10.', 'THis account is test-user10.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user10/inbox', 'https://example.com/users/test-user10/outbox', 'https://example.com/users/test-user10', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -9,7 +8,7 @@ VALUES (10, 'test-user10', 'example.com', 'Im test-user10.', 'THis account is te 'https://example.com/users/test-user10#pubkey', 'https://example.com/users/test-user10/following', 'https://example.com/users/test-user10/followers', null); -insert into POSTS (ID, "USER_ID", OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, +insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) VALUES (1240, 10, null, 'test post', 12345680, 0, 'https://example.com/users/test-user10/posts/1240', null, null, false, 'https://example.com/users/test-user10/posts/1240'), diff --git a/src/intTest/resources/sql/note/匿名でfollowers投稿を取得しようとすると404.sql b/src/intTest/resources/sql/note/匿名でfollowers投稿を取得しようとすると404.sql index 9b880740..e97f9b2d 100644 --- a/src/intTest/resources/sql/note/匿名でfollowers投稿を取得しようとすると404.sql +++ b/src/intTest/resources/sql/note/匿名でfollowers投稿を取得しようとすると404.sql @@ -1,7 +1,6 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (3, 'test-user3', 'example.com', 'Im test user3.', 'THis account is test user3.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user3/inbox', 'https://example.com/users/test-user3/outbox', 'https://example.com/users/test-user3', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -9,7 +8,7 @@ VALUES (3, 'test-user3', 'example.com', 'Im test user3.', 'THis account is test 'https://example.com/users/test-user3#pubkey', 'https://example.com/users/test-user3/following', 'https://example.com/users/test-user3/followers', null); -insert into POSTS (ID, "USER_ID", OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, +insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) VALUES (1236, 3, null, 'test post', 12345680, 2, 'https://example.com/users/test-user3/posts/1236', null, null, false, 'https://example.com/users/test-user3/posts/1236') diff --git a/src/intTest/resources/sql/note/匿名でpublic投稿を取得できる.sql b/src/intTest/resources/sql/note/匿名でpublic投稿を取得できる.sql index 14e7b47a..414a4394 100644 --- a/src/intTest/resources/sql/note/匿名でpublic投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/匿名でpublic投稿を取得できる.sql @@ -1,14 +1,14 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) +insert into actors (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (1, 'test-user', 'example.com', 'Im test user.', 'THis account is test user.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user/inbox', + 'https://example.com/users/test-user/inbox', 'https://example.com/users/test-user/outbox', 'https://example.com/users/test-user', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user#pubkey', 'https://example.com/users/test-user/following', 'https://example.com/users/test-users/followers', null); -insert into POSTS (ID, "USER_ID", OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, +insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) VALUES (1234, 1, null, 'test post', 12345680, 0, 'https://example.com/users/test-user/posts/1234', null, null, false, 'https://example.com/users/test-user/posts/1234') diff --git a/src/intTest/resources/sql/note/匿名でunlisted投稿を取得できる.sql b/src/intTest/resources/sql/note/匿名でunlisted投稿を取得できる.sql index f9bfe549..6a7dc9c5 100644 --- a/src/intTest/resources/sql/note/匿名でunlisted投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/匿名でunlisted投稿を取得できる.sql @@ -1,7 +1,6 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) +insert into actors (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (2, 'test-user2', 'example.com', 'Im test user2.', 'THis account is test user2.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user2/inbox', 'https://example.com/users/test-user2/outbox', 'https://example.com/users/test-user2', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', @@ -9,7 +8,7 @@ VALUES (2, 'test-user2', 'example.com', 'Im test user2.', 'THis account is test 'https://example.com/users/test-user2#pubkey', 'https://example.com/users/test-user2/following', 'https://example.com/users/test-user2/followers', null); -insert into POSTS (ID, "USER_ID", OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, +insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) VALUES (1235, 2, null, 'test post', 12345680, 1, 'https://example.com/users/test-user2/posts/1235', null, null, false, 'https://example.com/users/test-user2/posts/1235') diff --git a/src/intTest/resources/sql/test-post.sql b/src/intTest/resources/sql/test-post.sql index 01bcb2dd..eefb3795 100644 --- a/src/intTest/resources/sql/test-post.sql +++ b/src/intTest/resources/sql/test-post.sql @@ -1,3 +1,3 @@ -insert into posts (id, user_id, overview, text, created_at, visibility, url, repost_id, reply_id, sensitive, ap_id) +insert into posts (id, actor_id, overview, text, created_at, visibility, url, repost_id, reply_id, sensitive, ap_id) VALUES (1, 1, null, 'hello', 1234455, 0, 'https://localhost/users/1/posts/1', null, null, false, 'https://users/1/posts/1'); diff --git a/src/intTest/resources/sql/test-user.sql b/src/intTest/resources/sql/test-user.sql index a21d1795..54cb1852 100644 --- a/src/intTest/resources/sql/test-user.sql +++ b/src/intTest/resources/sql/test-user.sql @@ -1,7 +1,7 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (1, 'test-user', 'example.com', 'Im test user.', 'THis account is test user.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user/inbox', + 'https://example.com/users/test-user/inbox', 'https://example.com/users/test-user/outbox', 'https://example.com/users/test-user', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, diff --git a/src/intTest/resources/sql/test-user2.sql b/src/intTest/resources/sql/test-user2.sql index 7b123701..284716cb 100644 --- a/src/intTest/resources/sql/test-user2.sql +++ b/src/intTest/resources/sql/test-user2.sql @@ -1,7 +1,6 @@ -insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) +insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) VALUES (2, 'test-user2', 'example.com', 'Im test user.', 'THis account is test user.', - '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user2/inbox', 'https://example.com/users/test-user2/outbox', 'https://example.com/users/test-user2', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt index b46c377d..fd2e28e3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt @@ -12,7 +12,6 @@ data class Actor private constructor( val domain: String, val screenName: String, val description: String, - val password: String? = null, val inbox: String, val outbox: String, val url: String, @@ -24,11 +23,7 @@ data class Actor private constructor( val following: String? = null, val instance: Long? = null ) { - override fun toString(): String = - "User(id=$id, name='$name', domain='$domain', screenName='$screenName', description='$description'," + - " password=$password, inbox='$inbox', outbox='$outbox', url='$url', publicKey='$publicKey', " + - "privateKey=$privateKey, createdAt=$createdAt, keyId='$keyId', followers=$followers," + - " following=$following, instance=$instance)" + @Component class UserBuilder(private val characterLimit: CharacterLimit, private val applicationConfig: ApplicationConfig) { @@ -42,7 +37,6 @@ data class Actor private constructor( domain: String, screenName: String, description: String, - password: String? = null, inbox: String, outbox: String, url: String, @@ -97,7 +91,6 @@ data class Actor private constructor( // ローカルユーザーはpasswordとprivateKeyをnullにしてはいけない if (domain == applicationConfig.url.host) { - requireNotNull(password) { "password and privateKey must not be null for local users." } requireNotNull(privateKey) { "password and privateKey must not be null for local users." } } @@ -135,7 +128,6 @@ data class Actor private constructor( domain = domain, screenName = limitedScreenName, description = limitedDescription, - password = password, inbox = inbox, outbox = outbox, url = url, @@ -149,4 +141,24 @@ data class Actor private constructor( ) } } + + override fun toString(): String { + return "Actor(" + + "id=$id, " + + "name='$name', " + + "domain='$domain', " + + "screenName='$screenName', " + + "description='$description', " + + "inbox='$inbox', " + + "outbox='$outbox', " + + "url='$url', " + + "publicKey='$publicKey', " + + "privateKey=$privateKey, " + + "createdAt=$createdAt, " + + "keyId='$keyId', " + + "followers=$followers, " + + "following=$following, " + + "instance=$instance" + + ")" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt new file mode 100644 index 00000000..f4062917 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt @@ -0,0 +1,8 @@ +package dev.usbharu.hideout.core.domain.model.userdetails + +data class UserDetail( + val actorId: Long, + val password: String, + val autoAcceptFollowRequest: Boolean, + val autoAcceptFolloweeFollowRequest: Boolean +) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetailRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetailRepository.kt new file mode 100644 index 00000000..01041ae2 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetailRepository.kt @@ -0,0 +1,7 @@ +package dev.usbharu.hideout.core.domain.model.userdetails + +interface UserDetailRepository { + suspend fun save(userDetail: UserDetail): UserDetail + suspend fun delete(userDetail: UserDetail) + suspend fun findByActorId(actorId: Long): UserDetail? +} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/UserResultRowMapper.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/UserResultRowMapper.kt index a6cdd816..01958b82 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/UserResultRowMapper.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/UserResultRowMapper.kt @@ -16,7 +16,6 @@ class UserResultRowMapper(private val actorBuilder: Actor.UserBuilder) : ResultR domain = resultRow[Actors.domain], screenName = resultRow[Actors.screenName], description = resultRow[Actors.description], - password = resultRow[Actors.password], inbox = resultRow[Actors.inbox], outbox = resultRow[Actors.outbox], url = resultRow[Actors.url], diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt index d5988971..81625cd1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt @@ -24,7 +24,6 @@ class ActorRepositoryImpl( it[domain] = actor.domain it[screenName] = actor.screenName it[description] = actor.description - it[password] = actor.password it[inbox] = actor.inbox it[outbox] = actor.outbox it[url] = actor.url @@ -42,7 +41,6 @@ class ActorRepositoryImpl( it[domain] = actor.domain it[screenName] = actor.screenName it[description] = actor.description - it[password] = actor.password it[inbox] = actor.inbox it[outbox] = actor.outbox it[url] = actor.url @@ -68,7 +66,7 @@ class ActorRepositoryImpl( override suspend fun nextId(): Long = idGenerateService.generateId() } -object Actors : Table("users") { +object Actors : Table("actors") { val id: Column = long("id") val name: Column = varchar("name", length = 300) val domain: Column = varchar("domain", length = 1000) @@ -77,7 +75,6 @@ object Actors : Table("users") { "description", length = 10000 ) - val password: Column = varchar("password", length = 255).nullable() val inbox: Column = varchar("inbox", length = 1000).uniqueIndex() val outbox: Column = varchar("outbox", length = 1000).uniqueIndex() val url: Column = varchar("url", length = 1000).uniqueIndex() diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt index a2b3c186..f8b36460 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt @@ -22,7 +22,7 @@ class ExposedTimelineRepository(private val idGenerateService: IdGenerateService it[userId] = timeline.userId it[timelineId] = timeline.timelineId it[postId] = timeline.postId - it[postUserId] = timeline.postActorId + it[postActorId] = timeline.postActorId it[createdAt] = timeline.createdAt it[replyId] = timeline.replyId it[repostId] = timeline.repostId @@ -37,7 +37,7 @@ class ExposedTimelineRepository(private val idGenerateService: IdGenerateService it[userId] = timeline.userId it[timelineId] = timeline.timelineId it[postId] = timeline.postId - it[postUserId] = timeline.postActorId + it[postActorId] = timeline.postActorId it[createdAt] = timeline.createdAt it[replyId] = timeline.replyId it[repostId] = timeline.repostId @@ -57,7 +57,7 @@ class ExposedTimelineRepository(private val idGenerateService: IdGenerateService this[Timelines.userId] = it.userId this[Timelines.timelineId] = it.timelineId this[Timelines.postId] = it.postId - this[Timelines.postUserId] = it.postActorId + this[Timelines.postActorId] = it.postActorId this[Timelines.createdAt] = it.createdAt this[Timelines.replyId] = it.replyId this[Timelines.repostId] = it.repostId @@ -84,7 +84,7 @@ fun ResultRow.toTimeline(): Timeline { userId = this[Timelines.userId], timelineId = this[Timelines.timelineId], postId = this[Timelines.postId], - postActorId = this[Timelines.postUserId], + postActorId = this[Timelines.postActorId], createdAt = this[Timelines.createdAt], replyId = this[Timelines.replyId], repostId = this[Timelines.repostId], @@ -101,7 +101,7 @@ object Timelines : Table("timelines") { val userId = long("user_id") val timelineId = long("timeline_id") val postId = long("post_id") - val postUserId = long("post_user_id") + val postActorId = long("post_actor_id") val createdAt = long("created_at") val replyId = long("reply_id").nullable() val repostId = long("repost_id").nullable() diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt new file mode 100644 index 00000000..10e52cf8 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt @@ -0,0 +1,60 @@ +package dev.usbharu.hideout.core.infrastructure.exposedrepository + +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository +import org.jetbrains.exposed.dao.id.LongIdTable +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.deleteWhere +import org.jetbrains.exposed.sql.insert +import org.jetbrains.exposed.sql.select +import org.jetbrains.exposed.sql.update +import org.springframework.stereotype.Repository + +@Repository +class UserDetailRepositoryImpl : UserDetailRepository { + override suspend fun save(userDetail: UserDetail): UserDetail { + val singleOrNull = UserDetails.select { UserDetails.actorId eq userDetail.actorId }.singleOrNull() + if (singleOrNull == null) { + UserDetails.insert { + it[actorId] = userDetail.actorId + it[password] = userDetail.password + it[autoAcceptFollowRequest] = userDetail.autoAcceptFollowRequest + it[autoAcceptFolloweeFollowRequest] = userDetail.autoAcceptFolloweeFollowRequest + } + } else { + UserDetails.update({ UserDetails.actorId eq userDetail.actorId }) { + it[password] = userDetail.password + it[autoAcceptFollowRequest] = userDetail.autoAcceptFollowRequest + it[autoAcceptFolloweeFollowRequest] = userDetail.autoAcceptFolloweeFollowRequest + } + } + return userDetail + } + + override suspend fun delete(userDetail: UserDetail) { + UserDetails.deleteWhere { UserDetails.actorId eq userDetail.actorId } + } + + override suspend fun findByActorId(actorId: Long): UserDetail? { + return UserDetails + .select { UserDetails.actorId eq actorId } + .singleOrNull() + ?.let { + UserDetail( + it[UserDetails.actorId], + it[UserDetails.password], + it[UserDetails.autoAcceptFollowRequest], + it[UserDetails.autoAcceptFolloweeFollowRequest] + ) + } + } + +} + + +object UserDetails : LongIdTable("user_details") { + val actorId = long("actor_id").references(Actors.id) + val password = varchar("password", 255) + val autoAcceptFollowRequest = bool("auto_accept_follow_request") + val autoAcceptFolloweeFollowRequest = bool("auto_accept_followee_follow_request") +} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt index 7a6fa0ba..ddb289cb 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt @@ -2,6 +2,8 @@ package dev.usbharu.hideout.core.infrastructure.springframework.oauth2 import dev.usbharu.hideout.application.config.ApplicationConfig import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import dev.usbharu.hideout.core.query.ActorQueryService import kotlinx.coroutines.runBlocking import org.springframework.security.core.userdetails.UserDetails @@ -13,6 +15,7 @@ import org.springframework.stereotype.Service class UserDetailsServiceImpl( private val actorQueryService: ActorQueryService, private val applicationConfig: ApplicationConfig, + private val userDetailRepository: UserDetailRepository, private val transaction: Transaction ) : UserDetailsService { @@ -21,11 +24,17 @@ class UserDetailsServiceImpl( throw UsernameNotFoundException("$username not found") } transaction.transaction { - val findById = actorQueryService.findByNameAndDomain(username, applicationConfig.url.host) + val findById = try { + actorQueryService.findByNameAndDomain(username, applicationConfig.url.host) + } catch (e: FailedToGetResourcesException) { + throw UsernameNotFoundException("$username not found") + } + val userDetails = userDetailRepository.findByActorId(findById.id) + ?: throw UsernameNotFoundException("${findById.id} not found.") UserDetailsImpl( id = findById.id, username = findById.name, - password = findById.password, + password = userDetails.password, enabled = true, accountNonExpired = true, credentialsNonExpired = true, diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt index aa7b0f48..49ff8091 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt @@ -3,6 +3,8 @@ package dev.usbharu.hideout.core.service.user import dev.usbharu.hideout.application.config.ApplicationConfig import dev.usbharu.hideout.core.domain.model.actor.Actor import dev.usbharu.hideout.core.domain.model.actor.ActorRepository +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import dev.usbharu.hideout.core.query.ActorQueryService import dev.usbharu.hideout.core.service.instance.InstanceService import org.jetbrains.exposed.exceptions.ExposedSQLException @@ -18,7 +20,8 @@ class UserServiceImpl( private val actorQueryService: ActorQueryService, private val actorBuilder: Actor.UserBuilder, private val applicationConfig: ApplicationConfig, - private val instanceService: InstanceService + private val instanceService: InstanceService, + private val userDetailRepository: UserDetailRepository ) : UserService { @@ -38,7 +41,6 @@ class UserServiceImpl( domain = applicationConfig.url.host, screenName = user.screenName, description = user.description, - password = hashedPassword, inbox = "$userUrl/inbox", outbox = "$userUrl/outbox", url = userUrl, @@ -49,7 +51,9 @@ class UserServiceImpl( followers = "$userUrl/followers", keyId = "$userUrl#pubkey" ) - return actorRepository.save(userEntity) + val save = actorRepository.save(userEntity) + userDetailRepository.save(UserDetail(nextId, hashedPassword, true, true)) + return save } @Transactional diff --git a/src/main/resources/db/migration/V1__Init_DB.sql b/src/main/resources/db/migration/V1__Init_DB.sql index d1c00d0e..57aa0d35 100644 --- a/src/main/resources/db/migration/V1__Init_DB.sql +++ b/src/main/resources/db/migration/V1__Init_DB.sql @@ -38,7 +38,7 @@ create table if not exists user_details ( id bigserial primary key, actor_id bigint not null unique, - password varchar(255) null, + password varchar(255) not null, auto_accept_follow_request boolean not null, auto_accept_followee_follow_request boolean not null, constraint fk_user_details_actor_id__id foreign key (actor_id) references actors (id) on delete restrict on update restrict diff --git a/src/test/kotlin/utils/UserBuilder.kt b/src/test/kotlin/utils/UserBuilder.kt index c22fa9a7..c496eed8 100644 --- a/src/test/kotlin/utils/UserBuilder.kt +++ b/src/test/kotlin/utils/UserBuilder.kt @@ -36,7 +36,6 @@ object UserBuilder { domain = domain, screenName = screenName, description = description, - password = password, inbox = inbox, outbox = outbox, url = url, @@ -70,7 +69,6 @@ object UserBuilder { domain = domain, screenName = screenName, description = description, - password = null, inbox = inbox, outbox = outbox, url = url,