Skip to content

Commit 8ec62e8

Browse files
committed
Initial Commit
1 parent a933c19 commit 8ec62e8

File tree

106 files changed

+13885
-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.

106 files changed

+13885
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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.3.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.wissensalt.test</groupId>
12+
<artifactId>spring-angular-registration</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>spring-angular-registration</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>javax.validation</groupId>
24+
<artifactId>validation-api</artifactId>
25+
<!--<version>2.0.1.Final</version>-->
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-data-jpa</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-security</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-web</artifactId>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.postgresql</groupId>
42+
<artifactId>postgresql</artifactId>
43+
<scope>runtime</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.projectlombok</groupId>
47+
<artifactId>lombok</artifactId>
48+
<optional>true</optional>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-test</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.springframework.security</groupId>
57+
<artifactId>spring-security-test</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
</dependencies>
61+
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-maven-plugin</artifactId>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
71+
<repositories>
72+
<repository>
73+
<id>spring-snapshots</id>
74+
<name>Spring Snapshots</name>
75+
<url>https://repo.spring.io/snapshot</url>
76+
<snapshots>
77+
<enabled>true</enabled>
78+
</snapshots>
79+
</repository>
80+
<repository>
81+
<id>spring-milestones</id>
82+
<name>Spring Milestones</name>
83+
<url>https://repo.spring.io/milestone</url>
84+
</repository>
85+
</repositories>
86+
<pluginRepositories>
87+
<pluginRepository>
88+
<id>spring-snapshots</id>
89+
<name>Spring Snapshots</name>
90+
<url>https://repo.spring.io/snapshot</url>
91+
<snapshots>
92+
<enabled>true</enabled>
93+
</snapshots>
94+
</pluginRepository>
95+
<pluginRepository>
96+
<id>spring-milestones</id>
97+
<name>Spring Milestones</name>
98+
<url>https://repo.spring.io/milestone</url>
99+
</pluginRepository>
100+
</pluginRepositories>
101+
102+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.wissensalt.test.sar;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/*@ComponentScan(basePackages = {
7+
"com.wissensalt.test.sar.dao",
8+
"com.wissensalt.test.sar.endpoint",
9+
"com.wissensalt.test.sar.service",
10+
"com.wissensalt.test.sar.mapper",
11+
"com.wissensalt.test.sar.validation",
12+
}, lazyInit = true)
13+
@EntityScan(basePackages = {"com.wissensalt.test.sar.model"})
14+
@EnableJpaRepositories(basePackages = {"com.wissensalt.test.sar.dao"})*/
15+
@SpringBootApplication
16+
public class SpringAngularRegistrationApplication {
17+
18+
public static void main(String[] args) {
19+
SpringApplication.run(SpringAngularRegistrationApplication.class, args);
20+
}
21+
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.wissensalt.test.sar.auditrail;
2+
3+
import com.wissensalt.test.sar.model.base.ABaseAuditTrail;
4+
import lombok.AccessLevel;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
8+
9+
import javax.persistence.EntityListeners;
10+
import javax.persistence.MappedSuperclass;
11+
import javax.persistence.Transient;
12+
13+
@MappedSuperclass
14+
@EntityListeners(AuditingEntityListener.class)
15+
public abstract class AAuditTrail extends ABaseAuditTrail {
16+
/**
17+
*
18+
*
19+
*/
20+
private static final long serialVersionUID = -5401587542468260575L;
21+
22+
@Getter(AccessLevel.NONE)
23+
@Setter(AccessLevel.NONE)
24+
@Transient
25+
private AppAuditorAware auditorAware;
26+
27+
public AAuditTrail() {
28+
auditorAware = new AppAuditorAware();
29+
}
30+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.wissensalt.test.sar.auditrail;
2+
3+
import org.springframework.data.domain.AuditorAware;
4+
import org.springframework.security.core.context.SecurityContextHolder;
5+
import org.springframework.stereotype.Component;
6+
7+
import java.io.Serializable;
8+
import java.util.Optional;
9+
10+
/**
11+
* Created on 2/27/19.
12+
*
13+
* @author <a href="mailto:fauzi.knightmaster.achmad@gmail.com">Achmad Fauzi</a>
14+
*/
15+
@Component
16+
public class AppAuditorAware implements AuditorAware<String>, Serializable {
17+
/**
18+
*
19+
*
20+
*/
21+
private static final long serialVersionUID = 3916619591736957909L;
22+
23+
@Override
24+
public Optional<String> getCurrentAuditor() {
25+
String userName;
26+
try{
27+
userName = SecurityContextHolder.getContext().getAuthentication().getName();
28+
}catch (Exception e) {
29+
userName = "PUBLIC_USER";
30+
}
31+
32+
return Optional.of(userName);
33+
}
34+
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.wissensalt.test.sar.config;
2+
3+
import org.springframework.security.core.AuthenticationException;
4+
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
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+
import java.io.PrintWriter;
12+
13+
/**
14+
* Created on 4/28/18.
15+
*
16+
* @author <a href="mailto:fauzi.knightmaster.achmad@gmail.com">Achmad Fauzi</a>
17+
*/
18+
@Component
19+
public class BasicAuthEntryPoint extends BasicAuthenticationEntryPoint {
20+
21+
@Override
22+
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
23+
response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName());
24+
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
25+
PrintWriter writer = response.getWriter();
26+
writer.println("HTTP STATUS 401 - "+ authException.getMessage());
27+
}
28+
29+
@Override
30+
public void afterPropertiesSet() throws Exception {
31+
setRealmName("SECURED-BASIC-REALM");
32+
super.afterPropertiesSet();
33+
}
34+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.wissensalt.test.sar.config;
2+
3+
import org.springframework.web.filter.GenericFilterBean;
4+
5+
import javax.servlet.FilterChain;
6+
import javax.servlet.ServletException;
7+
import javax.servlet.ServletRequest;
8+
import javax.servlet.ServletResponse;
9+
import javax.servlet.http.HttpServletResponse;
10+
import java.io.IOException;
11+
12+
/**
13+
* Created on 5/11/18.
14+
*
15+
* @author <a href="mailto:fauzi.knightmaster.achmad@gmail.com">Achmad Fauzi</a>
16+
*/
17+
public class CorsFilter extends GenericFilterBean {
18+
@Override
19+
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
20+
HttpServletResponse response = (HttpServletResponse) servletResponse;
21+
response.setHeader("Access-Control-Allow-Origin", "*");
22+
response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE");
23+
response.setHeader("Access-Control-Max-Age", "3600");
24+
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Content-Length, X-Requested-With");
25+
filterChain.doFilter(servletRequest, servletResponse);
26+
}
27+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.wissensalt.test.sar.config;
2+
3+
import com.wissensalt.test.sar.service.impl.CustomUserDetailService;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
8+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
9+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
10+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
11+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
12+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
13+
import org.springframework.security.crypto.password.PasswordEncoder;
14+
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
15+
import org.springframework.web.cors.CorsConfiguration;
16+
import org.springframework.web.cors.CorsConfigurationSource;
17+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
18+
19+
import java.util.Arrays;
20+
21+
import static com.wissensalt.test.sar.statval.ISarConstant.RoleName.ADMIN;
22+
23+
/**
24+
* Created on 4/27/18.
25+
*
26+
* @author <a href="mailto:fauzi.knightmaster.achmad@gmail.com">Achmad Fauzi</a>
27+
*/
28+
@Configuration
29+
@EnableWebSecurity
30+
public class SecurityConfig extends WebSecurityConfigurerAdapter {
31+
32+
@Autowired
33+
private BasicAuthEntryPoint basicAuthEntryPoint;
34+
35+
@Bean
36+
public PasswordEncoder passwordEncoder () {
37+
return new BCryptPasswordEncoder();
38+
}
39+
40+
@Autowired
41+
private CustomUserDetailService customUserDetailService;
42+
43+
@Override
44+
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
45+
auth
46+
.authenticationProvider(authenticationProvider());
47+
}
48+
49+
@Bean
50+
public DaoAuthenticationProvider authenticationProvider() {
51+
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
52+
provider.setUserDetailsService(customUserDetailService);
53+
provider.setPasswordEncoder(passwordEncoder());
54+
return provider;
55+
}
56+
57+
@Override
58+
protected void configure(HttpSecurity http) throws Exception {
59+
http
60+
.authorizeRequests()
61+
.antMatchers("/registration/*").permitAll()
62+
.antMatchers("/auth/*").permitAll()
63+
.antMatchers("/api/*").hasRole(ADMIN)
64+
.anyRequest().authenticated()
65+
.and()
66+
.httpBasic().authenticationEntryPoint(basicAuthEntryPoint)
67+
.and()
68+
.csrf().disable();
69+
70+
71+
http.addFilterAfter(new CorsFilter(), BasicAuthenticationFilter.class);
72+
}
73+
74+
@Bean
75+
CorsConfigurationSource corsConfigurationSource()
76+
{
77+
CorsConfiguration configuration = new CorsConfiguration();
78+
configuration.setAllowedOrigins(Arrays.asList("http://localhost:4200"));
79+
configuration.setAllowedMethods(Arrays.asList("GET", "POST"));
80+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
81+
source.registerCorsConfiguration("/**", configuration);
82+
return source;
83+
}
84+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.wissensalt.test.sar.dao;
2+
3+
import com.wissensalt.test.sar.exception.DAOException;
4+
import com.wissensalt.test.sar.model.Role;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
7+
/**
8+
* Created on 5/8/19.
9+
*
10+
* @author <a href="mailto:fauzi.knightmaster.achmad@gmail.com">Achmad Fauzi</a>
11+
*/
12+
public interface IRoleDAO extends JpaRepository<Role, Long> {
13+
14+
Role findByName(String p_Name) throws DAOException;
15+
16+
Role findByCode(String p_Code) throws DAOException;
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.wissensalt.test.sar.dao;
2+
3+
import com.wissensalt.test.sar.exception.DAOException;
4+
import com.wissensalt.test.sar.model.User;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
7+
/**
8+
* Created on 5/8/19.
9+
*
10+
* @author <a href="mailto:fauzi.knightmaster.achmad@gmail.com">Achmad Fauzi</a>
11+
*/
12+
public interface IUserDAO extends JpaRepository<User, Long> {
13+
14+
User findByMobileNumber(String p_MobileNumber) throws DAOException;
15+
16+
User findByEmail(String p_Email) throws DAOException;
17+
18+
User findByCodeAndStatus(String p_Code, Boolean p_Status)throws DAOException;
19+
20+
User findByCodeOrEmail(String p_Code, String p_Email) throws DAOException;
21+
}

0 commit comments

Comments
 (0)