Exemplo n.º 1
0
 @Transactional
 // @Secured("ROLE_USER")
 public void createTransaction(BankingTx tx) {
   // add due to no insert trigger in sql server
   if (SobaConfig.getDatabaseVendor().equalsIgnoreCase("SQLServer")) {
     // System.out.println ("database vendor is SQL Server");
     double balance = accountManager.updateAccountBalance(tx.getAmount(), tx.getAccountId());
     tx.setBalance(balance);
   }
   aclBankingTxDao.insert(tx);
   addPermission(tx, new PrincipalSid(getCustomerUsername(tx)), BasePermission.READ);
   addPermission(tx, new GrantedAuthoritySid("ROLE_REP"), BasePermission.ADMINISTRATION);
   addPermission(tx, new GrantedAuthoritySid("ROLE_REP"), BasePermission.DELETE);
 }
Exemplo n.º 2
0
 @Transactional
 public void reverseTransaction(String txId) {
   BankingTx tx = aclBankingTxDao.findByTransactionID(txId);
   tx.setAmount(-tx.getAmount());
   tx.setDescription("Reversed: " + " amount = " + tx.getAmount() + " for " + tx.getDescription());
   tx.setTransactionId(Long.parseLong((new RandomID(9)).getId()));
   tx.setTransDate(new Timestamp(System.currentTimeMillis()));
   aclBankingTxDao.insert(tx);
   addPermission(tx, new PrincipalSid(getCustomerUsername(tx)), BasePermission.READ);
   addPermission(tx, new GrantedAuthoritySid("ROLE_REP"), BasePermission.ADMINISTRATION);
   addPermission(tx, new GrantedAuthoritySid("ROLE_REP"), BasePermission.DELETE);
 }
Exemplo n.º 3
0
  public void addPermission(BankingTx tx, Sid recipient, Permission permission) {
    MutableAcl acl;
    ObjectIdentity oid = new ObjectIdentityImpl(BankingTx.class, tx.getId());

    try {
      acl = (MutableAcl) mutableAclService.readAclById(oid);
    } catch (NotFoundException nfe) {
      System.out.println("oid=" + oid.toString());
      acl = mutableAclService.createAcl(oid);
    }

    acl.insertAce(acl.getEntries().size(), permission, recipient, true);
    mutableAclService.updateAcl(acl);
  }
Exemplo n.º 4
0
  public void deletePermission(BankingTx tx, Sid recipient, Permission permission) {
    ObjectIdentity oid = new ObjectIdentityImpl(BankingTx.class, tx.getTransactionId());
    MutableAcl acl = (MutableAcl) mutableAclService.readAclById(oid);

    // Remove all permissions associated with this particular recipient (string equality to KISS)
    List<AccessControlEntry> entries = acl.getEntries();

    for (int i = 0; i < entries.size(); i++) {
      if (entries.get(i).getSid().equals(recipient)
          && entries.get(i).getPermission().equals(permission)) {
        acl.deleteAce(i);
      }
    }

    mutableAclService.updateAcl(acl);
  }
Exemplo n.º 5
0
 private String getCustomerUsername(BankingTx tx) {
   String username = "";
   String authority =
       SecurityContextHolder.getContext().getAuthentication().getAuthorities().toString();
   if (authority.contains("ROLE_CUST")) {
     Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
     if (principal instanceof UserDetails) {
       username = ((UserDetails) principal).getUsername();
     } else {
       username = principal.toString();
     }
   } else {
     String accountId = tx.getAccountId();
     String customerId = accountDao.getCustomerId(accountId);
     username = loginUserDao.getUsernameByCustomerId(customerId);
   }
   return username;
 }