Skip to content

Commit

Permalink
Merge pull request #43 from jeffreybakker/fixes
Browse files Browse the repository at this point in the history
fix all of the new bugs that have come up since v2.0
  • Loading branch information
jeffreybakker authored Aug 3, 2017
2 parents c11b177 + abc9225 commit 3fa9f12
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 109 deletions.
75 changes: 5 additions & 70 deletions banq.iml
Original file line number Diff line number Diff line change
Expand Up @@ -16,76 +16,11 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.11" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.11" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.24" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.24" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.5.11" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:8.5.11" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.5.11" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-validator:5.3.4.Final" level="project" />
<orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.0.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.3" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.7" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.3.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.3.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.3.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.7.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:1.5.2.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:1.5.2.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:1.5.2.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:2.6.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:1.10.19" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.4.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.7.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:4.3.7.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:5.0.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.24" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-jpa:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.8.9" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-jdbc:8.5.11" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-juli:8.5.11" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:4.3.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.0.12.Final" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
<orderEntry type="library" name="Maven: org.jboss:jandex:2.0.0.Final" level="project" />
<orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.0.1.Final" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-entitymanager:5.0.12.Final" level="project" />
<orderEntry type="library" name="Maven: javax.transaction:javax.transaction-api:1.2" level="project" />
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:1.11.1.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:1.13.1.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-orm:4.3.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-tx:4.3.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.24" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aspects:4.3.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.41" level="project" />
<orderEntry type="library" name="Maven: com.github.briandilley.jsonrpc4j:jsonrpc4j:1.5.0" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: net.iharder:base64:2.3.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.7" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents.client5:httpclient5:5.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents.core5:httpcore5:5.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents.client5:httpclient5:5.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents.core5:httpcore5:5.0-alpha1" level="project" />
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/honours/ing/banq/access/AccessServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public NewCardBean provideAccess(String authToken, String iBAN, String username)
long accountNumber = IBANUtil.getAccountNumber(iBAN);
BankAccount account = accountRepository.findOne((int) accountNumber);

if (account == null) {
throw new InvalidParamValueError("Account does not exist");
}

