Skip to content

Secure with @PreAuthorize #84

Answered by maxixcom
adriendengreville asked this question in Q&A
Discussion options

You must be logged in to vote

Yes @Secure use only ROLE_ authorities as it is mentioned in annotation comments.

But I found that the annotation @PreAuthorize works fine. I use it like

    @DgsData(parentType = "Mutation", field = "updateCategory")
    @PreAuthorize("hasAuthority('admin:write')")
    fun updateCategory(input: CategoryUpdateInput): CategoryType? {
        return categoryService.update(input)
    }

Check if you have @EnableGlobalMethodSecurity(prePostEnabled = true) in your configuration.
I have it as follows:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
class SecurityConfig(
    private val jwtConfigProperties: JwtConfigProperties,
    private val userService: U…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@adriendengreville
Comment options

Answer selected by adriendengreville
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants