forked from bayang/jelu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: save activity in DB bayang#116
- Loading branch information
Showing
44 changed files
with
473 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/kotlin/io/github/bayang/jelu/config/UserAgentWebAuthenticationDetails.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.github.bayang.jelu.config | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect | ||
import com.fasterxml.jackson.annotation.JsonCreator | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import jakarta.servlet.http.HttpServletRequest | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.security.web.authentication.WebAuthenticationDetails | ||
|
||
class UserAgentWebAuthenticationDetails : WebAuthenticationDetails { | ||
|
||
var userAgent: String = "" | ||
|
||
constructor(remoteAddress: String?, sessionId: String?, userAgent: String?) : super(remoteAddress, sessionId) { | ||
if (userAgent != null) { | ||
this.userAgent = userAgent | ||
} | ||
} | ||
|
||
constructor(request: HttpServletRequest) : super(request) { | ||
this.userAgent = request.getHeader(HttpHeaders.USER_AGENT).orEmpty() | ||
} | ||
|
||
override fun toString(): String { | ||
val sb = StringBuilder() | ||
sb.append(javaClass.simpleName).append(" [") | ||
sb.append("RemoteIpAddress=").append(this.remoteAddress).append(", ") | ||
sb.append("UserAgent=").append(this.userAgent).append(", ") | ||
sb.append("SessionId=").append(this.sessionId).append("]") | ||
return sb.toString() | ||
} | ||
} | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonAutoDetect( | ||
fieldVisibility = JsonAutoDetect.Visibility.ANY, | ||
getterVisibility = JsonAutoDetect.Visibility.NONE, | ||
isGetterVisibility = JsonAutoDetect.Visibility.NONE, | ||
creatorVisibility = JsonAutoDetect.Visibility.ANY, | ||
) | ||
class UserAgentWebAuthenticationDetailsMixin @JsonCreator constructor( | ||
@JsonProperty("remoteAddress") remoteAddress: String?, | ||
@JsonProperty("sessionId") sessionId: String?, | ||
@JsonProperty("userAgent") userAgent: String?, | ||
) |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/io/github/bayang/jelu/config/UserAgentWebAuthenticationDetailsSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.github.bayang.jelu.config | ||
|
||
import jakarta.servlet.http.HttpServletRequest | ||
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class UserAgentWebAuthenticationDetailsSource : WebAuthenticationDetailsSource() { | ||
override fun buildDetails(context: HttpServletRequest): UserAgentWebAuthenticationDetails = | ||
UserAgentWebAuthenticationDetails(context) | ||
} |
Oops, something went wrong.