-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicate auth id fix #1186
base: v2.1
Are you sure you want to change the base?
Duplicate auth id fix #1186
Changes from 5 commits
5de2595
f05f49f
111a29b
0853933
bea4049
0cf4fa4
a0a528b
5dc1f4e
e6cde50
02feef0
690124e
953575a
de19219
3dcb9ca
dbdbf4f
d24820f
fba0d5d
a2bf76b
bf86f64
e7a5c42
8334adc
eeb57f7
638662d
920f743
ccd6ecd
84009bb
4ed7f57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* | ||
* | ||
*/ | ||
package org.opensrp.web.config.security; | ||
|
||
|
@@ -10,10 +10,15 @@ | |
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
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.oauth2.common.OAuth2AccessToken; | ||
import org.springframework.security.oauth2.provider.ClientDetailsService; | ||
import org.springframework.security.oauth2.provider.OAuth2Authentication; | ||
import org.springframework.security.oauth2.provider.token.AuthenticationKeyGenerator; | ||
import org.springframework.security.oauth2.provider.token.DefaultAuthenticationKeyGenerator; | ||
import org.springframework.security.oauth2.provider.token.DefaultTokenServices; | ||
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; | ||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher; | ||
|
@@ -26,15 +31,15 @@ | |
@EnableWebSecurity | ||
@Configuration | ||
@Profile("oauth2") | ||
public class OAuth2SecurityConfig extends BasicAuthSecurityConfig{ | ||
public class OAuth2SecurityConfig extends BasicAuthSecurityConfig { | ||
|
||
@Autowired | ||
private OauthAuthenticationProvider opensrpAuthenticationProvider; | ||
|
||
@Autowired | ||
private ClientDetailsService clientDetailsService; | ||
|
||
@Qualifier( value = "openSRPDataSource") | ||
@Qualifier(value = "openSRPDataSource") | ||
@Autowired | ||
private DataSource dataSource; | ||
|
||
|
@@ -67,14 +72,13 @@ protected void configure(HttpSecurity http) throws Exception { | |
/* @formatter:on */ | ||
} | ||
|
||
|
||
@Override | ||
protected void configure(AuthenticationManagerBuilder auth) throws Exception { | ||
auth.authenticationProvider(opensrpAuthenticationProvider).eraseCredentials(false); | ||
} | ||
} | ||
|
||
public DefaultTokenServices tokenServices() { | ||
DefaultTokenServices tokenServices= new DefaultTokenServices(); | ||
DefaultTokenServices tokenServices = new DefaultTokenServices(); | ||
tokenServices.setTokenStore(tokenStore()); | ||
tokenServices.setSupportRefreshToken(true); | ||
tokenServices.setClientDetailsService(clientDetailsService); | ||
|
@@ -83,7 +87,18 @@ public DefaultTokenServices tokenServices() { | |
|
||
@Bean | ||
public JdbcTokenStore tokenStore() { | ||
return new JdbcTokenStore(dataSource); | ||
final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); | ||
final AuthenticationKeyGenerator authenticationKeyGenerator = new DefaultAuthenticationKeyGenerator(); | ||
return new JdbcTokenStore(dataSource) { | ||
|
||
@Override | ||
public void storeAccessToken(final OAuth2AccessToken token, final OAuth2Authentication authentication) { | ||
final String key = authenticationKeyGenerator.extractKey(authentication); | ||
jdbcTemplate.update("delete from oauth_access_token where authentication_id = ?", key); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check for null on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log info when |
||
super.storeAccessToken(token, authentication); | ||
} | ||
|
||
}; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for null
authentication
.