Skip to content

Commit

Permalink
Merge pull request #32 from ohbus/develop
Browse files Browse the repository at this point in the history
push version 0.1.0 to master
  • Loading branch information
ohbus authored Jun 17, 2020
2 parents 3a0b653 + bf2ccd1 commit 8ffad4b
Show file tree
Hide file tree
Showing 78 changed files with 15,863 additions and 10 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM openjdk:11-jre-slim

LABEL maintainer="Subhrodip Mohanta"
LABEL email="[email protected]"
LABEL application="Retail Banking"

COPY target/retail.banking-0.1.0.jar /usr/local/retail.banking/

EXPOSE 8080

CMD ["java", "-jar", "/usr/local/retail.banking/retail.banking-0.1.0.jar"]
40 changes: 30 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,44 @@
</parent>
<groupId>xyz.subho</groupId>
<artifactId>retail.banking</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.1.0</version>
<name>retail.banking</name>
<description>Retail banking project using MVC for TCS Case Study using Agile Methodologies</description>

<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Subhrodip Apache Maven Packages</name>
<url>https://maven.pkg.github.com/ohbus/Retail-Banking</url>
</repository>
</distributionManagement>

<properties>
<java.version>11</java.version>
</properties>

<dependencies>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -43,11 +59,13 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -59,11 +77,13 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xyz/subho/retail/banking/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args);

}

}
54 changes: 54 additions & 0 deletions src/main/java/xyz/subho/retail/banking/config/RequestFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package xyz.subho.retail.banking.config;

import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class RequestFilter implements Filter {

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {
HttpServletResponse response = (HttpServletResponse) res;
HttpServletRequest request = (HttpServletRequest) req;

response.setHeader("Access-Control-Allow-Origin", "http://localhost:4200");
response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Credentials", "true");

if (!(request.getMethod().equalsIgnoreCase("OPTIONS"))) {
try {
chain.doFilter(req, res);
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("Pre-flight");
response.setHeader("Access-Control-Allow-Methods", "POST,GET,DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "authorization, content-type," +
"access-control-request-headers,access-control-request-method,accept,origin,authorization,x-requested-with");
response.setStatus(HttpServletResponse.SC_OK);
}

}

public void init(FilterConfig filterConfig) {
//System.out.println("Filter init Method Executed");
}

public void destroy() {
//System.out.println("Filter destroy Method Executed");
}

}
68 changes: 68 additions & 0 deletions src/main/java/xyz/subho/retail/banking/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package xyz.subho.retail.banking.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import xyz.subho.retail.banking.service.serviceImpl.UserSecurityServiceImpl;

import java.security.SecureRandom;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

/*
* @Autowired private Environment env;
*/

private static final String SALT = "salt"; // Salt should be protected carefully

private static final String[] PUBLIC_MATCHERS = { "/webjars/**", "/css/**", "/js/**", "/images/**", "/",
"/about/**", "/contact/**", "/error/**/*", "/console/**", "/signup", "/admin/**" };


@Autowired
private UserSecurityServiceImpl userSecurityService;


@Bean
public BCryptPasswordEncoder passwordEncoder() {

return new BCryptPasswordEncoder(12, new SecureRandom(SALT.getBytes()));

}

@Override
protected void configure(HttpSecurity http) throws Exception {

http.authorizeRequests()
// .antMatchers("/**")
.antMatchers(PUBLIC_MATCHERS).permitAll().anyRequest().authenticated();

http.csrf().disable().cors().disable().formLogin().failureUrl("/index?error").defaultSuccessUrl("/userFront")
.loginPage("/index").permitAll().and().logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/index?logout")
.deleteCookies("remember-me").permitAll().and().rememberMe();

}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

// auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
// //This is in-memory authentication

auth.userDetailsService(userSecurityService).passwordEncoder(passwordEncoder());

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package xyz.subho.retail.banking.controller;

import java.security.Principal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import xyz.subho.retail.banking.model.CurrentAccount;
import xyz.subho.retail.banking.model.CurrentTransaction;
import xyz.subho.retail.banking.model.SavingsAccount;
import xyz.subho.retail.banking.model.SavingsTransaction;
import xyz.subho.retail.banking.model.User;
import xyz.subho.retail.banking.service.AccountService;
import xyz.subho.retail.banking.service.TransactionService;
import xyz.subho.retail.banking.service.UserService;

@Controller
@RequestMapping("/account")
public class AccountController {

@Autowired
private UserService userService;

@Autowired
private AccountService accountService;

@Autowired
private TransactionService transactionService;

@RequestMapping("/currentAccount")
public String currentAccount(Model model, Principal principal) {

List<CurrentTransaction> currentTransactionList = transactionService.findCurrentTransactionList(principal.getName());

User user = userService.findByUsername(principal.getName());
CurrentAccount currentAccount = user.getCurrentAccount();

model.addAttribute("currentAccount", currentAccount);
model.addAttribute("currentTransactionList", currentTransactionList);

return "currentAccount";

}

@RequestMapping("/savingsAccount")
public String savingsAccount(Model model, Principal principal) {

List<SavingsTransaction> savingsTransactionList = transactionService.findSavingsTransactionList(principal.getName());
User user = userService.findByUsername(principal.getName());
SavingsAccount savingsAccount = user.getSavingsAccount();

model.addAttribute("savingsAccount", savingsAccount);
model.addAttribute("savingsTransactionList", savingsTransactionList);

return "savingsAccount";

}

@RequestMapping(value = "/deposit", method = RequestMethod.GET)
public String deposit(Model model) {

model.addAttribute("accountType", "");
model.addAttribute("amount", "");

return "deposit";

}

@RequestMapping(value = "/deposit", method = RequestMethod.POST)
public String depositPOST(@ModelAttribute("amount") String amount, @ModelAttribute("accountType") String accountType, Principal principal) {

accountService.deposit(accountType, Double.parseDouble(amount), principal);

return "redirect:/userFront";

}

@RequestMapping(value = "/withdraw", method = RequestMethod.GET)
public String withdraw(Model model) {

model.addAttribute("accountType", "");
model.addAttribute("amount", "");

return "withdraw";

}

@RequestMapping(value = "/withdraw", method = RequestMethod.POST)
public String withdrawPOST(@ModelAttribute("amount") String amount, @ModelAttribute("accountType") String accountType, Principal principal) {

accountService.withdraw(accountType, Double.parseDouble(amount), principal);

return "redirect:/userFront";

}

}
Loading

0 comments on commit 8ffad4b

Please sign in to comment.