File tree Expand file tree Collapse file tree
jetty-session-demo/src/main
java/com/baeldung/spring/session/tomcatex
tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88@ SpringBootApplication
99@ RestController
1010public class JettyWebApplication {
11- public static void main (String [] args ) {
12- SpringApplication .run (JettyWebApplication .class , args );
13- }
11+ public static void main (String [] args ) {
12+ SpringApplication .run (JettyWebApplication .class , args );
13+ }
1414
15- @ RequestMapping
16- public String helloJetty () {
17- return "hello Jetty" ;
18- }
15+ @ RequestMapping
16+ public String helloJetty () {
17+ return "hello Jetty" ;
18+ }
1919
20- @ RequestMapping ("/test" )
21- public String lksjdf () {
22- return "" ;
23- }
20+ @ RequestMapping ("/test" )
21+ public String lksjdf () {
22+ return "" ;
23+ }
2424}
Original file line number Diff line number Diff line change 1010@ EnableWebSecurity
1111public class SecurityConfig extends WebSecurityConfigurerAdapter {
1212
13- @ Override
14- protected void configure (HttpSecurity http ) throws Exception {
15- http
16- .sessionManagement ()
17- .sessionCreationPolicy (SessionCreationPolicy .NEVER )
18- .and ()
19- .authorizeRequests ().anyRequest ().hasRole ("ADMIN" );
20- }
13+ @ Override
14+ protected void configure (HttpSecurity http ) throws Exception {
15+ http
16+ .sessionManagement ()
17+ .sessionCreationPolicy (SessionCreationPolicy .NEVER )
18+ .and ()
19+ .authorizeRequests ().anyRequest ().hasRole ("ADMIN" );
20+ }
2121}
Original file line number Diff line number Diff line change 1010@ Configuration
1111@ EnableRedisHttpSession
1212public class SessionConfig extends AbstractHttpSessionApplicationInitializer {
13- @ Bean
14- public HttpSessionStrategy httpSessionStrategy () {
15- return new HeaderHttpSessionStrategy ();
16- }
13+ @ Bean
14+ public HttpSessionStrategy httpSessionStrategy () {
15+ return new HeaderHttpSessionStrategy ();
16+ }
1717}
Original file line number Diff line number Diff line change 11server.port =8081
2-
32spring.redis.host =localhost
43spring.redis.port =6379
Original file line number Diff line number Diff line change 44 xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
55 <modelVersion >4.0.0</modelVersion >
66
7+
78 <parent >
89 <groupId >com.baeldung</groupId >
910 <artifactId >parent-modules</artifactId >
1213
1314 <artifactId >spring-session</artifactId >
1415 <version >1.0.0-SNAPSHOT</version >
16+ <packaging >pom</packaging >
1517
1618 <modules >
1719 <module >jetty-session-demo</module >
Original file line number Diff line number Diff line change 1111@ EnableWebSecurity
1212public class SecurityConfig extends WebSecurityConfigurerAdapter {
1313
14- @ Autowired
15- public void configureGlobal (AuthenticationManagerBuilder auth ) throws Exception {
16- auth .inMemoryAuthentication ()
17- .withUser ("user" ).password ("password" ).roles ("USER" ).and ()
18- .withUser ("admin" ).password ("password" ).roles ("ADMIN" );
19- }
14+ @ Autowired
15+ public void configureGlobal (AuthenticationManagerBuilder auth ) throws Exception {
16+ auth .inMemoryAuthentication ()
17+ .withUser ("user" ).password ("password" ).roles ("USER" ).and ()
18+ .withUser ("admin" ).password ("password" ).roles ("ADMIN" );
19+ }
2020
21- @ Override
22- protected void configure (HttpSecurity http ) throws Exception {
23- http
24- .httpBasic ().and ()
25- .authorizeRequests ()
26- .antMatchers ("/" ).permitAll ()
27- .antMatchers ("/tomcat" ).hasRole ("USER" )
28- .antMatchers ("/tomcat/admin" ).hasRole ("ADMIN" )
29- .anyRequest ().authenticated ();
30- }
21+ @ Override
22+ protected void configure (HttpSecurity http ) throws Exception {
23+ http
24+ .httpBasic ().and ()
25+ .authorizeRequests ()
26+ .antMatchers ("/" ).permitAll ()
27+ .antMatchers ("/tomcat" ).hasRole ("USER" )
28+ .antMatchers ("/tomcat/admin" ).hasRole ("ADMIN" )
29+ .anyRequest ().authenticated ();
30+ }
3131}
Original file line number Diff line number Diff line change 88@ SpringBootApplication
99@ RestController
1010public class TomcatWebApplication {
11- public static void main (String [] args ) {
12- SpringApplication .run (TomcatWebApplication .class , args );
13- }
11+ public static void main (String [] args ) {
12+ SpringApplication .run (TomcatWebApplication .class , args );
13+ }
1414
15- @ RequestMapping
16- public String helloDefault () {
17- return "hello default" ;
18- }
15+ @ RequestMapping
16+ public String helloDefault () {
17+ return "hello default" ;
18+ }
1919
20- @ RequestMapping ("/tomcat" )
21- public String helloTomcat () {
22- return "hello tomcat" ;
23- }
20+ @ RequestMapping ("/tomcat" )
21+ public String helloTomcat () {
22+ return "hello tomcat" ;
23+ }
2424
25- @ RequestMapping ("/tomcat/admin" )
26- public String helloTomcatAdmin () {
27- return "hello tomcat admin" ;
28- }
25+ @ RequestMapping ("/tomcat/admin" )
26+ public String helloTomcatAdmin () {
27+ return "hello tomcat admin" ;
28+ }
2929}
You can’t perform that action at this time.
0 commit comments