add PreAthourized to memomry
This commit is contained in:
parent
97c666e832
commit
313de12d51
@ -2,6 +2,7 @@ package com.chantha.mini.config
|
|||||||
|
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
|
||||||
|
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.builders.HttpSecurity
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
|
||||||
@ -10,11 +11,12 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
|
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||||
class WebSecurityConfig : WebSecurityConfigurerAdapter() {
|
class WebSecurityConfig : WebSecurityConfigurerAdapter() {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun configure(auth: AuthenticationManagerBuilder) {
|
override fun configure(auth: AuthenticationManagerBuilder) {
|
||||||
auth.inMemoryAuthentication().withUser("admin").password("{noop}admin").roles("ADMIN")
|
auth.inMemoryAuthentication().withUser("admin").password("{noop}admin").roles("ADMIN")
|
||||||
.and().withUser("dba").password("dba").roles("DBA")
|
.and().withUser("dba").password("{noop}dba").roles("DBA")
|
||||||
.and().withUser("user").password("user").roles("USER")
|
.and().withUser("user").password("user").roles("USER")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,28 +4,30 @@ import com.chantha.mini.dto.UserDto
|
|||||||
import com.chantha.mini.service.UserService
|
import com.chantha.mini.service.UserService
|
||||||
import com.fasterxml.jackson.annotation.JsonRootName
|
import com.fasterxml.jackson.annotation.JsonRootName
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize
|
||||||
import org.springframework.stereotype.Controller
|
import org.springframework.stereotype.Controller
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
import org.springframework.web.bind.annotation.*
|
||||||
import org.springframework.web.bind.annotation.PathVariable
|
import java.util.*
|
||||||
import org.springframework.web.bind.annotation.RestController
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
class UserController @Autowired constructor(private val userService: UserService){
|
class UserController @Autowired constructor(private val userService: UserService){
|
||||||
|
|
||||||
@GetMapping("/api/user/name/{firstName}/{lastName}")
|
@GetMapping("/api/user/name/{firstName}/{lastName}")
|
||||||
fun findByFirstNameAndLastName(@PathVariable firstName:String ?="",@PathVariable lastName:String?=""):UserDto{
|
fun findByFirstNameAndLastName(@PathVariable firstName:String ?="",@PathVariable lastName:String?=""):UserDto{
|
||||||
println(lastName+" "+firstName)
|
|
||||||
return userService.findByFirstNameAndLastName(firstName,lastName)
|
return userService.findByFirstNameAndLastName(firstName,lastName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
@GetMapping("/api/user")
|
@GetMapping("/api/user")
|
||||||
fun findAllRecord():List<UserDto>{
|
fun findAllRecord():List<UserDto>{
|
||||||
return userService.findAllRecord().orEmpty()
|
return userService.findAllRecord().orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/api/user/id/{id}")
|
@RequestMapping("/api/user/{id}")
|
||||||
fun findById(@PathVariable Id:Long ):UserDto{
|
fun findByOneRecord(@PathVariable uid:String): List<UserDto> {
|
||||||
return userService.findById(Id)
|
//error Path Varaible Missing URI
|
||||||
|
print(uid)
|
||||||
|
return userService.findByOneRecord(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import com.chantha.mini.dto.UserDto
|
|||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
import org.springframework.data.jpa.repository.Query
|
import org.springframework.data.jpa.repository.Query
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
interface UserRepo : JpaRepository<UserDto,Long> {
|
interface UserRepo : JpaRepository<UserDto,Long> {
|
||||||
@ -13,5 +14,5 @@ interface UserRepo : JpaRepository<UserDto,Long> {
|
|||||||
@Query("SELECT * FROM user_dto",nativeQuery = true)
|
@Query("SELECT * FROM user_dto",nativeQuery = true)
|
||||||
fun findAllRecord():List<UserDto>
|
fun findAllRecord():List<UserDto>
|
||||||
@Query("SELECT * FROM user_dto WHERE id=?1",nativeQuery = true)
|
@Query("SELECT * FROM user_dto WHERE id=?1",nativeQuery = true)
|
||||||
fun findById(Id :Long ?= 0):UserDto
|
fun findByOneRecord(Id :Long ): List<UserDto>
|
||||||
}
|
}
|
@ -19,7 +19,7 @@ class UserService @Autowired constructor(private val userRepo: UserRepo) {
|
|||||||
return userRepo.findAllRecord()
|
return userRepo.findAllRecord()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findById(Id : Long? = 0): UserDto {
|
fun findByOneRecord(Id : Long ): List<UserDto> {
|
||||||
return userRepo.findById(Id)
|
return userRepo.findByOneRecord(Id)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user