This commit is contained in:
anhefti 2019-02-04 18:28:31 +01:00
parent ec26aefadf
commit 21efe190bd
3 changed files with 19 additions and 18 deletions

View file

@ -23,11 +23,9 @@ import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -56,7 +54,6 @@ import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
@GuiProfile @GuiProfile
@RestController @RestController
@Order(6) @Order(6)
@Import(DataSourceAutoConfiguration.class)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter implements ErrorController { public class WebSecurityConfig extends WebSecurityConfigurerAdapter implements ErrorController {
@Value("${sebserver.webservice.api.redirect.unauthorized}") @Value("${sebserver.webservice.api.redirect.unauthorized}")

View file

@ -8,14 +8,25 @@
package ch.ethz.seb.sebserver.webservice; package ch.ethz.seb.sebserver.webservice;
import javax.sql.DataSource;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
@Configuration
@WebServiceProfile @WebServiceProfile
@Import(DataSourceAutoConfiguration.class)
public class WebServiceInit implements ApplicationListener<ApplicationReadyEvent> { public class WebServiceInit implements ApplicationListener<ApplicationReadyEvent> {
private static final Logger log = LoggerFactory.getLogger(WebServiceInit.class); private static final Logger log = LoggerFactory.getLogger(WebServiceInit.class);
@ -27,4 +38,10 @@ public class WebServiceInit implements ApplicationListener<ApplicationReadyEvent
// TODO whatever has to be initialized for the web-service component right after startup comes here // TODO whatever has to be initialized for the web-service component right after startup comes here
} }
@Lazy
@Bean
public TokenStore tokenStore(final DataSource dataSource) {
return new JdbcTokenStore(dataSource);
}
} }

View file

@ -8,14 +8,9 @@
package ch.ethz.seb.sebserver.webservice.weblayer.oauth; package ch.ethz.seb.sebserver.webservice.weblayer.oauth;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
@ -26,7 +21,6 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Aut
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.AccessTokenConverter; import org.springframework.security.oauth2.provider.token.AccessTokenConverter;
import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import ch.ethz.seb.sebserver.WebSecurityConfig; import ch.ethz.seb.sebserver.WebSecurityConfig;
@ -44,13 +38,12 @@ import ch.ethz.seb.sebserver.webservice.weblayer.WebServiceUserDetails;
@Configuration @Configuration
@EnableAuthorizationServer @EnableAuthorizationServer
@Order(100) @Order(100)
@Import(DataSourceAutoConfiguration.class)
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired @Autowired
private AccessTokenConverter accessTokenConverter; private AccessTokenConverter accessTokenConverter;
@Autowired(required = true) @Autowired(required = true)
private DataSource dataSource; private TokenStore tokenStore;
@Autowired @Autowired
private WebServiceUserDetails webServiceUserDetails; private WebServiceUserDetails webServiceUserDetails;
@Autowired @Autowired
@ -75,18 +68,12 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
clients.withClientDetails(this.webServiceClientDetails); clients.withClientDetails(this.webServiceClientDetails);
} }
@Bean
public TokenStore tokenStore(final DataSource dataSource) {
System.out.println("************************* this.dataSource:" + this.dataSource);
return new JdbcTokenStore(this.dataSource);
}
@Override @Override
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) { public void configure(final AuthorizationServerEndpointsConfigurer endpoints) {
final JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter(); final JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
jwtAccessTokenConverter.setAccessTokenConverter(this.accessTokenConverter); jwtAccessTokenConverter.setAccessTokenConverter(this.accessTokenConverter);
endpoints endpoints
.tokenStore(tokenStore(this.dataSource)) .tokenStore(this.tokenStore)
.authenticationManager(this.authenticationManager) .authenticationManager(this.authenticationManager)
.userDetailsService(this.webServiceUserDetails) .userDetailsService(this.webServiceUserDetails)
.accessTokenConverter(jwtAccessTokenConverter); .accessTokenConverter(jwtAccessTokenConverter);