Skip to content

Commit 6a70217

Browse files
committed
angular-ecommerce-starter
https://github.com/SaiUpadhyayula/SpringAngularEcommerce Elasticsearch example
1 parent ee83305 commit 6a70217

File tree

74 files changed

+384070
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+384070
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SpringAngularEcommerce
2+
SpringAngularEcommerce is a shopping cart application developed as a pet project to get to know about different technologies.
3+
4+
This project is still in development.
5+
6+
Code for Angular app: https://github.com/SaiUpadhyayula/NgSpringShoppingStore-frontend
7+
8+
#Features
9+
- Token Based User Authentication(JWT)
10+
- Product Search
11+
- Product Catalog
12+
- Payment Gateway (using Stripe) - TODO
13+
- Wishlist - TODO
14+
- Admin Console - TODO
15+
- Order Management - TODO
16+
- User Management - TODO
17+
- PDF Report Generation (Order Acknowledgment) - TODO
18+
19+
20+
#Technologies:
21+
- Spring Boot
22+
- Mongo DB
23+
- Angular
24+
- Redis for Caching
25+
- Elastic Search
26+
27+
#Images of Application:
28+
1. Home Page
29+
30+
![Home Page](https://github.com/SaiUpadhyayula/NgSpringShoppingStore/blob/master/src/main/resources/images/homepage.PNG)
31+
32+
2. Category Page
33+
34+
![Category Page](https://github.com/SaiUpadhyayula/NgSpringShoppingStore/blob/master/src/main/resources/images/category-page.PNG)
35+
36+
3. Category Page With Filters
37+
38+
![Category Page With Filters](https://github.com/SaiUpadhyayula/NgSpringShoppingStore/blob/master/src/main/resources/images/category-page-with-filters.PNG)
39+
40+
4. Product Page
41+
42+
![Product Page](https://github.com/SaiUpadhyayula/NgSpringShoppingStore/blob/master/src/main/resources/images/product-page.PNG)
43+
44+
5. Product Page - Review Section
45+
46+
![Product Page Review Section](https://github.com/SaiUpadhyayula/NgSpringShoppingStore/blob/master/src/main/resources/images/product-page-review-section.PNG)
47+
48+
6. Search Page
49+
![Search Page](https://github.com/SaiUpadhyayula/NgSpringShoppingStore/blob/master/src/main/resources/images/search-page.PNG)
50+
51+
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.1.1.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.techie.shoppingstore</groupId>
12+
<artifactId>NGSpringShoppingStore</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>NGSpringShoppingStore</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-actuator</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-cache</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.data</groupId>
32+
<artifactId>spring-data-mongodb</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-mail</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-security</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-web</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.security.oauth</groupId>
48+
<artifactId>spring-security-oauth2</artifactId>
49+
<version>2.3.5.RELEASE</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.springframework.security</groupId>
53+
<artifactId>spring-security-jwt</artifactId>
54+
<version>1.0.9.RELEASE</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.projectlombok</groupId>
58+
<artifactId>lombok</artifactId>
59+
<version>1.18.4</version>
60+
<scope>provided</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.springframework.boot</groupId>
64+
<artifactId>spring-boot-starter-test</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.springframework.security</groupId>
69+
<artifactId>spring-security-test</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>io.jsonwebtoken</groupId>
74+
<artifactId>jjwt-api</artifactId>
75+
<version>0.10.5</version>
76+
</dependency>
77+
<dependency>
78+
<groupId>io.jsonwebtoken</groupId>
79+
<artifactId>jjwt-impl</artifactId>
80+
<scope>runtime</scope>
81+
<version>0.10.5</version>
82+
</dependency>
83+
<dependency>
84+
<groupId>io.jsonwebtoken</groupId>
85+
<artifactId>jjwt-jackson</artifactId>
86+
<scope>runtime</scope>
87+
<version>0.10.5</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.springframework.boot</groupId>
91+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.springframework.boot</groupId>
95+
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
96+
</dependency>
97+
<dependency>
98+
<groupId>com.mashape.unirest</groupId>
99+
<artifactId>unirest-java</artifactId>
100+
<version>1.4.9</version>
101+
</dependency>
102+
<dependency>
103+
<groupId>org.elasticsearch.client</groupId>
104+
<artifactId>elasticsearch-rest-high-level-client</artifactId>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.springframework.boot</groupId>
108+
<artifactId>spring-boot-starter-data-redis</artifactId>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.mapstruct</groupId>
112+
<artifactId>mapstruct</artifactId>
113+
<version>1.3.0.Final</version>
114+
</dependency>
115+
</dependencies>
116+
117+
<build>
118+
<plugins>
119+
<plugin>
120+
<groupId>org.springframework.boot</groupId>
121+
<artifactId>spring-boot-maven-plugin</artifactId>
122+
</plugin>
123+
<plugin>
124+
<groupId>org.apache.maven.plugins</groupId>
125+
<artifactId>maven-compiler-plugin</artifactId>
126+
<version>3.5.1</version> <!-- or newer version -->
127+
<configuration>
128+
<source>1.8</source>
129+
<target>1.8</target>
130+
<annotationProcessorPaths>
131+
<path>
132+
<groupId>org.mapstruct</groupId>
133+
<artifactId>mapstruct-processor</artifactId>
134+
<version>1.3.0.Final</version>
135+
</path>
136+
<path>
137+
<groupId>org.projectlombok</groupId>
138+
<artifactId>lombok</artifactId>
139+
<version>1.18.4</version>
140+
</path>
141+
</annotationProcessorPaths>
142+
</configuration>
143+
</plugin>
144+
</plugins>
145+
</build>
146+
147+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.techie.shoppingstore;
2+
3+
import com.techie.shoppingstore.config.AppSecurityConfig;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.cache.annotation.EnableCaching;
7+
import org.springframework.context.annotation.Import;
8+
import org.springframework.scheduling.annotation.EnableAsync;
9+
10+
@SpringBootApplication
11+
@EnableCaching
12+
@EnableAsync
13+
@Import(AppSecurityConfig.class)
14+
public class NgSpringShoppingStoreApplication {
15+
16+
public static void main(String[] args) {
17+
SpringApplication.run(NgSpringShoppingStoreApplication.class, args);
18+
}
19+
20+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.techie.shoppingstore.config;
2+
3+
import com.techie.shoppingstore.repository.UserRepository;
4+
import com.techie.shoppingstore.service.JWTAuthenticationFilter;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.http.HttpMethod;
8+
import org.springframework.security.authentication.AuthenticationManager;
9+
import org.springframework.security.config.BeanIds;
10+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
11+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
12+
import org.springframework.security.config.annotation.web.builders.WebSecurity;
13+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
14+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
15+
import org.springframework.security.config.http.SessionCreationPolicy;
16+
import org.springframework.security.core.userdetails.UserDetailsService;
17+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
18+
import org.springframework.security.crypto.password.PasswordEncoder;
19+
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
20+
21+
@EnableWebSecurity
22+
public class AppSecurityConfig extends WebSecurityConfigurerAdapter {
23+
24+
@Autowired
25+
private UserRepository userRepository;
26+
@Autowired
27+
private UserDetailsService userDetailsService;
28+
@Autowired
29+
private UnauthorizedEntryPoint unauthorizedEntryPoint;
30+
@Autowired
31+
private CustomAccessDeniedHandler customAccessDeniedHandler;
32+
33+
@Bean
34+
public JWTAuthenticationFilter jwtAuthenticationFilter() {
35+
return new JWTAuthenticationFilter();
36+
}
37+
38+
@Bean(BeanIds.AUTHENTICATION_MANAGER)
39+
@Override
40+
public AuthenticationManager authenticationManagerBean() throws Exception {
41+
return super.authenticationManagerBean();
42+
}
43+
44+
@Override
45+
public void configure(WebSecurity web) {
46+
web.ignoring()
47+
.antMatchers(HttpMethod.OPTIONS, "/**");
48+
}
49+
50+
@Override
51+
public void configure(HttpSecurity httpSecurity) throws Exception {
52+
httpSecurity
53+
.cors()
54+
.and()
55+
.csrf()
56+
.disable()
57+
.exceptionHandling()
58+
.authenticationEntryPoint(unauthorizedEntryPoint)
59+
.and()
60+
.sessionManagement()
61+
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
62+
.and()
63+
.authorizeRequests()
64+
.antMatchers("/api/auth/**")
65+
.permitAll()
66+
.antMatchers("/api/store/catalog/**")
67+
.permitAll()
68+
.anyRequest().authenticated();
69+
70+
71+
// Add our custom JWT security filter
72+
httpSecurity.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
73+
}
74+
75+
@Autowired
76+
public void configureGlobal(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
77+
authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(encoder());
78+
}
79+
80+
@Bean
81+
PasswordEncoder encoder() {
82+
return new BCryptPasswordEncoder(12);
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.techie.shoppingstore.config;
2+
3+
import org.springframework.security.access.AccessDeniedException;
4+
import org.springframework.security.web.access.AccessDeniedHandler;
5+
import org.springframework.stereotype.Component;
6+
7+
import javax.servlet.ServletException;
8+
import javax.servlet.http.HttpServletRequest;
9+
import javax.servlet.http.HttpServletResponse;
10+
import java.io.IOException;
11+
12+
@Component
13+
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
14+
@Override
15+
public void handle(HttpServletRequest httpServletRequest,
16+
HttpServletResponse httpServletResponse,
17+
AccessDeniedException accessDeniedException) throws IOException, ServletException {
18+
httpServletResponse.setStatus(403);
19+
}
20+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.techie.shoppingstore.config;
2+
3+
import com.techie.shoppingstore.exceptions.SpringStoreException;
4+
import org.elasticsearch.client.Client;
5+
import org.elasticsearch.common.settings.Settings;
6+
import org.elasticsearch.common.transport.TransportAddress;
7+
import org.elasticsearch.transport.client.PreBuiltTransportClient;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
11+
12+
import java.net.InetAddress;
13+
import java.net.UnknownHostException;
14+
15+
@Configuration
16+
@EnableElasticsearchRepositories
17+
public class ElasticSearchConfig {
18+
19+
@Bean
20+
public Client client() {
21+
System.setProperty("es.set.netty.runtime.available.processors", "false");
22+
try {
23+
return new PreBuiltTransportClient(Settings.EMPTY)
24+
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
25+
26+
} catch (UnknownHostException e) {
27+
throw new SpringStoreException("An error occured when configuring Elastic Search");
28+
}
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.techie.shoppingstore.config;
2+
3+
import lombok.Data;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
@Data
9+
public class MailConfig {
10+
11+
@Value("${spring.mail.host}")
12+
private String host;
13+
@Value("${spring.mail.port}")
14+
private int port;
15+
@Value("${spring.mail.username}")
16+
private String username;
17+
@Value("${spring.mail.password}")
18+
private String password;
19+
20+
}

0 commit comments

Comments
 (0)