Source Code
Source Code
xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
5 <modelVersion>4.0.0</modelVersion>
6 <parent>
7 <groupId>org.springframework.boot</groupId>
8 <artifactId>spring-boot-starter-parent</artifactId>
9 <version>3.1.0</version>
10 <relativePath /> <!-- lookup parent from repository -->
11 </parent>
12 <groupId>com.ecommerce</groupId>
13 <artifactId>SpringBootSecurity</artifactId>
14 <version>0.0.1-SNAPSHOT</version>
15 <name>SpringBootSecurity</name>
16 <description>Demo project for Spring Boot</description>
17 <properties>
18 <java.version>20</java.version>
19 </properties>
20 <dependencies>
21 <dependency>
22 <groupId>org.springframework.boot</groupId>
23 <artifactId>spring-boot-starter-web</artifactId>
24 </dependency>
25 <dependency>
26 <groupId>org.springframework.boot</groupId>
27 <artifactId>spring-boot-starter-security</artifactId>
28 </dependency>
29 <!-- JSP support -->
30 <dependency>
31 <groupId>
32 org.apache.tomcat.embed</groupId>
33 <artifactId>tomcat-embed-jasper</artifactId>
34 <scope>
35 provided</scope>
36 </dependency>
37 <dependency>
38 <groupId>org.springframework.boot</groupId>
39 <artifactId>spring-boot-starter-test</artifactId>
40 <scope>test</scope>
41 </dependency>
42 </dependencies>
43
44 <build>
45 <plugins>
46 <plugin>
47 <groupId>org.springframework.boot</groupId>
48 <artifactId>spring-boot-maven-plugin</artifactId>
49 </plugin>
50 </plugins>
51 </build>
52 </project>
Page 1
index.jsp
Page 1
home.jsp
Page 1
seller.jsp
Page 1
WebSecurityConfig.java
1 package com.ecommerce.webSecurity;
2
3 import org.springframework.beans.factory.annotation.Autowired;
9
10 @EnableWebSecurity
11 @Configuration
12 public class WebSecurityConfig{
13
14 @Autowired
15 public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
{
16 PasswordEncoder encoder =
PasswordEncoderFactories.createDelegatingPasswordEncoder();
17
18 auth.inMemoryAuthentication()
19 .withUser("user").password(encoder.encode("password")).roles("USER")
20 .and()
21 .withUser("user1").password(encoder.encode("password1")).roles("USER")
22 .and()
23 .withUser("user2").password(encoder.encode("password2")).roles("USER")
24 .and()
25 .withUser("admin1").password(encoder.encode("adminpassword1")).roles
("ADMIN");
26 }
27 }
Page 1
Seller.java
1 package com.ecommerce.controller;
2
3 import org.springframework.stereotype.Controller;
5
6 @Controller
7 public class Seller {
8
9 @GetMapping("/displayseller")
10 public String displaySeller() {
11 return "seller/seller";
12 }
13 @GetMapping("displayhome")
14 public String displayHome() {
15 return "home/home";
16 }
17 }
Page 1