增加权限配置
diff --git a/build.gradle b/build.gradle
index 0e9b130..ead6122 100644
--- a/build.gradle
+++ b/build.gradle
@@ -16,24 +16,37 @@
mavenCentral()
}
+war {
+ baseName = "payapi-service"
+ manifest {
+ attributes('Payapi-Version': rootProject.version)
+ writeTo(project.buildDir + "/classes/MATE-INF.MF")
+ }
+}
+
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
+ implementation 'org.springframework.security:spring-security-oauth2-client'
+ implementation 'org.springframework.security:spring-security-oauth2-jose'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
implementation 'org.jetbrains.kotlin:kotlin-reflect'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
- providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
- testImplementation 'org.springframework.boot:spring-boot-starter-test'
- implementation group: 'com.sun.jersey', name: 'jersey-client', version:'1.19'
+ implementation 'org.postgresql:postgresql:42.2.5'
+ implementation 'com.jcabi:jcabi-manifests:1.1'
+ implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
+ implementation group: 'com.sun.jersey', name: 'jersey-client', version: '1.19'
implementation group: 'javax.servlet', name: 'jstl', version: '1.2'
implementation group: 'taglibs', name: 'standard', version: '1.1.2'
implementation group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.1'
implementation group: 'log4j', name: 'log4j', version: '1.2.16'
- implementation files ('libs/ojdbc6.jar')
+ implementation files('libs/ojdbc6.jar')
- implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
+
+ providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
+ testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
compileKotlin {
diff --git a/config/application-devel-pg.properties b/config/application-devel-pg.properties
index c092cce..64f9736 100644
--- a/config/application-devel-pg.properties
+++ b/config/application-devel-pg.properties
@@ -3,8 +3,9 @@
# create and drop tables and sequences, loads import.sql
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
+spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
# Oracle settings
-spring.datasource.url=jdbc:postgresql://172.28.201.101:5432/dlpay
+spring.datasource.url=jdbc:postgresql://172.28.201.70:15432/payapi
spring.datasource.username=payapi
spring.datasource.password=123456
diff --git a/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt b/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt
index e72d7fb..baa9e6c 100644
--- a/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt
+++ b/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt
@@ -1,25 +1,38 @@
package com.supwisdom.dlpay
+import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.PropertySource
+import org.springframework.core.annotation.Order
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
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.core.Authentication
import org.springframework.security.core.userdetails.User
import org.springframework.security.core.userdetails.UserDetailsService
+import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository
import org.springframework.security.provisioning.InMemoryUserDetailsManager
+import org.springframework.security.web.authentication.logout.CookieClearingLogoutHandler
+import org.springframework.security.web.authentication.logout.LogoutSuccessHandler
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer
+import javax.servlet.http.HttpServletRequest
+import javax.servlet.http.HttpServletResponse
@EnableWebSecurity
-class WebSecurityConfig : WebMvcConfigurer {
+class WebSecurityConfig {
+ @Autowired
+ private lateinit var clientRegistrationRepository: ClientRegistrationRepository
@Bean
- open fun userDetailsService(): UserDetailsService {
+ fun userDetailsService(): UserDetailsService {
val manager = InMemoryUserDetailsManager()
manager.createUser(User.withDefaultPasswordEncoder()
.username("admin")
@@ -28,25 +41,57 @@
return manager
}
+ companion object {
+ @Configuration
+ @Order(1)
+ class ApiWebSecurityConfigurationAdapter : WebSecurityConfigurerAdapter() {
+ @Autowired
+ private lateinit var clientRegistrationRepository: ClientRegistrationRepository
-}
+ override fun configure(http: HttpSecurity) {
+ http.authorizeRequests()
+// .antMatchers("/login", "/resources/**", "/about", "/common/**").permitAll()
+// .antMatchers("/admin/**").hasRole("ADMIN")
+// .antMatchers("/db/**").access("hasRole('ADMIN') and hasRole('DBA')")
+ .antMatchers("/**").permitAll()
+ .antMatchers("/admin/**").hasRole("ADMIN")
+ .anyRequest().authenticated()
+ .and().httpBasic()
+ .and()
+ .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
+// .oauth2Client()
+// .clientRegistrationRepository(clientRegistrationRepository)
+// .authorizedClientRepository(this.authorizedClientRepository())
+// .authorizedClientService(this.authorizedClientService())
+// .authorizationCodeGrant()
+// .authorizationRequestRepository(this.authorizationRequestRepository())
+// .authorizationRequestResolver(this.authorizationRequestResolver())
+// .accessTokenResponseClient(this.accessTokenResponseClient())
+ }
+ }
-@EnableWebSecurity
-class OAuth2ClientSecurityConfig : WebSecurityConfigurerAdapter() {
+ @Configuration
+ class MvcWebSecurityConfigurationAdapter : WebSecurityConfigurerAdapter() {
- override fun configure(http: HttpSecurity) {
- http.authorizeRequests()
- .antMatchers("/login", "/resources/**", "/about").permitAll()
- .antMatchers("/admin/**").hasRole("ADMIN")
- .antMatchers("/db/**").access("hasRole('ADMIN') and hasRole('DBA')")
- .anyRequest().authenticated()
- .and()
- .formLogin()
- .loginPage("/login").permitAll()
+ override fun configure(http: HttpSecurity) {
+ http.authorizeRequests()
+ .anyRequest().authenticated()
+ .and()
+ .formLogin()
+ .loginPage("/user/login").permitAll()
+ .and()
+ .logout()
+ .logoutUrl("/user/logout")
+ .logoutSuccessUrl("/user/home")
+ .invalidateHttpSession(true)
+ .addLogoutHandler(CookieClearingLogoutHandler())
+ }
+ }
}
}
+
@SpringBootApplication
class DlpayApplication
diff --git a/src/main/kotlin/com/supwisdom/dlpay/framework/controller/framework_controller.kt b/src/main/kotlin/com/supwisdom/dlpay/framework/controller/framework_controller.kt
new file mode 100644
index 0000000..b385f9b
--- /dev/null
+++ b/src/main/kotlin/com/supwisdom/dlpay/framework/controller/framework_controller.kt
@@ -0,0 +1,28 @@
+package com.supwisdom.dlpay.framework.controller
+
+import com.jcabi.manifests.Manifests
+import com.supwisdom.dlpay.framework.ResponseBodyBuilder
+import org.springframework.http.ResponseEntity
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RestController
+
+
+@RestController
+@RequestMapping("/common")
+class AboutController {
+ @GetMapping("/version")
+ fun version(): ResponseEntity<Any> {
+ return try {
+ Manifests.read("Payapi-Version").let {
+ ResponseEntity.ok(ResponseBodyBuilder.create()
+ .data("version", it)
+ .success())
+ }
+ } catch (e: IllegalArgumentException) {
+ ResponseEntity.ok(ResponseBodyBuilder.create()
+ .data("version", "unknown")
+ .success())
+ }
+ }
+}
\ No newline at end of file