if (!account.getPrimaryHolder().equals(customer)) {
throw new NotAuthorizedError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface BankAccountRepository extends JpaRepository<BankAccount, Intege
@Query("SELECT account FROM BankAccount account JOIN account.holders holder WHERE holder.id = ?1")
List<BankAccount> findBankAccountsByHolders(int customer);

BankAccount findBankAccountsByPrimaryHolder(Customer customer);
@Query("SELECT account FROM BankAccount account WHERE account.primaryHolder.id = ?1")
List<BankAccount> findBankAccountsByPrimaryHolder(int customer);

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,14 @@ public void closeAccount(String authToken, String iBAN) throws NotAuthorizedErro
cardRepository.delete(cards);

repository.delete(account);

// Delete the customer if that is needed
List<BankAccount> primaryAccounts = repository.findBankAccountsByPrimaryHolder(customer.getId());
List<BankAccount> holderAccounts = repository.findBankAccountsByHolders(customer.getId());

if (primaryAccounts.size() == 0 && holderAccounts.size() == 0) {
auth.deleteForCustomer(customer);
customerRepository.delete(customer);
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/honours/ing/banq/auth/AuthRepository.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package honours.ing.banq.auth;

import honours.ing.banq.customer.Customer;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

/**
* @author jeffrey
* @since 14-5-17
Expand All @@ -10,4 +13,6 @@ public interface AuthRepository extends JpaRepository<Authentication, Long> {

Authentication findByToken(String token);

List<Authentication> findByCustomer(Customer customer);

}
2 changes: 2 additions & 0 deletions src/main/java/honours/ing/banq/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface AuthService {

AuthToken getAuthToken(@JsonRpcParam("username") String username, @JsonRpcParam("password") String password) throws AuthenticationError;

void deleteForCustomer(Customer customer);

Customer getAuthorizedCustomer(String token) throws NotAuthorizedError;
BankAccount getAuthorizedAccount(String iBAN, String pinCard, String pinCode) throws InvalidPINError;

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/honours/ing/banq/auth/AuthServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.Calendar;
import java.util.List;
import java.util.Objects;
import java.util.Random;

Expand Down Expand Up @@ -70,6 +71,12 @@ public AuthToken getAuthToken(String username, String password) throws Authentic
return new AuthToken(auth.getToken());
}

@Override
public void deleteForCustomer(Customer customer) {
List<Authentication> authenticationList = repository.findByCustomer(customer);
repository.delete(authenticationList);
}

@Override
public Customer getAuthorizedCustomer(String token) throws NotAuthorizedError {
if (token == null || token.length() == 0) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/honours/ing/banq/info/InfoServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ public List<UserAccessBean> getUserAccess(String authToken) throws NotAuthorized
}

List<BankAccount> accounts = bankAccountRepository.findBankAccountsByHolders(customer.getId());
BankAccount primaryAccount = bankAccountRepository.findBankAccountsByPrimaryHolder(customer);
accounts.addAll(bankAccountRepository.findBankAccountsByPrimaryHolder(customer.getId()));

List<UserAccessBean> userAccessBeanList = new ArrayList<>();
for (BankAccount account : accounts) {
userAccessBeanList.add(new UserAccessBean(account, account.getPrimaryHolder()));
}

userAccessBeanList.add(new UserAccessBean(primaryAccount, primaryAccount.getPrimaryHolder()));

return userAccessBeanList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,7 @@ public void depositIntoAccount(String iBAN, String pinCard, String pinCode, Doub
throw new InvalidParamValueError("The given IBAN is not valid.");
}

BankAccount bankAccount = bankAccountRepository.findOne((int) IBANUtil.getAccountNumber
(iBAN));
Card card = cardRepository.findByAccountAndCardNumber(bankAccount, pinCard);

// Check for card matching iBAN
if (card == null) {
throw new InvalidParamValueError("The given card does not belong to the given iBAN.");
}

// Check pin code
if (!Objects.equals(card.getPin(), pinCode)) {
throw new InvalidPINError();
}
BankAccount bankAccount = auth.getAuthorizedAccount(iBAN, pinCard, pinCode);

// Check balance
if (amount <= 0d) {
Expand All @@ -80,8 +68,8 @@ public void depositIntoAccount(String iBAN, String pinCard, String pinCode, Doub
}

@Override
public void payFromAccount(String sourceIBAN, String targetIBAN, String pinCard, String
pinCode, Double amount) throws InvalidParamValueError, InvalidPINError {
public void payFromAccount(String sourceIBAN, String targetIBAN, String pinCard, String pinCode, Double amount)
throws InvalidParamValueError, InvalidPINError {
if (!IBANUtil.isValidIBAN(sourceIBAN)) {
throw new InvalidParamValueError("The given source IBAN is not valid.");
}
Expand All @@ -90,21 +78,8 @@ public void payFromAccount(String sourceIBAN, String targetIBAN, String pinCard,
throw new InvalidParamValueError("The given target IBAN is not valid.");
}

BankAccount fromBankAccount = bankAccountRepository.findOne((int) IBANUtil
.getAccountNumber(sourceIBAN));
BankAccount toBankAccount = bankAccountRepository.findOne((int) IBANUtil.getAccountNumber
(targetIBAN));
Card card = cardRepository.findByAccountAndCardNumber(fromBankAccount, pinCard);

// Check for card matching iBAN
if (card == null) {
throw new InvalidParamValueError("The given card does not belong to the given iBAN.");
}

// Check pin code
if (!Objects.equals(card.getPin(), pinCode)) {
throw new InvalidPINError();
}
BankAccount fromBankAccount = auth.getAuthorizedAccount(sourceIBAN, pinCard, pinCode);
BankAccount toBankAccount = bankAccountRepository.findOne((int) IBANUtil.getAccountNumber(targetIBAN));

// Check balance
if (fromBankAccount.getBalance() - amount < 0) {
Expand All @@ -128,9 +103,8 @@ public void payFromAccount(String sourceIBAN, String targetIBAN, String pinCard,
}

@Override
public void transferMoney(String authToken, String sourceIBAN, String targetIBAN, String
targetName, Double amount, String description) throws InvalidParamValueError,
NotAuthorizedError {
public void transferMoney(String authToken, String sourceIBAN, String targetIBAN, String targetName,
Double amount, String description) throws InvalidParamValueError, NotAuthorizedError {
if (!IBANUtil.isValidIBAN(sourceIBAN)) {
throw new InvalidParamValueError("The given source IBAN is not valid.");
}
Expand All @@ -146,8 +120,7 @@ public void transferMoney(String authToken, String sourceIBAN, String targetIBAN
Customer customer = auth.getAuthorizedCustomer(authToken);

// Check if bank account is held by customer
if (!fromBankAccount.getHolders().contains(customer) && !fromBankAccount.getPrimaryHolder
().equals(customer)) {
if (!fromBankAccount.getHolders().contains(customer) && !fromBankAccount.getPrimaryHolder().equals(customer)) {
throw new NotAuthorizedError();
}

Expand Down

0 comments on commit 3fa9f12

Please sign in to comment.