-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from ohbus/develop
push version 0.1.0 to master
- Loading branch information
Showing
78 changed files
with
15,863 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/xyz/subho/retail/banking/config/RequestFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
68
src/main/java/xyz/subho/retail/banking/config/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
src/main/java/xyz/subho/retail/banking/controller/AccountController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.