From 2490f2749e085597c6188e600e5df25eca76d5c9 Mon Sep 17 00:00:00 2001 From: Shashank Verma Date: Mon, 18 Sep 2023 12:29:26 +0530 Subject: [PATCH] service: Apply ktlint fixes Signed-off-by: Shashank Verma --- .../com/mnnit/moticlubs/OpenAPIDefinition.kt | 6 +- .../moticlubs/controller/ChannelController.kt | 28 ++++++--- .../moticlubs/controller/ClubController.kt | 19 ++++-- .../moticlubs/controller/PostController.kt | 26 ++++++-- .../moticlubs/controller/ReplyController.kt | 18 +++++- .../controller/SuperAdminController.kt | 10 +++- .../moticlubs/controller/UrlController.kt | 19 ++++-- .../moticlubs/controller/UserController.kt | 22 +++++-- .../moticlubs/controller/ViewController.kt | 7 ++- .../moticlubs/repository/AdminRepository.kt | 10 ++-- .../moticlubs/repository/ChannelRepository.kt | 23 +++++--- .../moticlubs/repository/ClubRepository.kt | 22 +++---- .../moticlubs/repository/FCMRepository.kt | 4 +- .../moticlubs/repository/MemberRepository.kt | 12 ++-- .../moticlubs/repository/PostRepository.kt | 18 +++--- .../moticlubs/repository/ReplyRepository.kt | 8 +-- .../repository/SuperAdminRepository.kt | 2 +- .../moticlubs/repository/UrlRepository.kt | 5 +- .../moticlubs/repository/UserRepository.kt | 12 ++-- .../moticlubs/repository/ViewRepository.kt | 8 +-- .../mnnit/moticlubs/service/ChannelService.kt | 4 +- .../mnnit/moticlubs/service/ClubService.kt | 2 +- .../moticlubs/service/NotificationService.kt | 59 ++++++++++++------- .../com/mnnit/moticlubs/service/UrlService.kt | 2 +- .../mnnit/moticlubs/service/UserService.kt | 9 ++- .../mnnit/moticlubs/utils/GlobalExceptions.kt | 4 +- .../kotlin/com/mnnit/moticlubs/utils/Utils.kt | 23 ++++---- .../web/config/FirebaseConfiguration.kt | 2 +- .../web/security/AuthenticationToken.kt | 2 +- .../moticlubs/web/security/KeyProvider.kt | 8 +-- .../web/security/PathAuthorization.kt | 2 - .../moticlubs/web/security/SecurityConfig.kt | 48 ++++++++------- .../MotiClubsServiceApplicationTests.kt | 3 +- 33 files changed, 283 insertions(+), 164 deletions(-) diff --git a/src/main/kotlin/com/mnnit/moticlubs/OpenAPIDefinition.kt b/src/main/kotlin/com/mnnit/moticlubs/OpenAPIDefinition.kt index d42b88d..3c2c040 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/OpenAPIDefinition.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/OpenAPIDefinition.kt @@ -11,7 +11,7 @@ import io.swagger.v3.oas.annotations.servers.Server @SecurityScheme( type = SecuritySchemeType.HTTP, name = "Firebase Auth", - scheme = "Bearer" + scheme = "Bearer", ) @OpenAPIDefinition( info = Info( @@ -20,7 +20,7 @@ import io.swagger.v3.oas.annotations.servers.Server contact = Contact( name = "CC-Club MNNIT", url = "https://github.com/CC-MNNIT", - email = "computer.club@mnnit.ac.in" + email = "computer.club@mnnit.ac.in", ), ), servers = [ @@ -33,6 +33,6 @@ import io.swagger.v3.oas.annotations.servers.Server description = "Production", ), ], - security = [SecurityRequirement(name = "Firebase Auth")] + security = [SecurityRequirement(name = "Firebase Auth")], ) class OpenAPIDefinition diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/ChannelController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/ChannelController.kt index 75b8d96..213bc6e 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/ChannelController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/ChannelController.kt @@ -6,15 +6,29 @@ import com.mnnit.moticlubs.dto.request.MembersDTO import com.mnnit.moticlubs.dto.request.UpdateChannelDTO import com.mnnit.moticlubs.service.ChannelService import com.mnnit.moticlubs.service.MemberService -import com.mnnit.moticlubs.utils.* +import com.mnnit.moticlubs.utils.Constants import com.mnnit.moticlubs.utils.Constants.BASE_PATH import com.mnnit.moticlubs.utils.Constants.CHANNEL_ID_CLAIM import com.mnnit.moticlubs.utils.Constants.CHANNEL_ROUTE +import com.mnnit.moticlubs.utils.ResponseStamp +import com.mnnit.moticlubs.utils.ServiceLogger +import com.mnnit.moticlubs.utils.apiWrapper +import com.mnnit.moticlubs.utils.invalidateStamp +import com.mnnit.moticlubs.utils.wrapError import com.mnnit.moticlubs.web.security.PathAuthorization import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestHeader +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono @RestController @@ -41,7 +55,7 @@ class ChannelController( serviceCall = { uid -> LOGGER.info("getAllChannels") channelService.getAllChannels(uid) - } + }, ) @GetMapping("/{$CHANNEL_ID_CLAIM}") @@ -56,7 +70,7 @@ class ChannelController( serviceCall = { uid -> LOGGER.info("getChannelFromChid: chid: $channelId") channelService.getChannelByChID(uid, channelId) - } + }, ) @GetMapping("/members/{${CHANNEL_ID_CLAIM}}") @@ -71,7 +85,7 @@ class ChannelController( serviceCall = { LOGGER.info("getMembers: chid: $channelId") memberService.getMembersByChid(channelId) - } + }, ) @PostMapping("/members") @@ -115,7 +129,7 @@ class ChannelController( @Operation(summary = "Updates the name of channel") fun updateChannel( @RequestBody dto: UpdateChannelDTO, - @PathVariable channelId: Long + @PathVariable channelId: Long, ): Mono> = pathAuthorization .clubAuthorization(dto.cid) .flatMap { @@ -129,7 +143,7 @@ class ChannelController( @Operation(summary = "Deletes the channel and the posts in it") fun deleteChannel( @RequestParam clubId: Long, - @PathVariable channelId: Long + @PathVariable channelId: Long, ): Mono> = pathAuthorization .clubAuthorization(clubId) .flatMap { diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/ClubController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/ClubController.kt index 859412c..336e28b 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/ClubController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/ClubController.kt @@ -3,15 +3,26 @@ package com.mnnit.moticlubs.controller import com.mnnit.moticlubs.dao.Club import com.mnnit.moticlubs.dto.request.UpdateClubDTO import com.mnnit.moticlubs.service.ClubService -import com.mnnit.moticlubs.utils.* +import com.mnnit.moticlubs.utils.Constants import com.mnnit.moticlubs.utils.Constants.BASE_PATH import com.mnnit.moticlubs.utils.Constants.CLUBS_ROUTE import com.mnnit.moticlubs.utils.Constants.CLUB_ID_CLAIM +import com.mnnit.moticlubs.utils.ResponseStamp +import com.mnnit.moticlubs.utils.ServiceLogger +import com.mnnit.moticlubs.utils.apiWrapper +import com.mnnit.moticlubs.utils.invalidateStamp +import com.mnnit.moticlubs.utils.wrapError import com.mnnit.moticlubs.web.security.PathAuthorization import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestHeader +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono @RestController @@ -37,14 +48,14 @@ class ClubController( serviceCall = { LOGGER.info("getClubs") clubService.getAllClubs() - } + }, ) @PutMapping("/{$CLUB_ID_CLAIM}") @Operation(summary = "Updates club avatar, description and summary") fun updateClub( @RequestBody dto: UpdateClubDTO, - @PathVariable clubId: Long + @PathVariable clubId: Long, ): Mono> = pathAuthorization .clubAuthorization(clubId) .flatMap { diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/PostController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/PostController.kt index 69f9111..b1b471b 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/PostController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/PostController.kt @@ -3,16 +3,30 @@ package com.mnnit.moticlubs.controller import com.mnnit.moticlubs.dao.Post import com.mnnit.moticlubs.dto.request.UpdatePostDTO import com.mnnit.moticlubs.service.PostService -import com.mnnit.moticlubs.utils.* +import com.mnnit.moticlubs.utils.Constants import com.mnnit.moticlubs.utils.Constants.BASE_PATH import com.mnnit.moticlubs.utils.Constants.POSTS_ROUTE import com.mnnit.moticlubs.utils.Constants.POST_ID_CLAIM +import com.mnnit.moticlubs.utils.ResponseStamp +import com.mnnit.moticlubs.utils.ServiceLogger +import com.mnnit.moticlubs.utils.apiWrapper +import com.mnnit.moticlubs.utils.invalidateStamp +import com.mnnit.moticlubs.utils.wrapError import com.mnnit.moticlubs.web.security.PathAuthorization import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.data.domain.PageRequest import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestHeader +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono @RestController @@ -41,14 +55,14 @@ class PostController( serviceCall = { LOGGER.info("getPostsByChannel: chid: $channelId; page: $page; items: $items") postService.getPostsByChannel(channelId, PageRequest.of(maxOf(page - 1, 0), items)) - } + }, ) @PostMapping @Operation(summary = "Saves post and notify users") fun savePost( @RequestBody post: Post, - @RequestParam clubId: Long + @RequestParam clubId: Long, ): Mono> = pathAuthorization .clubAuthorization(clubId) .flatMap { @@ -63,7 +77,7 @@ class PostController( fun updatePost( @RequestBody dto: UpdatePostDTO, @PathVariable postId: Long, - @RequestParam clubId: Long + @RequestParam clubId: Long, ): Mono> = pathAuthorization .clubAuthorization(clubId) .flatMap { @@ -77,7 +91,7 @@ class PostController( @Operation(summary = "Deletes post") fun deletePost( @PathVariable postId: Long, - @RequestParam clubId: Long + @RequestParam clubId: Long, ): Mono> = pathAuthorization .clubAuthorization(clubId) .flatMap { diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/ReplyController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/ReplyController.kt index d3e3e1d..2952592 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/ReplyController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/ReplyController.kt @@ -2,15 +2,27 @@ package com.mnnit.moticlubs.controller import com.mnnit.moticlubs.dao.Reply import com.mnnit.moticlubs.service.ReplyService -import com.mnnit.moticlubs.utils.* +import com.mnnit.moticlubs.utils.Constants import com.mnnit.moticlubs.utils.Constants.BASE_PATH import com.mnnit.moticlubs.utils.Constants.REPLY_ROUTE +import com.mnnit.moticlubs.utils.ResponseStamp +import com.mnnit.moticlubs.utils.ServiceLogger +import com.mnnit.moticlubs.utils.apiWrapper +import com.mnnit.moticlubs.utils.invalidateStamp +import com.mnnit.moticlubs.utils.wrapError import com.mnnit.moticlubs.web.security.PathAuthorization import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.data.domain.PageRequest import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestHeader +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono @RestController @@ -39,7 +51,7 @@ class ReplyController( serviceCall = { LOGGER.info("getReplies: pid: $postId; page: $page; items: $items") replyService.getRepliesByPid(postId, PageRequest.of(maxOf(page - 1, 0), items)) - } + }, ) @PostMapping diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/SuperAdminController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/SuperAdminController.kt index a6a20a0..d4e235a 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/SuperAdminController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/SuperAdminController.kt @@ -17,7 +17,13 @@ import com.mnnit.moticlubs.web.security.PathAuthorization import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono @RestController @@ -54,7 +60,7 @@ class SuperAdminController( name = dto.name, description = dto.description, summary = dto.summary, - ) + ), ) } .invalidateStamp { ResponseStamp.CLUB } diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/UrlController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/UrlController.kt index 990598b..ec8db6d 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/UrlController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/UrlController.kt @@ -3,14 +3,25 @@ package com.mnnit.moticlubs.controller import com.mnnit.moticlubs.dao.Url import com.mnnit.moticlubs.dto.request.SaveUrlsDTO import com.mnnit.moticlubs.service.UrlService -import com.mnnit.moticlubs.utils.* +import com.mnnit.moticlubs.utils.Constants import com.mnnit.moticlubs.utils.Constants.BASE_PATH import com.mnnit.moticlubs.utils.Constants.URL_ROUTE +import com.mnnit.moticlubs.utils.ResponseStamp +import com.mnnit.moticlubs.utils.ServiceLogger +import com.mnnit.moticlubs.utils.apiWrapper +import com.mnnit.moticlubs.utils.invalidateStamp +import com.mnnit.moticlubs.utils.wrapError import com.mnnit.moticlubs.web.security.PathAuthorization import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestHeader +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono @RestController @@ -37,7 +48,7 @@ class UrlController( serviceCall = { LOGGER.info("getUrls: cid: $clubId") urlService.getUrlsByCid(clubId) - } + }, ) @PostMapping @@ -49,7 +60,7 @@ class UrlController( LOGGER.info("updateUrls: cid: $clubId") urlService.saveUrl( clubId, - dto.urls.map { url -> Url(url.urlid, clubId, url.name, url.color, url.url) } + dto.urls.map { url -> Url(url.urlid, clubId, url.name, url.color, url.url) }, ) } .invalidateStamp { ResponseStamp.URL.withKey("$clubId") } diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/UserController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/UserController.kt index 8f8f2fc..c4753ed 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/UserController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/UserController.kt @@ -8,18 +8,28 @@ import com.mnnit.moticlubs.dto.request.UpdateContactDTO import com.mnnit.moticlubs.dto.response.AdminUserDTO import com.mnnit.moticlubs.service.FCMService import com.mnnit.moticlubs.service.UserService -import com.mnnit.moticlubs.utils.* import com.mnnit.moticlubs.utils.Constants.BASE_PATH import com.mnnit.moticlubs.utils.Constants.STAMP_HEADER import com.mnnit.moticlubs.utils.Constants.USER_ID_CLAIM import com.mnnit.moticlubs.utils.Constants.USER_ROUTE +import com.mnnit.moticlubs.utils.ResponseStamp import com.mnnit.moticlubs.utils.ResponseStamp.invalidateStamp +import com.mnnit.moticlubs.utils.ServiceLogger +import com.mnnit.moticlubs.utils.apiWrapper +import com.mnnit.moticlubs.utils.invalidateStamp +import com.mnnit.moticlubs.utils.wrapError import com.mnnit.moticlubs.web.security.PathAuthorization import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity import org.springframework.http.server.reactive.ServerHttpRequest -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestHeader +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono @RestController @@ -47,7 +57,7 @@ class UserController( serviceCall = { LOGGER.info("getSelf: uid: $it, ${serverRequest.path.value()}") userService.getUserByUid(it) - } + }, ) @GetMapping("/{$USER_ID_CLAIM}") @@ -62,7 +72,7 @@ class UserController( serviceCall = { LOGGER.info("getUser: uid: $userId") userService.getUserByUid(userId) - } + }, ) @GetMapping("/all") @@ -76,7 +86,7 @@ class UserController( serviceCall = { LOGGER.info("getAll") userService.getAllUsers() - } + }, ) @GetMapping("/admins") @@ -90,7 +100,7 @@ class UserController( serviceCall = { LOGGER.info("getAdmins") userService.getAllAdminUsers() - } + }, ) @PostMapping diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/ViewController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/ViewController.kt index c4df039..44435e6 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/ViewController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/ViewController.kt @@ -9,7 +9,12 @@ import com.mnnit.moticlubs.utils.wrapError import com.mnnit.moticlubs.web.security.PathAuthorization import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono @RestController diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/AdminRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/AdminRepository.kt index 95e8aa2..de6d181 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/AdminRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/AdminRepository.kt @@ -29,7 +29,7 @@ class AdminRepository( .map { AdminUserDTO( clubId = it[Admin::cid.name].toString().toLong(), - user = User(it) + user = User(it), ) } @@ -37,7 +37,7 @@ class AdminRepository( fun findAllByCid(cid: Long): Flux = db .select( Query.query(Criteria.where(Admin::cid.name).`is`(cid)), - Admin::class.java + Admin::class.java, ) @Transactional @@ -48,10 +48,10 @@ class AdminRepository( .where(Admin::cid.name) .`is`(admin.cid) .and( - Criteria.where(Admin::uid.name).`is`(admin.uid) - ) + Criteria.where(Admin::uid.name).`is`(admin.uid), + ), ), - Admin::class.java + Admin::class.java, ) @Transactional diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/ChannelRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/ChannelRepository.kt index c189d65..342c70e 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/ChannelRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/ChannelRepository.kt @@ -23,7 +23,10 @@ class ChannelRepository( @Transactional fun findAll(uid: Long): Flux = db .databaseClient - .sql("SELECT channel.* FROM channel INNER JOIN member ON channel.chid = member.chid WHERE uid = :uid UNION (SELECT * FROM channel WHERE private = 0) ORDER BY chid") + .sql( + "SELECT channel.* FROM channel INNER JOIN member ON channel.chid = member.chid " + + "WHERE uid = :uid UNION (SELECT * FROM channel WHERE private = 0) ORDER BY chid", + ) .bind(0, uid) .fetch() .all() @@ -33,25 +36,27 @@ class ChannelRepository( fun findById(chid: Long): Mono = db .selectOne( Query.query(Criteria.where(Channel::chid.name).`is`(chid)).limit(1), - Channel::class.java + Channel::class.java, ) @Transactional fun findByCid(cid: Long): Flux = db .select( Query.query(Criteria.where(Channel::cid.name).`is`(cid)), - Channel::class.java + Channel::class.java, ) @Transactional fun update(chid: Long, dto: UpdateChannelDTO): Mono = db .update( Query.query(Criteria.where(Channel::chid.name).`is`(chid)), - Update.from(HashMap().apply { - this[SqlIdentifier.unquoted(Channel::name.name)] = dto.name - this[SqlIdentifier.unquoted(Channel::private.name)] = if (dto.private) 1 else 0 - }), - Channel::class.java + Update.from( + HashMap().apply { + this[SqlIdentifier.unquoted(Channel::name.name)] = dto.name + this[SqlIdentifier.unquoted(Channel::private.name)] = if (dto.private) 1 else 0 + }, + ), + Channel::class.java, ) .flatMap { findById(chid) } @@ -59,7 +64,7 @@ class ChannelRepository( fun deleteById(chid: Long): Mono = db .delete( Query.query(Criteria.where(Channel::chid.name).`is`(chid)), - Channel::class.java + Channel::class.java, ) .then() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/ClubRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/ClubRepository.kt index 5bf34f4..63aa793 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/ClubRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/ClubRepository.kt @@ -24,26 +24,28 @@ class ClubRepository( @Transactional fun findAll(): Flux = db.select( Query.empty().sort(Sort.by(Sort.Direction.ASC, Club::cid.name)), - Club::class.java + Club::class.java, ) @Transactional fun findById(cid: Long): Mono = db .selectOne( Query.query(Criteria.where(Club::cid.name).`is`(cid)).limit(1), - Club::class.java + Club::class.java, ) @Transactional fun updateClub(cid: Long, dto: UpdateClubDTO): Mono = db .update( Query.query(Criteria.where(Club::cid.name).`is`(cid)), - Update.from(HashMap().apply { - this[SqlIdentifier.unquoted(Club::description.name)] = dto.description - this[SqlIdentifier.unquoted(Club::avatar.name)] = dto.avatar - this[SqlIdentifier.unquoted(Club::summary.name)] = dto.summary - }), - Club::class.java + Update.from( + HashMap().apply { + this[SqlIdentifier.unquoted(Club::description.name)] = dto.description + this[SqlIdentifier.unquoted(Club::avatar.name)] = dto.avatar + this[SqlIdentifier.unquoted(Club::summary.name)] = dto.summary + }, + ), + Club::class.java, ) .flatMap { findById(cid) } @@ -51,14 +53,14 @@ class ClubRepository( fun existsById(cid: Long): Mono = db .exists( Query.query(Criteria.where(Club::cid.name).`is`(cid)), - Club::class.java + Club::class.java, ) @Transactional fun deleteById(cid: Long): Mono = db .delete( Query.query(Criteria.where(Club::cid.name).`is`(cid)), - Club::class.java + Club::class.java, ) .then() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/FCMRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/FCMRepository.kt index 6f9c18e..87ad176 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/FCMRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/FCMRepository.kt @@ -22,7 +22,7 @@ class FCMRepository( fun findById(uid: Long): Mono = db .selectOne( Query.query(Criteria.where(FCM::uid.name).`is`(uid)).limit(1), - FCM::class.java + FCM::class.java, ) @Transactional @@ -32,7 +32,7 @@ class FCMRepository( fun exists(fcm: FCM): Mono = db .exists( Query.query(Criteria.where(FCM::uid.name).`is`(fcm.uid)), - FCM::class.java + FCM::class.java, ) @Transactional diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/MemberRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/MemberRepository.kt index 7f4301d..6473fae 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/MemberRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/MemberRepository.kt @@ -22,7 +22,7 @@ class MemberRepository( fun findAllByChid(chid: Long): Flux = db .select( Query.query(Criteria.where(Member::chid.name).`is`(chid)), - Member::class.java + Member::class.java, ) @Transactional @@ -32,10 +32,10 @@ class MemberRepository( Criteria .where(Member::chid.name).`is`(member.chid) .and( - Criteria.where(Member::uid.name).`is`(member.uid) - ) + Criteria.where(Member::uid.name).`is`(member.uid), + ), ), - Member::class.java + Member::class.java, ) @Transactional @@ -47,7 +47,7 @@ class MemberRepository( fun deleteAllByUid(uid: Long): Mono = db .delete( Query.query(Criteria.where(Member::uid.name).`is`(uid)), - Member::class.java + Member::class.java, ) .then() @@ -55,7 +55,7 @@ class MemberRepository( fun deleteAllByChid(chid: Long): Mono = db .delete( Query.query(Criteria.where(Member::chid.name).`is`(chid)), - Member::class.java + Member::class.java, ) .then() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/PostRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/PostRepository.kt index 574415b..72c5676 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/PostRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/PostRepository.kt @@ -26,7 +26,7 @@ class PostRepository( fun findById(pid: Long): Mono = db .selectOne( Query.query(Criteria.where(Post::pid.name).`is`(pid)).limit(1), - Post::class.java + Post::class.java, ) @Transactional @@ -36,18 +36,20 @@ class PostRepository( .sort(Sort.by(Sort.Direction.DESC, Post::updated.name)) .limit(pageRequest.pageSize) .offset(pageRequest.offset), - Post::class.java + Post::class.java, ) @Transactional fun updatePost(pid: Long, dto: UpdatePostDTO): Mono = db .update( Query.query(Criteria.where(Post::pid.name).`is`(pid)), - Update.from(HashMap().apply { - this[SqlIdentifier.unquoted(Post::message.name)] = dto.message - this[SqlIdentifier.unquoted(Post::updated.name)] = dto.updated - }), - Post::class.java + Update.from( + HashMap().apply { + this[SqlIdentifier.unquoted(Post::message.name)] = dto.message + this[SqlIdentifier.unquoted(Post::updated.name)] = dto.updated + }, + ), + Post::class.java, ) .flatMap { findById(pid) } @@ -55,7 +57,7 @@ class PostRepository( fun deleteById(pid: Long): Mono = db .delete( Query.query(Criteria.where(Post::pid.name).`is`(pid)), - Post::class.java + Post::class.java, ) .then() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/ReplyRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/ReplyRepository.kt index 3af8f63..99f9a9f 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/ReplyRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/ReplyRepository.kt @@ -23,7 +23,7 @@ class ReplyRepository( fun findById(rid: Long): Mono = db .selectOne( Query.query(Criteria.where(Reply::time.name).`is`(rid)).limit(1), - Reply::class.java + Reply::class.java, ) @Transactional @@ -33,14 +33,14 @@ class ReplyRepository( .sort(Sort.by(Sort.Direction.DESC, Reply::time.name)) .limit(pageRequest.pageSize) .offset(pageRequest.offset), - Reply::class.java + Reply::class.java, ) @Transactional fun findUidByPid(pid: Long): Flux = db .select( Query.query(Criteria.where(Reply::pid.name).`is`(pid)), - Reply::class.java + Reply::class.java, ) .map { it.uid } @@ -48,7 +48,7 @@ class ReplyRepository( fun deleteById(rid: Long): Mono = db .delete( Query.query(Criteria.where(Reply::time.name).`is`(rid)), - Reply::class.java + Reply::class.java, ) .then() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/SuperAdminRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/SuperAdminRepository.kt index 6944120..ae93e2e 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/SuperAdminRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/SuperAdminRepository.kt @@ -17,6 +17,6 @@ class SuperAdminRepository( fun existsById(uid: Long): Mono = db .exists( Query.query(Criteria.where(SuperAdmin::uid.name).`is`(uid)), - SuperAdmin::class.java + SuperAdmin::class.java, ) } diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/UrlRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/UrlRepository.kt index 4449a2b..5dbb868 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/UrlRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/UrlRepository.kt @@ -18,19 +18,18 @@ class UrlRepository( fun saveAll(list: List): Flux = Flux.fromIterable(list) .concatMap { db.insert(it) } - @Transactional fun findAllByCid(cid: Long): Flux = db .select( Query.query(Criteria.where(Url::cid.name).`is`(cid)), - Url::class.java + Url::class.java, ) @Transactional fun deleteAllByCid(cid: Long): Mono = db .delete( Query.query(Criteria.where(Url::cid.name).`is`(cid)), - Url::class.java + Url::class.java, ) .then() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/UserRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/UserRepository.kt index c05467d..90f645f 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/UserRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/UserRepository.kt @@ -23,7 +23,7 @@ class UserRepository( fun findById(uid: Long): Mono = db .selectOne( Query.query(Criteria.where(User::uid.name).`is`(uid)).limit(1), - User::class.java + User::class.java, ) @Transactional @@ -33,14 +33,14 @@ class UserRepository( fun findByRegNo(regNo: String): Mono = db .selectOne( Query.query(Criteria.where(User::regno.name).`is`(regNo)).limit(1), - User::class.java + User::class.java, ) @Transactional fun exists(user: User): Mono = db .exists( Query.query(Criteria.where(User::email.name).`is`(user.email)), - User::class.java + User::class.java, ) @Transactional @@ -48,7 +48,7 @@ class UserRepository( .update( Query.query(Criteria.where(User::uid.name).`is`(uid)), Update.update(User::avatar.name, avatar), - User::class.java + User::class.java, ) .then(findById(uid)) @@ -57,7 +57,7 @@ class UserRepository( .update( Query.query(Criteria.where(User::uid.name).`is`(uid)), Update.update(User::contact.name, contact), - User::class.java + User::class.java, ) .then(findById(uid)) @@ -65,7 +65,7 @@ class UserRepository( fun deleteById(uid: Long): Mono = db .delete( Query.query(Criteria.where(User::uid.name).`is`(uid)).limit(1), - User::class.java + User::class.java, ) .then() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/ViewRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/ViewRepository.kt index 0a6741b..86be290 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/ViewRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/ViewRepository.kt @@ -22,10 +22,10 @@ class ViewRepository( .where(View::pid.name) .`is`(view.pid) .and( - Criteria.where(View::uid.name).`is`(view.uid) - ) + Criteria.where(View::uid.name).`is`(view.uid), + ), ), - View::class.java + View::class.java, ) .flatMap { if (it) Mono.just(view) else db.insert(view) } @@ -33,6 +33,6 @@ class ViewRepository( fun findAllByPid(pid: Long): Flux = db .select( Query.query(Criteria.where(View::pid.name).`is`(pid)), - View::class.java + View::class.java, ) } diff --git a/src/main/kotlin/com/mnnit/moticlubs/service/ChannelService.kt b/src/main/kotlin/com/mnnit/moticlubs/service/ChannelService.kt index 94f5605..60f5dcd 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/service/ChannelService.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/service/ChannelService.kt @@ -41,7 +41,9 @@ class ChannelService( Mono.error(UnauthorizedException("User is not allowed to view this channel")) } } - } else Mono.just(channel) + } else { + Mono.just(channel) + } } @CacheEvict(cacheNames = ["all_channels", "members"], allEntries = true) diff --git a/src/main/kotlin/com/mnnit/moticlubs/service/ClubService.kt b/src/main/kotlin/com/mnnit/moticlubs/service/ClubService.kt index cd45c02..77a9c12 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/service/ClubService.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/service/ClubService.kt @@ -32,7 +32,7 @@ class ClubService( @CacheEvict( cacheNames = ["all_clubs", "urls", "admins", "all_channels", "members", "post", "replies"], - allEntries = true + allEntries = true, ) fun deleteClubByCid(cid: Long): Mono = clubRepository.deleteById(cid) } diff --git a/src/main/kotlin/com/mnnit/moticlubs/service/NotificationService.kt b/src/main/kotlin/com/mnnit/moticlubs/service/NotificationService.kt index 1916d7e..0518184 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/service/NotificationService.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/service/NotificationService.kt @@ -2,8 +2,19 @@ package com.mnnit.moticlubs.service import com.google.firebase.messaging.FirebaseMessaging import com.google.firebase.messaging.Message -import com.mnnit.moticlubs.dao.* -import com.mnnit.moticlubs.repository.* +import com.mnnit.moticlubs.dao.Channel +import com.mnnit.moticlubs.dao.Club +import com.mnnit.moticlubs.dao.FCM +import com.mnnit.moticlubs.dao.Post +import com.mnnit.moticlubs.dao.Reply +import com.mnnit.moticlubs.dao.User +import com.mnnit.moticlubs.repository.ChannelRepository +import com.mnnit.moticlubs.repository.ClubRepository +import com.mnnit.moticlubs.repository.FCMRepository +import com.mnnit.moticlubs.repository.MemberRepository +import com.mnnit.moticlubs.repository.PostRepository +import com.mnnit.moticlubs.repository.ReplyRepository +import com.mnnit.moticlubs.repository.UserRepository import com.mnnit.moticlubs.utils.ServiceLogger import org.springframework.stereotype.Service import reactor.core.publisher.Mono @@ -40,10 +51,12 @@ class NotificationService( clubRepository.findById(channel.cid) .flatMap { club -> - Mono.just(getPostPayload(post, user, club, channel).apply { - this["type"] = Type.POST.ordinal.toString() - this["updated"] = updated.toString() - }) + Mono.just( + getPostPayload(post, user, club, channel).apply { + this["type"] = Type.POST.ordinal.toString() + this["updated"] = updated.toString() + }, + ) } .flatMap { payload -> if (channel.private) { @@ -58,11 +71,13 @@ class NotificationService( fun notifyDeletePost(post: Post): Mono = Mono.just(post) .flatMap { p -> - Mono.just(HashMap().apply { - this["type"] = Type.DELETE_POST.ordinal.toString() - this["pid"] = p.pid.toString() - this["chid"] = p.chid.toString() - }) + Mono.just( + HashMap().apply { + this["type"] = Type.DELETE_POST.ordinal.toString() + this["pid"] = p.pid.toString() + this["chid"] = p.chid.toString() + }, + ) }.flatMap { payload -> LOGGER.info("notifyDeletePost: payload: $payload") notifyAll(payload) @@ -89,12 +104,14 @@ class NotificationService( fun notifyDeleteReply(reply: Reply): Mono = postRepository.findById(reply.pid) .flatMap { post -> - Mono.just(HashMap().apply { - this["type"] = Type.DELETE_REPLY.ordinal.toString() - this["pid"] = reply.pid.toString() - this["chid"] = post.chid.toString() - this["time"] = reply.time.toString() - }) + Mono.just( + HashMap().apply { + this["type"] = Type.DELETE_REPLY.ordinal.toString() + this["pid"] = reply.pid.toString() + this["chid"] = post.chid.toString() + this["time"] = reply.time.toString() + }, + ) } .flatMap { payload -> LOGGER.info("notifyDeleteReply: payload: $payload") @@ -132,7 +149,7 @@ class NotificationService( memberRepository.findAllByChid(chid) .flatMap { fcmRepository.findById(it.uid) } .distinct { it.uid } - .flatMap { fcm -> sendNotification(fcm, payload) } + .flatMap { fcm -> sendNotification(fcm, payload) }, ) private fun notifyPostParticipants(pid: Long, payload: HashMap): Mono = Mono @@ -140,7 +157,7 @@ class NotificationService( replyRepository.findUidByPid(pid) .distinct() .flatMap { fcmRepository.findById(it) } - .flatMap { fcm -> sendNotification(fcm, payload) } + .flatMap { fcm -> sendNotification(fcm, payload) }, ) private fun notifyAll(payload: HashMap): Mono = fcmRepository @@ -155,12 +172,12 @@ class NotificationService( Message.builder() .setToken(fcm.token) .putAllData(payload) - .build() + .build(), ) LOGGER.debug("FCM: notification sent: ID: $messageId") } catch (e: Exception) { LOGGER.warn("Unable to send notification to ${fcm.uid}: ${e.localizedMessage}") - } + }, ) .then() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/service/UrlService.kt b/src/main/kotlin/com/mnnit/moticlubs/service/UrlService.kt index 71b909e..babc70d 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/service/UrlService.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/service/UrlService.kt @@ -19,7 +19,7 @@ class UrlService( .then( urlRepository .saveAll(urls) - .collectList() + .collectList(), ) @Cacheable("urls", key = "#cid") diff --git a/src/main/kotlin/com/mnnit/moticlubs/service/UserService.kt b/src/main/kotlin/com/mnnit/moticlubs/service/UserService.kt index 53b6864..7b22417 100755 --- a/src/main/kotlin/com/mnnit/moticlubs/service/UserService.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/service/UserService.kt @@ -28,9 +28,12 @@ class UserService( fcmRepository.save(FCM(savedUser.uid, "")) .flatMap { val record = firebaseAuth.getUserByEmail(savedUser.email) - firebaseAuth.setCustomUserClaims(record.uid, HashMap().apply { - this[USER_ID_CLAIM] = savedUser.uid - }) + firebaseAuth.setCustomUserClaims( + record.uid, + HashMap().apply { + this[USER_ID_CLAIM] = savedUser.uid + }, + ) Mono.just(savedUser) } } diff --git a/src/main/kotlin/com/mnnit/moticlubs/utils/GlobalExceptions.kt b/src/main/kotlin/com/mnnit/moticlubs/utils/GlobalExceptions.kt index 9d8cfee..f7170b7 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/utils/GlobalExceptions.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/utils/GlobalExceptions.kt @@ -7,12 +7,12 @@ class UnauthorizedException( override val message: String, ) : ResponseStatusException( HttpStatus.UNAUTHORIZED, - message + message, ) class CachedException( override val message: String, ) : ResponseStatusException( HttpStatus.NOT_MODIFIED, - message + message, ) diff --git a/src/main/kotlin/com/mnnit/moticlubs/utils/Utils.kt b/src/main/kotlin/com/mnnit/moticlubs/utils/Utils.kt index 2e5225f..9a22fe1 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/utils/Utils.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/utils/Utils.kt @@ -14,11 +14,12 @@ import java.time.Duration fun Mono.wrapError(): Mono = onErrorMap { when (it) { is UnauthorizedException, - is CachedException -> it + is CachedException, + -> it else -> ResponseStatusException( HttpStatus.INTERNAL_SERVER_ERROR, - it.localizedMessage + it.localizedMessage, ) } } @@ -27,7 +28,7 @@ fun apiWrapper( key: ResponseStamp.StampKey, stampValue: Long, authorization: () -> Mono, - serviceCall: (data: Long) -> Mono + serviceCall: (data: Long) -> Mono, ): Mono> = authorization() .flatMap { if (key.validateLast(stampValue)) Mono.empty() else Mono.just(it) } .flatMap { serviceCall(it) } @@ -40,7 +41,7 @@ fun apiWrapper( Mono.just( ResponseEntity.status(HttpStatus.NOT_MODIFIED) .header(Constants.STAMP_HEADER, key.getString(stampValue)) - .build() + .build(), ) } .wrapError() @@ -56,12 +57,14 @@ fun Mono.invalidateStamp( fun Mono.invalidateStamp( getStampKey: () -> ResponseStamp.StampKey, -): Mono> = then(Mono.fromCallable { - val updatedStamp = getStampKey().invalidateStamp() - ResponseEntity.ok() - .header(Constants.STAMP_HEADER, updatedStamp.toString()) - .build() -}) +): Mono> = then( + Mono.fromCallable { + val updatedStamp = getStampKey().invalidateStamp() + ResponseEntity.ok() + .header(Constants.STAMP_HEADER, updatedStamp.toString()) + .build() + }, +) fun Mono.storeCache(): Mono = cache(Duration.ofSeconds(120)) diff --git a/src/main/kotlin/com/mnnit/moticlubs/web/config/FirebaseConfiguration.kt b/src/main/kotlin/com/mnnit/moticlubs/web/config/FirebaseConfiguration.kt index 8a5a2b3..b322c7b 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/web/config/FirebaseConfiguration.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/web/config/FirebaseConfiguration.kt @@ -29,7 +29,7 @@ class FirebaseConfiguration { .initializeApp( FirebaseOptions.builder() .setCredentials(googleCredentials) - .build() + .build(), ) @Bean diff --git a/src/main/kotlin/com/mnnit/moticlubs/web/security/AuthenticationToken.kt b/src/main/kotlin/com/mnnit/moticlubs/web/security/AuthenticationToken.kt index 43f0582..0ec8bf2 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/web/security/AuthenticationToken.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/web/security/AuthenticationToken.kt @@ -3,7 +3,7 @@ package com.mnnit.moticlubs.web.security import com.auth0.jwt.interfaces.DecodedJWT class AuthenticationToken( - private val decodedJWT: DecodedJWT + private val decodedJWT: DecodedJWT, ) { val isEmailVerified diff --git a/src/main/kotlin/com/mnnit/moticlubs/web/security/KeyProvider.kt b/src/main/kotlin/com/mnnit/moticlubs/web/security/KeyProvider.kt index 66cf43b..1e74799 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/web/security/KeyProvider.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/web/security/KeyProvider.kt @@ -27,12 +27,12 @@ import java.util.concurrent.TimeUnit @Service class KeyProvider( private val googleClient: GoogleClient, - private val properties: FirebaseConfiguration.Properties + private val properties: FirebaseConfiguration.Properties, ) { private data class PublicCert( val maxAge: Long, - val publicKeys: Map + val publicKeys: Map, ) companion object { @@ -85,7 +85,7 @@ class KeyProvider( val header = JWTParser().parseHeader( Base64.getUrlDecoder() .decode(jwt.split(".")[0]) - .toString(StandardCharsets.UTF_8) + .toString(StandardCharsets.UTF_8), ) val verifier = cert.publicKeys[header.keyId] @@ -105,7 +105,7 @@ class KeyProvider( publicKey .replace("-----BEGIN CERTIFICATE-----\n", "") .replace("-----END CERTIFICATE-----\n", "") - .replace("\n", "") + .replace("\n", ""), ) val certificate = CertificateFactory.getInstance("X.509") .generateCertificate(ByteArrayInputStream(decode)) as X509Certificate diff --git a/src/main/kotlin/com/mnnit/moticlubs/web/security/PathAuthorization.kt b/src/main/kotlin/com/mnnit/moticlubs/web/security/PathAuthorization.kt index 2798a0e..a1ee1c3 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/web/security/PathAuthorization.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/web/security/PathAuthorization.kt @@ -1,10 +1,8 @@ package com.mnnit.moticlubs.web.security -import com.google.firebase.auth.FirebaseToken import com.mnnit.moticlubs.dao.Admin import com.mnnit.moticlubs.repository.AdminRepository import com.mnnit.moticlubs.repository.SuperAdminRepository -import com.mnnit.moticlubs.utils.Constants.USER_ID_CLAIM import com.mnnit.moticlubs.utils.ServiceLogger import com.mnnit.moticlubs.utils.UnauthorizedException import com.mnnit.moticlubs.utils.getReqId diff --git a/src/main/kotlin/com/mnnit/moticlubs/web/security/SecurityConfig.kt b/src/main/kotlin/com/mnnit/moticlubs/web/security/SecurityConfig.kt index 6c51d00..28ebfd1 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/web/security/SecurityConfig.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/web/security/SecurityConfig.kt @@ -43,24 +43,30 @@ class SecurityConfig( keyProvider: KeyProvider, ): SecurityWebFilterChain = http .csrf { it.disable() } - - // Change context path of service - .addFilterAt({ exchange, chain -> - chain.filter( - exchange.mutate() - .request(exchange.request.mutate().contextPath(contextPath).build()) - .build() - ) - }, SecurityWebFiltersOrder.FIRST) - - // Firebase auth for APIs - .addFilterAt(firebaseAuthTokenFilter(keyProvider), SecurityWebFiltersOrder.AUTHENTICATION) - - // Store requestId for logging and tracing - .addFilterAt({ exchange, chain -> - putReqId(exchange.request.id) - chain.filter(exchange) - }, SecurityWebFiltersOrder.AUTHORIZATION) + .addFilterAt( + // Change context path of service + { exchange, chain -> + chain.filter( + exchange.mutate() + .request(exchange.request.mutate().contextPath(contextPath).build()) + .build(), + ) + }, + SecurityWebFiltersOrder.FIRST, + ) + .addFilterAt( + // Firebase auth for APIs + firebaseAuthTokenFilter(keyProvider), + SecurityWebFiltersOrder.AUTHENTICATION, + ) + .addFilterAt( + // Store requestId for logging and tracing + { exchange, chain -> + putReqId(exchange.request.id) + chain.filter(exchange) + }, + SecurityWebFiltersOrder.AUTHORIZATION, + ) .authorizeExchange { spec -> spec.pathMatchers( "/actuator/**", @@ -76,10 +82,10 @@ class SecurityConfig( ReactiveAuthenticationManager { auth -> val token = auth.principal as AuthenticationToken LOGGER.info( - "authentication: emailVerified: ${token.isEmailVerified}; claims: ${token.userId}" + "authentication: emailVerified: ${token.isEmailVerified}; claims: ${token.userId}", ) Mono.just(auth.apply { isAuthenticated = true }) - } + }, ).apply { setServerAuthenticationConverter { exchange -> putReqId(exchange.request.id) @@ -98,7 +104,7 @@ class SecurityConfig( ?.replace("Bearer", "") ?.trim() ?: return@setServerAuthenticationConverter Mono.error( - UnauthorizedException("Missing firebase auth token") + UnauthorizedException("Missing firebase auth token"), ) try { diff --git a/src/test/kotlin/com/mnnit/moticlubs/MotiClubsServiceApplicationTests.kt b/src/test/kotlin/com/mnnit/moticlubs/MotiClubsServiceApplicationTests.kt index 3a5cdb8..bf2ac75 100644 --- a/src/test/kotlin/com/mnnit/moticlubs/MotiClubsServiceApplicationTests.kt +++ b/src/test/kotlin/com/mnnit/moticlubs/MotiClubsServiceApplicationTests.kt @@ -3,11 +3,10 @@ package com.mnnit.moticlubs import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest -@SpringBootTest +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) class MotiClubsServiceApplicationTests { @Test fun contextLoads() { } - }