spring-projects / spring-projects/spring-security

OAuth: ClientDetailsService @PostConstruct method called twice

Open
#4,251 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Summary

We've added a @PostContruct method called init(), to our ClientDetailsService implementation. We then observe that init() is called twice: once on launch of the application during context creation, and once when the ClientDetailsService is first accessed by the token endpoints. Further calls to ClientDetailsService do not elicit calls to init(). The problem is that we have logic in the init() method that we want called exactly once.

Actual Behavior

OurClientDetailsServiceImpl.init() called twice, once on launch of the application during context creation, and once when the ClientDetailsService is first accessed by the token endpoints.

Expected Behavior

OurClientDetailsServiceImpl.init() called once on launch of the application during context creation.

Configuration

Configuration file is contained in sample repository below. The environment is as follows

  • Java v. 1.8
  • macOS Sierra v. 10.12.3
Version

Spring-Boot 1.5.2, and the corresponding spring-boot-security and spring-security-oauth versions.

Sample

The following code sample can be used to recreate the issue. The issue can be reproduced by building the project, running it, and issuing the following command in the terminal: curl acme:acmesecret@localhost:8080/oauth/token -d grant_type=password -d username=user -d password=password.

Also, thanks for your awesome work, and for your help.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked spring-oauth-issue-sample and reproduce the behavior by launching the application, then calling the /oauth/token endpoint with the supplied curl command. Trace the ClientDetailsService access during context creation and the first token request; done means the implementation's init() method is called exactly once.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
authentication, authorization, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.