Compare commits
No commits in common. "49023d2237c8a0c097f807a624727f90c8a36545" and "ea9c700f373338f35c43694eaf0aa4b4af46a85d" have entirely different histories.
49023d2237
...
ea9c700f37
11
.github/dependabot.yml
vendored
11
.github/dependabot.yml
vendored
@ -1,11 +0,0 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "gradle" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
11
.gitmodules
vendored
11
.gitmodules
vendored
@ -1,8 +1,3 @@
|
||||
[submodule "cubetiq-security-core"]
|
||||
path = cubetiq-security-core
|
||||
url = https://git.cubetiqs.com/cubetiq/cubetiq-security-core.git
|
||||
branch = main
|
||||
[submodule "cubetiq-security-web"]
|
||||
path = cubetiq-security-web
|
||||
url = https://git.cubetiqs.com/cubetiq/cubetiq-security-web.git
|
||||
branch = main
|
||||
[submodule "cubetiq-security-jwt"]
|
||||
path = cubetiq-security-jwt
|
||||
url = https://git.cubetiqs.com/CUBETIQ/cubetiq-security-jwt.git
|
||||
|
@ -1,7 +1,7 @@
|
||||
# GraphQL & Spring Boot (Demo Project)
|
||||
- Spring Boot
|
||||
- DGS Framework
|
||||
- Kotlin
|
||||
- Spring Boot (2.6)
|
||||
- DGS Framework (4.5.0)
|
||||
- Kotlin (1.5.21)
|
||||
|
||||
# Contributors
|
||||
- Sambo Chea <sombochea@cubetiqs.com>
|
@ -1,23 +1,23 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id("org.springframework.boot") version "3.0.0" apply false
|
||||
id("io.spring.dependency-management") version "1.1.0" apply false
|
||||
kotlin("jvm") version "1.7.22" apply false
|
||||
kotlin("plugin.spring") version "1.7.22" apply false
|
||||
kotlin("plugin.jpa") version "1.7.22" apply false
|
||||
id("com.netflix.dgs.codegen") version "5.6.3" apply false
|
||||
id("org.springframework.boot") version "2.5.3" apply false
|
||||
id("io.spring.dependency-management") version "1.0.11.RELEASE" apply false
|
||||
kotlin("jvm") version "1.5.21" apply false
|
||||
kotlin("plugin.spring") version "1.5.21" apply false
|
||||
kotlin("plugin.jpa") version "1.5.21" apply false
|
||||
id("com.netflix.dgs.codegen") version "5.0.5" apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri("https://m.ctdn.net") }
|
||||
}
|
||||
|
||||
group = "com.cubetiqs"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
|
||||
val javaVersion = "17"
|
||||
val javaVersion = "11"
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
sourceCompatibility = javaVersion
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit 612bafe9af476798a40a536c82112c63c8627f4f
|
1
cubetiq-security-jwt
Submodule
1
cubetiq-security-jwt
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit d69f52fee0d6c8c0fad3eab64dc0645470168a49
|
@ -1 +0,0 @@
|
||||
Subproject commit 62d0e718e59af79db15871bde67affd8c38b15e5
|
@ -7,12 +7,13 @@ plugins {
|
||||
id("com.netflix.dgs.codegen")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":cubetiq-security-web"))
|
||||
extra["dgsVersion"] = "4.5.0"
|
||||
|
||||
implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:5.4.3"))
|
||||
implementation("com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter")
|
||||
runtimeOnly("com.netflix.graphql.dgs:graphql-dgs-subscriptions-websockets-autoconfigure")
|
||||
dependencies {
|
||||
api(project(":cubetiq-security-jwt"))
|
||||
|
||||
implementation("com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter:${property("dgsVersion")}")
|
||||
runtimeOnly("com.netflix.graphql.dgs:graphql-dgs-subscriptions-websockets-autoconfigure:${property("dgsVersion")}")
|
||||
|
||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||
|
@ -1,19 +1,10 @@
|
||||
package com.cubetiqs.graphql.demo
|
||||
|
||||
import com.cubetiqs.sp.security.util.PasswordUtils
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.runApplication
|
||||
import org.springframework.security.crypto.password.PasswordEncoder
|
||||
|
||||
@SpringBootApplication
|
||||
class GraphqlDemoApplication @Autowired constructor(
|
||||
private val passwordEncoder: PasswordEncoder,
|
||||
) {
|
||||
init {
|
||||
PasswordUtils.setEncoder(passwordEncoder)
|
||||
}
|
||||
}
|
||||
class GraphqlDemoApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<GraphqlDemoApplication>(*args)
|
||||
|
@ -1,44 +1,37 @@
|
||||
package com.cubetiqs.graphql.demo.config
|
||||
|
||||
import com.cubetiqs.graphql.demo.security.AuthService
|
||||
import com.cubetiqs.sp.security.EnableCubetiqSecurityModule
|
||||
import com.cubetiqs.sp.security.jwt.CubetiqJwtProperties
|
||||
import com.cubetiqs.sp.security.jwt.JwtSecurityConfigurer
|
||||
import com.cubetiqs.sp.security.support.AuthenticationExceptionEntryPoint
|
||||
import com.cubetiqs.security.jwt.AuthenticationExceptionEntryPoint
|
||||
import com.cubetiqs.security.jwt.JwtSecurityConfigurer
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
|
||||
import org.springframework.security.config.http.SessionCreationPolicy
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
|
||||
import org.springframework.security.crypto.password.PasswordEncoder
|
||||
import org.springframework.security.web.SecurityFilterChain
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableMethodSecurity(prePostEnabled = true)
|
||||
@EnableCubetiqSecurityModule
|
||||
class WebSecurityConfig @Autowired constructor(
|
||||
private val authService: AuthService,
|
||||
private val cubetiqJwtProperties: CubetiqJwtProperties,
|
||||
) {
|
||||
@Bean
|
||||
fun passwordEncoder(): PasswordEncoder {
|
||||
return BCryptPasswordEncoder(10)
|
||||
}
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
class WebSecurityConfig : WebSecurityConfigurerAdapter() {
|
||||
@Autowired
|
||||
private lateinit var authService: AuthService
|
||||
|
||||
@Bean
|
||||
fun filterChain(http: HttpSecurity): SecurityFilterChain {
|
||||
http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||
override fun configure(http: HttpSecurity) {
|
||||
http.csrf().disable()
|
||||
.sessionManagement()
|
||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||
|
||||
http.exceptionHandling().authenticationEntryPoint(AuthenticationExceptionEntryPoint())
|
||||
http
|
||||
.exceptionHandling()
|
||||
.authenticationEntryPoint(AuthenticationExceptionEntryPoint())
|
||||
|
||||
http.apply(JwtSecurityConfigurer(authService, cubetiqJwtProperties))
|
||||
http
|
||||
.apply(JwtSecurityConfigurer(authService))
|
||||
|
||||
http.authorizeHttpRequests().anyRequest().permitAll()
|
||||
|
||||
return http.build()
|
||||
http
|
||||
.authorizeRequests()
|
||||
.anyRequest().permitAll()
|
||||
}
|
||||
}
|
@ -2,8 +2,8 @@ package com.cubetiqs.graphql.demo.domain
|
||||
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener
|
||||
import java.io.Serializable
|
||||
import jakarta.persistence.EntityListeners
|
||||
import jakarta.persistence.MappedSuperclass
|
||||
import javax.persistence.EntityListeners
|
||||
import javax.persistence.MappedSuperclass
|
||||
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener::class)
|
||||
|
@ -8,7 +8,7 @@ import org.springframework.data.annotation.CreatedDate
|
||||
import org.springframework.data.annotation.LastModifiedDate
|
||||
import java.math.BigDecimal
|
||||
import java.util.*
|
||||
import jakarta.persistence.*
|
||||
import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
@Table(name = "accounts", indexes = [
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.cubetiqs.graphql.demo.domain.account
|
||||
|
||||
import java.util.*
|
||||
import jakarta.persistence.PostPersist
|
||||
import jakarta.persistence.PrePersist
|
||||
import jakarta.persistence.PreUpdate
|
||||
import javax.persistence.PostPersist
|
||||
import javax.persistence.PrePersist
|
||||
import javax.persistence.PreUpdate
|
||||
|
||||
class AccountEntityListener {
|
||||
@PrePersist
|
||||
|
@ -7,7 +7,7 @@ import org.hibernate.Hibernate
|
||||
import org.springframework.data.annotation.CreatedDate
|
||||
import org.springframework.data.annotation.LastModifiedDate
|
||||
import java.util.*
|
||||
import jakarta.persistence.*
|
||||
import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
@Table(
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.cubetiqs.graphql.demo.domain.user
|
||||
|
||||
import java.util.*
|
||||
import jakarta.persistence.PrePersist
|
||||
import jakarta.persistence.PreUpdate
|
||||
import javax.persistence.PrePersist
|
||||
import javax.persistence.PreUpdate
|
||||
|
||||
class UserEntityListener {
|
||||
@PrePersist
|
||||
|
@ -4,7 +4,7 @@ import com.cubetiqs.graphql.demo.context.GMutation
|
||||
import com.cubetiqs.graphql.demo.dgmodel.DgsConstants
|
||||
import com.cubetiqs.graphql.demo.dgmodel.types.LoginResponse
|
||||
import com.cubetiqs.graphql.demo.security.AuthService
|
||||
import com.cubetiqs.sp.security.jwt.util.JwtTokenUtils
|
||||
import com.cubetiqs.security.jwt.util.JwtUtils
|
||||
import com.netflix.graphql.dgs.DgsMutation
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
|
||||
@ -16,10 +16,7 @@ class LoginMutationResolver {
|
||||
@DgsMutation(field = DgsConstants.MUTATION.Login)
|
||||
fun login(username: String, password: String): LoginResponse {
|
||||
val auth = authService.login(username, password)
|
||||
val token = JwtTokenUtils.createTokens(auth)
|
||||
return LoginResponse(
|
||||
accessToken = token.accessToken,
|
||||
refreshToken = token.refreshToken,
|
||||
)
|
||||
val token = JwtUtils.encryptToken(auth)
|
||||
return LoginResponse(token)
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import com.cubetiqs.graphql.demo.domain.user.User
|
||||
import com.cubetiqs.graphql.demo.domain.user.UserInput
|
||||
import com.cubetiqs.graphql.demo.domain.user.UserMapper
|
||||
import com.cubetiqs.graphql.demo.repository.UserRepository
|
||||
import com.cubetiqs.sp.security.util.PasswordUtils
|
||||
import com.cubetiqs.security.jwt.util.JwtUtils
|
||||
import com.netflix.graphql.dgs.DgsMutation
|
||||
import com.netflix.graphql.dgs.exceptions.DgsEntityNotFoundException
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
@ -30,7 +30,7 @@ class UserMutationResolver @Autowired constructor(
|
||||
@DgsMutation(field = DgsConstants.MUTATION.ChangeUserPassword)
|
||||
fun changePassword(input: UserChangePasswordInput): User {
|
||||
val user = userRepository.queryByUsername(input.username).orElse(null) ?: throw DgsEntityNotFoundException("User not found!")
|
||||
user.password = PasswordUtils.encode(input.password)
|
||||
user.password = JwtUtils.passwordEncoder().encode(input.password)
|
||||
return userRepository.save(user)
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package com.cubetiqs.graphql.demo.security
|
||||
|
||||
import com.cubetiqs.graphql.demo.domain.user.User
|
||||
import com.cubetiqs.sp.security.jwt.util.JwtTokenUtils
|
||||
import com.cubetiqs.sp.security.util.PasswordUtils
|
||||
import com.cubetiqs.security.jwt.util.JwtUtils
|
||||
import org.springframework.security.core.GrantedAuthority
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority
|
||||
import org.springframework.security.core.userdetails.UserDetails
|
||||
@ -48,7 +47,7 @@ data class AuthDetails(
|
||||
}
|
||||
|
||||
fun isPasswordValid(password: String): Boolean {
|
||||
return PasswordUtils.matches(password, this.getPassword())
|
||||
return JwtUtils.passwordEncoder().matches(password, this.getPassword())
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
1
dgs-graphql/src/main/resources/.gitignore
vendored
1
dgs-graphql/src/main/resources/.gitignore
vendored
@ -1 +0,0 @@
|
||||
application-local.yml
|
@ -3,8 +3,6 @@ server:
|
||||
|
||||
# Spring Boot
|
||||
spring:
|
||||
profiles:
|
||||
active: ${APP_PROFILE:}
|
||||
datasource:
|
||||
url: jdbc:postgresql://${DB_HOST:localhost}:5432/${DB_NAME:graphql-demo}
|
||||
username: ${DB_USER:your-username}
|
||||
|
@ -14,8 +14,7 @@ input UserInput {
|
||||
}
|
||||
|
||||
type LoginResponse {
|
||||
accessToken: String
|
||||
refreshToken: String
|
||||
token: String
|
||||
}
|
||||
|
||||
input UserChangePasswordInput {
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
@ -1,3 +1,4 @@
|
||||
rootProject.name = "spring-graphql-demo"
|
||||
rootProject.name = "graphql-demo"
|
||||
|
||||
include("cubetiq-security-core", "cubetiq-security-web", "dgs-graphql")
|
||||
include("dgs-graphql")
|
||||
include("cubetiq-security-jwt")
|
Loading…
Reference in New Issue
Block a user