File tree Expand file tree Collapse file tree
test/java/org/baeldung/test Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818 <modules >
1919 <module >spring-security-sso-auth-server</module >
2020 <module >spring-security-sso-ui</module >
21+ <module >spring-security-sso-ui-2</module >
2122 </modules >
2223
2324 <properties >
Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+ <artifactId >spring-security-sso-ui-2</artifactId >
5+
6+ <name >spring-security-sso-ui-2</name >
7+ <packaging >war</packaging >
8+
9+ <parent >
10+ <groupId >org.baeldung</groupId >
11+ <artifactId >spring-security-sso</artifactId >
12+ <version >1.0.0-SNAPSHOT</version >
13+ </parent >
14+
15+ <dependencies >
16+
17+ <dependency >
18+ <groupId >org.springframework.boot</groupId >
19+ <artifactId >spring-boot-starter-web</artifactId >
20+ </dependency >
21+
22+ <dependency >
23+ <groupId >org.springframework.boot</groupId >
24+ <artifactId >spring-boot-starter-security</artifactId >
25+ </dependency >
26+
27+ <dependency >
28+ <groupId >org.springframework.security.oauth</groupId >
29+ <artifactId >spring-security-oauth2</artifactId >
30+ </dependency >
31+
32+ <dependency >
33+ <groupId >org.springframework.boot</groupId >
34+ <artifactId >spring-boot-starter-thymeleaf</artifactId >
35+ </dependency >
36+
37+ <dependency >
38+ <groupId >org.thymeleaf.extras</groupId >
39+ <artifactId >thymeleaf-extras-springsecurity4</artifactId >
40+ </dependency >
41+
42+ </dependencies >
43+
44+ </project >
Original file line number Diff line number Diff line change 1+ package org .baeldung .config ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .boot .autoconfigure .security .oauth2 .client .EnableOAuth2Sso ;
6+ import org .springframework .context .annotation .Bean ;
7+ import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
8+ import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
9+ import org .springframework .web .context .request .RequestContextListener ;
10+
11+ @ EnableOAuth2Sso
12+ @ SpringBootApplication
13+ public class UiApplication extends WebSecurityConfigurerAdapter {
14+
15+ @ Override
16+ public void configure (HttpSecurity http ) throws Exception {
17+ http .antMatcher ("/**" )
18+ .authorizeRequests ()
19+ .antMatchers ("/" , "/login**" )
20+ .permitAll ()
21+ .anyRequest ()
22+ .authenticated ();
23+ }
24+
25+ @ Bean
26+ public RequestContextListener requestContextListener () {
27+ return new RequestContextListener ();
28+ }
29+
30+ public static void main (String [] args ) {
31+ SpringApplication .run (UiApplication .class , args );
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ package org .baeldung .config ;
2+
3+ import org .springframework .context .annotation .Bean ;
4+ import org .springframework .context .annotation .Configuration ;
5+ import org .springframework .context .support .PropertySourcesPlaceholderConfigurer ;
6+ import org .springframework .web .servlet .config .annotation .DefaultServletHandlerConfigurer ;
7+ import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
8+ import org .springframework .web .servlet .config .annotation .ResourceHandlerRegistry ;
9+ import org .springframework .web .servlet .config .annotation .ViewControllerRegistry ;
10+ import org .springframework .web .servlet .config .annotation .WebMvcConfigurerAdapter ;
11+
12+ @ Configuration
13+ @ EnableWebMvc
14+ public class UiWebConfig extends WebMvcConfigurerAdapter {
15+
16+ @ Bean
17+ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer () {
18+ return new PropertySourcesPlaceholderConfigurer ();
19+ }
20+
21+ @ Override
22+ public void configureDefaultServletHandling (final DefaultServletHandlerConfigurer configurer ) {
23+ configurer .enable ();
24+ }
25+
26+ @ Override
27+ public void addViewControllers (final ViewControllerRegistry registry ) {
28+ super .addViewControllers (registry );
29+ registry .addViewController ("/" )
30+ .setViewName ("forward:/index" );
31+ registry .addViewController ("/index" );
32+ registry .addViewController ("/securedPage" );
33+ }
34+
35+ @ Override
36+ public void addResourceHandlers (final ResourceHandlerRegistry registry ) {
37+ registry .addResourceHandler ("/resources/**" )
38+ .addResourceLocations ("/resources/" );
39+ }
40+
41+ }
Original file line number Diff line number Diff line change 1+ server :
2+ port : 8083
3+ context-path : /ui2
4+ session :
5+ cookie :
6+ name : UI2SESSION
7+ security :
8+ basic :
9+ enabled : false
10+ oauth2 :
11+ client :
12+ clientId : SampleClientId
13+ clientSecret : secret
14+ accessTokenUri : http://localhost:8081/auth/oauth/token
15+ userAuthorizationUri : http://localhost:8081/auth/oauth/authorize
16+ resource :
17+ userInfoUri : http://localhost:8081/auth/user/me
18+ spring :
19+ thymeleaf :
20+ cache : false
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta http-equiv ="Content-Type " content ="text/html; charset=utf-8 " />
5+ < title > Spring Security SSO Client 2</ title >
6+ < link rel ="stylesheet "
7+ href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css " />
8+ </ head >
9+
10+ < body >
11+ < div class ="container ">
12+ < div class ="col-sm-12 ">
13+ < h1 > Spring Security SSO Client 2</ h1 >
14+ < a class ="btn btn-primary " href ="securedPage "> Login</ a >
15+ </ div >
16+ </ div >
17+ </ body >
18+ </ html >
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta http-equiv ="Content-Type " content ="text/html; charset=utf-8 " />
5+ < title > Spring Security SSO Client 2</ title >
6+ < link rel ="stylesheet "
7+ href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css " />
8+ </ head >
9+
10+ < body >
11+ < div class ="container ">
12+ < div class ="col-sm-12 ">
13+ < h1 > Secured Page</ h1 >
14+ Welcome, < span th:text ="${#authentication.name} "> Name</ span >
15+ < br />
16+ Your authorities are < span th:text ="${#authentication.authorities} "> authorities</ span >
17+ </ div >
18+ </ div >
19+ </ body >
20+ </ html >
Original file line number Diff line number Diff line change 1+ package org .baeldung .test ;
2+
3+ import org .baeldung .config .UiApplication ;
4+ import org .junit .Test ;
5+ import org .junit .runner .RunWith ;
6+ import org .springframework .boot .test .context .SpringBootTest ;
7+ import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
8+ import org .springframework .test .context .junit4 .SpringRunner ;
9+
10+ @ RunWith (SpringRunner .class )
11+ @ SpringBootTest (classes = UiApplication .class , webEnvironment = WebEnvironment .RANDOM_PORT )
12+ public class UiIntegrationTest {
13+
14+ @ Test
15+ public void whenLoadApplication_thenSuccess () {
16+
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments