Commit 45d28884 by Tuomas Riihimäki

Move logging over jms

1 parent 417092e2
Showing with 108 additions and 81 deletions
...@@ -21,15 +21,20 @@ package fi.codecrew.moya.beans; ...@@ -21,15 +21,20 @@ package fi.codecrew.moya.beans;
import javax.ejb.Local; import javax.ejb.Local;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
import fi.codecrew.moya.model.LogEntry; import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
import fi.codecrew.moya.model.User;
@Local @Local
public interface LoggingBeanLocal { public interface LoggingBeanLocal {
//
// LogEntry logMessage(SecurityLogType paramType, LanEvent event, User user, Object... description);
//
// LogEntry logMessage(SecurityLogType paramType, EventUser user, Object... description);
LogEntry logMessage(SecurityLogType paramType, LanEvent event, User user, Object... description); void sendMessage(MoyaEventMessage moyaMessage);
LogEntry logMessage(SecurityLogType paramType, EventUser user, Object... description); void sendMessage(MoyaEventType type, EventUser user, String message);
void sendMessage(MoyaEventType type, EventUser user, Object... message);
} }
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
*/ */
package fi.codecrew.moya.exceptions; package fi.codecrew.moya.exceptions;
public class BortalCatchableException extends Exception { import javax.ejb.EJBException;
public class BortalCatchableException extends EJBException {
private String i18nMessage; private String i18nMessage;
......
...@@ -58,6 +58,7 @@ import fi.codecrew.moya.model.FoodWave; ...@@ -58,6 +58,7 @@ import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag; import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
* Session Bean implementation class BillBean * Session Bean implementation class BillBean
...@@ -96,7 +97,7 @@ public class BillBean implements BillBeanLocal { ...@@ -96,7 +97,7 @@ public class BillBean implements BillBeanLocal {
@EJB @EJB
private DiscountBean discountBean; private DiscountBean discountBean;
@EJB @EJB
private LoggingBeanLocal logbean; private LoggingBeanLocal logbean;
...@@ -229,10 +230,9 @@ public class BillBean implements BillBeanLocal { ...@@ -229,10 +230,9 @@ public class BillBean implements BillBeanLocal {
return ret; return ret;
} }
/** /**
* We will mark bill paid in different transaction. That's because we don't wont it to fail if something other fails. * We will mark bill paid in different transaction. That's because we don't
* wont it to fail if something other fails.
* *
* @param bill * @param bill
* @param when * @param when
...@@ -243,61 +243,57 @@ public class BillBean implements BillBeanLocal { ...@@ -243,61 +243,57 @@ public class BillBean implements BillBeanLocal {
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private Bill markPaidSafeTransaction(Bill bill, Calendar when, boolean useCredits) throws BillException { private Bill markPaidSafeTransaction(Bill bill, Calendar when, boolean useCredits) throws BillException {
bill = billFacade.reload(bill); bill = billFacade.reload(bill);
if (bill.getAccountEvent() != null || bill.getPaidDate() != null) { if (bill.getAccountEvent() != null || bill.getPaidDate() != null) {
logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Trying to doublemark bill paid", bill.getId()); logbean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Tried to mark already paid bill as paid: " + bill.getId());
throw new BillExceptionAlreadyPaid("Trying to mark bill paid, already paid, BillID: "+bill.getId()); // logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Trying to doublemark bill paid", bill.getId());
throw new BillExceptionAlreadyPaid("Trying to mark bill paid, already paid, BillID: " + bill.getId());
} }
Product creditproduct = productBean.findCreditProduct(); Product creditproduct = productBean.findCreditProduct();
EventUser user = bill.getUser(); EventUser user = bill.getUser();
if (useCredits) {
if(useCredits) {
// check if there is enought credits // check if there is enought credits
if(bill.getUser().getAccountBalance().compareTo(bill.getTotalPrice()) < 1) { if (bill.getUser().getAccountBalance().compareTo(bill.getTotalPrice()) < 1) {
logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Trying to pay bill with accountevents, and there is no saldo, billid: ", bill.getId()); logbean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Trying to pay bill with accountevents, and there is no saldo, billid: " + bill.getId());
throw new BillExceptionNotEnoughtCredits("There is not enought credits to pay. , BillID: "+bill.getId());
// logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Trying to pay bill with accountevents, and there is no saldo, billid: ", bill.getId());
throw new BillExceptionNotEnoughtCredits("There is not enought credits to pay. , BillID: " + bill.getId());
} }
} else { } else {
AccountEvent ac = productBean.createAccountEvent(creditproduct, bill.totalPrice(), user); AccountEvent ac = productBean.createAccountEvent(creditproduct, bill.totalPrice(), user);
logger.info("Created creditentry. {}, userproducts {}", ac, user.getAccountEvents().size()); logger.info("Created creditentry. {}, userproducts {}", ac, user.getAccountEvents().size());
ac.setEventTime(when); ac.setEventTime(when);
ac.setBill(bill); ac.setBill(bill);
ac.setSeller(permbean.getCurrentUser()); ac.setSeller(permbean.getCurrentUser());
bill.setAccountEvent(ac); bill.setAccountEvent(ac);
} }
bill.setPaidDate(when.getTime()); bill.setPaidDate(when.getTime());
return bill; return bill;
} }
@Override @Override
@RolesAllowed({ BillPermission.S_WRITE_ALL, @RolesAllowed({ BillPermission.S_WRITE_ALL,
SpecialPermission.S_VERKKOMAKSU_CHECK }) SpecialPermission.S_VERKKOMAKSU_CHECK })
public Bill markPaid(Bill bill, Calendar when, boolean useCredits) throws BillException { public Bill markPaid(Bill bill, Calendar when, boolean useCredits) throws BillException {
bill = markPaidSafeTransaction(bill, when, useCredits);
bill = markPaidSafeTransaction(bill, when,useCredits);
EventUser user = bill.getUser(); EventUser user = bill.getUser();
if (bill.isFoowavePaymentOver() && !permbean.hasPermission(ShopPermission.MANAGE_FOODWAVES)) if (bill.isFoowavePaymentOver() && !permbean.hasPermission(ShopPermission.MANAGE_FOODWAVES))
{ {
logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "FoodwaveClosed and marking bill for it paid"); logbean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "FoodwaveClosed and marking bill for it paid. Billid: " + bill.getId());
throw new EJBException("Trying to mark paid a closed or left foodwave"); throw new EJBException("Trying to mark paid a closed or left foodwave");
} }
// bill = billFacade.merge(bill); // bill = billFacade.merge(bill);
...@@ -315,9 +311,9 @@ public class BillBean implements BillBeanLocal { ...@@ -315,9 +311,9 @@ public class BillBean implements BillBeanLocal {
} }
} }
billFacade.flush(); billFacade.flush();
/* /*
MailMessage msg = new MailMessage(); MailMessage msg = new MailMessage();
...@@ -329,11 +325,11 @@ public class BillBean implements BillBeanLocal { ...@@ -329,11 +325,11 @@ public class BillBean implements BillBeanLocal {
msg.setTo(bill.getUser().getUser()); msg.setTo(bill.getUser().getUser());
utilbean.sendMail(msg); utilbean.sendMail(msg);
*/ */
eventUserFacade.flush(); eventUserFacade.flush();
logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Marking bill paid, for user: ", bill.getUser().getId(),"BillId: ",bill.getId()); logbean.sendMessage(MoyaEventType.BILL_PAID, permbean.getCurrentUser(), "Marking bill paid, for user: ", bill.getUser().getId(), "BillId: ", bill.getId());
eventUserFacade.evict(bill.getUser()); eventUserFacade.evict(bill.getUser());
return bill; return bill;
} }
...@@ -341,7 +337,7 @@ public class BillBean implements BillBeanLocal { ...@@ -341,7 +337,7 @@ public class BillBean implements BillBeanLocal {
@RolesAllowed({ BillPermission.S_CREATE_BILL, BillPermission.S_WRITE_ALL }) @RolesAllowed({ BillPermission.S_CREATE_BILL, BillPermission.S_WRITE_ALL })
public Bill createBill(Bill bill) { public Bill createBill(Bill bill) {
if (!permbean.isCurrentUser(bill.getUser()) && !permbean.hasPermission(BillPermission.WRITE_ALL)) { if (!permbean.isCurrentUser(bill.getUser()) && !permbean.hasPermission(BillPermission.WRITE_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to create bill for user "); loggingBean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Not enought rights to create bill for user: ", bill.getUser());
throw new EJBAccessException("Could not create bill for another user"); throw new EJBAccessException("Could not create bill for another user");
} }
billFacade.create(bill); billFacade.create(bill);
...@@ -358,7 +354,7 @@ public class BillBean implements BillBeanLocal { ...@@ -358,7 +354,7 @@ public class BillBean implements BillBeanLocal {
@RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_READ_ALL }) @RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_READ_ALL })
public List<Bill> find(EventUser user) { public List<Bill> find(EventUser user) {
if (!permbean.isCurrentUser(user) && !permbean.hasPermission(BillPermission.READ_ALL)) { if (!permbean.isCurrentUser(user) && !permbean.hasPermission(BillPermission.READ_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to get bill list for user "); loggingBean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Not enought rights to get bill list for user ", user);
throw new EJBAccessException("Could not list bills for another user"); throw new EJBAccessException("Could not list bills for another user");
} }
return billFacade.find(user); return billFacade.find(user);
...@@ -368,7 +364,7 @@ public class BillBean implements BillBeanLocal { ...@@ -368,7 +364,7 @@ public class BillBean implements BillBeanLocal {
@RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL }) @RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL })
public Bill expireBill(Bill bill) { public Bill expireBill(Bill bill) {
if (!permbean.isCurrentUser(bill.getUser()) && !permbean.hasPermission(BillPermission.WRITE_ALL)) { if (!permbean.isCurrentUser(bill.getUser()) && !permbean.hasPermission(BillPermission.WRITE_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to expire a bill for user "); loggingBean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Not enought rights to expire a bill for user", bill);
throw new EJBAccessException("Could not list bills for another user"); throw new EJBAccessException("Could not list bills for another user");
} }
......
...@@ -65,6 +65,7 @@ import fi.codecrew.moya.model.LanEventPrivatePropertyKey; ...@@ -65,6 +65,7 @@ import fi.codecrew.moya.model.LanEventPrivatePropertyKey;
import fi.codecrew.moya.util.CheckoutBank; import fi.codecrew.moya.util.CheckoutBank;
import fi.codecrew.moya.util.CheckoutReturnType; import fi.codecrew.moya.util.CheckoutReturnType;
import fi.codecrew.moya.utilities.PasswordFunctions; import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
* Session Bean implementation class CheckoutFiBean * Session Bean implementation class CheckoutFiBean
...@@ -308,7 +309,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -308,7 +309,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
String[] splittedStamp = stamp.split(STAMP_SPLITCHAR); String[] splittedStamp = stamp.split(STAMP_SPLITCHAR);
if (splittedStamp.length != 2) if (splittedStamp.length != 2)
{ {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Unable to split stamp ", stamp, " with splitchar ", STAMP_SPLITCHAR); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Unable to split stamp '", stamp, "' with splitchar ", STAMP_SPLITCHAR);
return false; return false;
} }
...@@ -321,17 +322,17 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -321,17 +322,17 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
switch (returnType) switch (returnType)
{ {
case CANCEL: case CANCEL:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "received cancel for stamp ", stamp); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "received cancel for stamp ", stamp);
// Return true when checksum was correct // Return true when checksum was correct
ret = true; ret = true;
break; break;
case DELAYED: case DELAYED:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "received delayed for stamp ", stamp); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "received delayed for stamp ", stamp);
// Return true when checksum was correct // Return true when checksum was correct
ret = true; ret = true;
break; break;
case REJECT: case REJECT:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "received reject for stamp ", stamp); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "received reject for stamp ", stamp);
// Return true when checksum was correct // Return true when checksum was correct
ret = true; ret = true;
break; break;
...@@ -352,29 +353,29 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -352,29 +353,29 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
{ {
logger.info("Trying to mark bill {} paid", bill); logger.info("Trying to mark bill {} paid", bill);
vmrunner.markPaid(bill, Calendar.getInstance()); vmrunner.markPaid(bill, Calendar.getInstance());
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Marking bill paid. Received bill status ", statusInt, " for bill ", bill, " stamp ", stamp, " payment: ", payment, " reference ", reference); logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Marking bill paid from checkout. Received bill status ", statusInt, " for bill ", bill, " stamp ", stamp, " payment: ", payment, " reference ", reference);
ret = true; ret = true;
} else { } else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Bill already marked paid: ", bill, " status ", status, " stamp ", stamp, " payment ", payment); logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Bill already marked paid: ", bill, " status ", status, " stamp ", stamp, " payment ", payment);
} }
break; break;
default: default:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Not marking bill paid: Return status ", status, " for bill ", bill, " stamp ", stamp, " payment ", payment); logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Not marking bill paid because of invalid status: Return status ", status, " for bill ", bill, " stamp ", stamp, " payment ", payment);
break; break;
} }
break; break;
default: default:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Valid mac, but Invalid return type: ", returnType, " for stamp ", stamp, " payment ", payment, " status ", status); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Valid mac, but Invalid return type: ", returnType, " for stamp ", stamp, " payment ", payment, " status ", status);
throw new EJBException("Unknown return type!"); throw new EJBException("Unknown return type!");
} }
} }
else { else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Validated mac, but bill not found for id: ", splittedStamp[0], " stamp ", stamp, " mac: ", mac); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Validated mac, but bill not found for id: ", splittedStamp[0], " stamp ", stamp, " mac: ", mac);
} }
} else { } else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Unable to validate order reference: ", reference, " calculated checksum: ", calculatedMac, " version ", version, " stamp ", stamp, " status ", status, " mac ", mac); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Unable to validate order reference: ", reference, " calculated checksum: ", calculatedMac, " version ", version, " stamp ", stamp, " status ", status, " mac ", mac);
} }
......
...@@ -49,6 +49,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey; ...@@ -49,6 +49,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.PasswordFunctions; import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
* Session Bean implementation class SessionHandlerBean * Session Bean implementation class SessionHandlerBean
...@@ -65,9 +66,6 @@ public class JaasBean implements MoyaRealmBeanRemote { ...@@ -65,9 +66,6 @@ public class JaasBean implements MoyaRealmBeanRemote {
private EventUserFacade eventUserFacade; private EventUserFacade eventUserFacade;
@EJB @EJB
private LoggingBeanLocal secubean;
@EJB
private UserBean userbean; private UserBean userbean;
@EJB @EJB
private PermissionBeanLocal permbean; private PermissionBeanLocal permbean;
...@@ -83,6 +81,9 @@ public class JaasBean implements MoyaRealmBeanRemote { ...@@ -83,6 +81,9 @@ public class JaasBean implements MoyaRealmBeanRemote {
@EJB @EJB
private EventBean eventorgbean; private EventBean eventorgbean;
@EJB
private LoggingBeanLocal secubean;
public EventUser tryLogin(String username, String password) { public EventUser tryLogin(String username, String password) {
// username = username.trim().toLowerCase(); // username = username.trim().toLowerCase();
...@@ -104,7 +105,8 @@ public class JaasBean implements MoyaRealmBeanRemote { ...@@ -104,7 +105,8 @@ public class JaasBean implements MoyaRealmBeanRemote {
if (user.isAnonymous()) { if (user.isAnonymous()) {
logger.info("logging in as anonymous!!!"); logger.info("logging in as anonymous!!!");
} else if (!user.checkPassword(password)) { } else if (!user.checkPassword(password)) {
secubean.logMessage(SecurityLogType.permissionDenied, eventUser, "Login failed: wrong password for username ", username);
secubean.sendMessage(MoyaEventType.LOGIN_FAILED, eventUser, "Login failed: wrong password for username ", username);
eventUser = null; eventUser = null;
user = null; user = null;
} }
...@@ -124,7 +126,7 @@ public class JaasBean implements MoyaRealmBeanRemote { ...@@ -124,7 +126,7 @@ public class JaasBean implements MoyaRealmBeanRemote {
eventUser.setCreator(eventUser); eventUser.setCreator(eventUser);
} }
} else { } else {
secubean.logMessage(SecurityLogType.permissionDenied, eventbean.getCurrentEvent(), null, "Login failed: Username not found: ", username); secubean.sendMessage(MoyaEventType.LOGIN_FAILED, eventUserFacade.findByLogin(User.ANONYMOUS_LOGINNAME), "Login failed: Username not found: ", username);
} }
return eventUser; return eventUser;
......
...@@ -75,6 +75,7 @@ import fi.codecrew.moya.model.PlaceGroup; ...@@ -75,6 +75,7 @@ import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PlaceSlot; import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag; import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
* *
...@@ -303,7 +304,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -303,7 +304,7 @@ public class PlaceBean implements PlaceBeanLocal {
user = permbean.getCurrentUser(); user = permbean.getCurrentUser();
} else { } else {
if (!user.equals(permbean.getCurrentUser()) && !permbean.hasPermission(MapPermission.MANAGE_OTHERS)) { if (!user.equals(permbean.getCurrentUser()) && !permbean.hasPermission(MapPermission.MANAGE_OTHERS)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Can not buy places for user " + user); loggerbean.sendMessage(MoyaEventType.PLACE_ERROR, permbean.getCurrentUser(), "Can not buy places for user " + user);
throw new EJBAccessException("Not enough permissions to buy place"); throw new EJBAccessException("Not enough permissions to buy place");
} }
user = eventUserFacade.reload(user); user = eventUserFacade.reload(user);
...@@ -564,7 +565,8 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -564,7 +565,8 @@ public class PlaceBean implements PlaceBeanLocal {
place.getGroup().getPlaces().remove(place); place.getGroup().getPlaces().remove(place);
} }
place.setGroup(null); place.setGroup(null);
place.setCurrentUser(null);
if (place.getPlaceReserver() != null) if (place.getPlaceReserver() != null)
{ {
GroupMembership res = place.getPlaceReserver(); GroupMembership res = place.getPlaceReserver();
...@@ -700,6 +702,8 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -700,6 +702,8 @@ public class PlaceBean implements PlaceBeanLocal {
@Override @Override
public List<EventMap> getMaps() { public List<EventMap> getMaps() {
return eventMapFacade.getMaps(); return eventMapFacade.getMaps();
}
@Override @Override
public List<PlaceSlot> getFreePlaceslots(EventUser user) { public List<PlaceSlot> getFreePlaceslots(EventUser user) {
user = eventUserFacade.reload(user); user = eventUserFacade.reload(user);
......
...@@ -52,6 +52,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey; ...@@ -52,6 +52,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup; import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.BarcodeUtils; import fi.codecrew.moya.utilities.BarcodeUtils;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
* Session Bean implementation class PlaceGroupBean * Session Bean implementation class PlaceGroupBean
...@@ -293,7 +294,7 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal { ...@@ -293,7 +294,7 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal {
gmem = gmemfacade.reload(gmem); gmem = gmemfacade.reload(gmem);
if (!(permbean.getCurrentUser().getId().equals(gmem.getPlaceGroup().getCreator().getId()) || permbean.hasPermission(MapPermission.MANAGE_OTHERS))) { if (!(permbean.getCurrentUser().getId().equals(gmem.getPlaceGroup().getCreator().getId()) || permbean.hasPermission(MapPermission.MANAGE_OTHERS))) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to release and generate group membership: " + gmem); loggerbean.sendMessage(MoyaEventType.PLACE_ERROR, permbean.getCurrentUser(), "User tried to release and generate group membership: " + gmem);
throw new EJBAccessException("Not enough rights to release token"); throw new EJBAccessException("Not enough rights to release token");
} }
gmem.setUser(null); gmem.setUser(null);
......
...@@ -62,6 +62,7 @@ import fi.codecrew.moya.model.Product; ...@@ -62,6 +62,7 @@ import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag; import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.model.ProductLimitation; import fi.codecrew.moya.model.ProductLimitation;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
* Session Bean implementation class ProductBean * Session Bean implementation class ProductBean
...@@ -462,7 +463,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -462,7 +463,7 @@ public class ProductBean implements ProductBeanLocal {
EventUser ret = acco.getUser(); EventUser ret = acco.getUser();
ret.getAccountEvents().remove(acco); ret.getAccountEvents().remove(acco);
loggingbean.logMessage(SecurityLogType.accountEvent, permbean.getCurrentUser(), "Deleting AccountEvent '", acco.getProduct().getName(), "' count: '", acco.getQuantity().toString(), "' unitprice: '", acco.getUnitPrice().toString(), "' accouser: '", acco.getUser().getUser().getLogin(), "'"); loggingbean.sendMessage(MoyaEventType.ACCOUNTEVENT_INFO, permbean.getCurrentUser(), "Deleting AccountEvent '", acco.getProduct().getName(), "' count: '", acco.getQuantity().toString(), "' unitprice: '", acco.getUnitPrice().toString(), "' accouser: '", acco.getUser().getUser().getLogin(), "'");
acco.getProduct().getAccountEvents().remove(acco); acco.getProduct().getAccountEvents().remove(acco);
acco.getUser().getAccountEvents().remove(acco); acco.getUser().getAccountEvents().remove(acco);
if (acco.getBill() != null) { if (acco.getBill() != null) {
......
...@@ -47,6 +47,7 @@ import fi.codecrew.moya.facade.UserFacade; ...@@ -47,6 +47,7 @@ import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.ApplicationPermission; import fi.codecrew.moya.model.ApplicationPermission;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
* *
...@@ -241,7 +242,7 @@ public class RoleBean implements RoleBeanLocal { ...@@ -241,7 +242,7 @@ public class RoleBean implements RoleBeanLocal {
@RolesAllowed(SpecialPermission.S_USER) @RolesAllowed(SpecialPermission.S_USER)
public List<Role> getRoles(EventUser selectedUser) { public List<Role> getRoles(EventUser selectedUser) {
if (!permbean.isCurrentUser(selectedUser) && !permbean.hasPermission(UserPermission.READ_ROLES)) { if (!permbean.isCurrentUser(selectedUser) && !permbean.hasPermission(UserPermission.READ_ROLES)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to touch another user roles: " + selectedUser); loggerbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION, permbean.getCurrentUser(), "User tried to touch another user roles: " + selectedUser);
throw new EJBAccessException("Not enough rights to read user permissions"); throw new EJBAccessException("Not enough rights to read user permissions");
} }
return roleFacade.findForUser(selectedUser); return roleFacade.findForUser(selectedUser);
......
...@@ -92,6 +92,7 @@ import fi.codecrew.moya.utilities.I18n; ...@@ -92,6 +92,7 @@ import fi.codecrew.moya.utilities.I18n;
import fi.codecrew.moya.utilities.PasswordFunctions; import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.SearchQuery; import fi.codecrew.moya.utilities.SearchQuery;
import fi.codecrew.moya.utilities.SearchResult; import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@LocalBean @LocalBean
@Stateless @Stateless
...@@ -185,7 +186,7 @@ public class UserBean implements UserBeanLocal { ...@@ -185,7 +186,7 @@ public class UserBean implements UserBeanLocal {
@RolesAllowed(SpecialPermission.S_USER) @RolesAllowed(SpecialPermission.S_USER)
public EventUser mergeChanges(EventUser user) { public EventUser mergeChanges(EventUser user) {
if (!permbean.isCurrentUser(user) && !permbean.hasPermission(UserPermission.MODIFY)) { if (!permbean.isCurrentUser(user) && !permbean.hasPermission(UserPermission.MODIFY)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to save another user: " + user); loggerbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION, permbean.getCurrentUser(), "User tried to save another user: " + user);
throw new EJBAccessException("Not enough rights to save user"); throw new EJBAccessException("Not enough rights to save user");
} }
...@@ -200,7 +201,7 @@ public class UserBean implements UserBeanLocal { ...@@ -200,7 +201,7 @@ public class UserBean implements UserBeanLocal {
EventUser currusr = permbean.getCurrentUser(); EventUser currusr = permbean.getCurrentUser();
if (!currusr.equals(u) && !permbean.hasPermission(UserPermission.MODIFY)) { if (!currusr.equals(u) && !permbean.hasPermission(UserPermission.MODIFY)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to fetc another users roles: " + u); loggerbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION, permbean.getCurrentUser(), "User tried to fetc another users roles: " + u);
throw new EJBAccessException("Not enough rights to find roles"); throw new EJBAccessException("Not enough rights to find roles");
} }
...@@ -286,7 +287,7 @@ public class UserBean implements UserBeanLocal { ...@@ -286,7 +287,7 @@ public class UserBean implements UserBeanLocal {
EventUser curruser = permbean.getCurrentUser(); EventUser curruser = permbean.getCurrentUser();
if (!curruser.equals(user) && !permbean.hasPermission(UserPermission.MODIFY)) { if (!curruser.equals(user) && !permbean.hasPermission(UserPermission.MODIFY)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, curruser, "user tried to save picture to userid " + user + " without sufficient permissions!"); loggerbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION, curruser, "user tried to save picture for userid " + user + " without sufficient permissions!");
throw new EJBAccessException("No permission to upload image as another user"); throw new EJBAccessException("No permission to upload image as another user");
} }
......
...@@ -62,6 +62,7 @@ import fi.codecrew.moya.model.LanEventPrivatePropertyKey; ...@@ -62,6 +62,7 @@ import fi.codecrew.moya.model.LanEventPrivatePropertyKey;
import fi.codecrew.moya.util.SvmReturnType; import fi.codecrew.moya.util.SvmReturnType;
import fi.codecrew.moya.util.VerkkomaksutReturnEntry; import fi.codecrew.moya.util.VerkkomaksutReturnEntry;
import fi.codecrew.moya.utilities.PasswordFunctions; import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
import fi.codecrew.moya.verkkomaksutfi.PaymentEntry; import fi.codecrew.moya.verkkomaksutfi.PaymentEntry;
/** /**
...@@ -122,22 +123,22 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal { ...@@ -122,22 +123,22 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
{ {
// If bill is unpaid, mark it paid... // If bill is unpaid, mark it paid...
if (SvmReturnType.PENDING.equals(type) || paid.equals("0000000000")) { if (SvmReturnType.PENDING.equals(type) || paid.equals("0000000000")) {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Received pending message ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode); logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Received pending message ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode);
} else if (bill.getAccountEvent() == null } else if (bill.getAccountEvent() == null
&& bill.getPaidDate() == null && bill.getPaidDate() == null
&& (SvmReturnType.NOTIFICATION.equals(type) || SvmReturnType.SUCCESS.equals(type))) { && (SvmReturnType.NOTIFICATION.equals(type) || SvmReturnType.SUCCESS.equals(type))) {
vmrunner.markPaid(bill, Calendar.getInstance()); vmrunner.markPaid(bill, Calendar.getInstance());
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Validated order number ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode); logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Validated order number ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode);
ret = true; ret = true;
} else { } else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Bill already marked paid or other error. ", orderNumber, " bill ", bill.toString(), " with authcode: ", authcode); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Bill already marked paid or other error. ", orderNumber, " bill ", bill.toString(), " with authcode: ", authcode);
ret = true; ret = true;
} }
} else { } else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Mac validated, but unable to find bill for order number ", orderNumber); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Mac validated, but unable to find bill for order number ", orderNumber);
} }
} else { } else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Unable to validate order number: ", orderNumber, " calculated checksum: ", calculatedHash, " authcode ", authcode, " paid ", paid, " method ", method); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Unable to validate order number: ", orderNumber, " calculated checksum: ", calculatedHash, " authcode ", authcode, " paid ", paid, " method ", method);
} }
...@@ -170,9 +171,9 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal { ...@@ -170,9 +171,9 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
VerkkomaksutReturnEntry ret = sendMessage(message, merchantid, merchantPassword); VerkkomaksutReturnEntry ret = sendMessage(message, merchantid, merchantPassword);
if (ret != null) if (ret != null)
if (ret.isError()) { if (ret.isError()) {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "User trieed to create new token for bill: ", bill.toString(), " but received error: ", ret.getErrorCode(), " message ", ret.getErrorMessage()); logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "User trieed to create new token for bill: ", bill.toString(), " but received error: ", ret.getErrorCode(), " message ", ret.getErrorMessage());
} else { } else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "User crated new token for bill: ", bill.toString(), " Got: ", ret.getOrderNumber(), " token ", ret.getToken()); logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "User crated new token for bill: ", bill.toString(), " Got: ", ret.getOrderNumber(), " token ", ret.getToken());
} }
......
...@@ -13,6 +13,7 @@ import org.slf4j.Logger; ...@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.BotBean; import fi.codecrew.moya.beans.BotBean;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
/** /**
* Message-Driven Bean implementation class for: IrcBotTopicListener * Message-Driven Bean implementation class for: IrcBotTopicListener
......
...@@ -17,8 +17,11 @@ import org.slf4j.Logger; ...@@ -17,8 +17,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@Stateless @Stateless
@JMSDestinationDefinition(name = MoyaEventSender.MOYA_EVENT_SENDER_TOPIC, @JMSDestinationDefinition(name = MoyaEventSender.MOYA_EVENT_SENDER_TOPIC,
...@@ -29,7 +32,7 @@ import fi.codecrew.moya.model.EventUser; ...@@ -29,7 +32,7 @@ import fi.codecrew.moya.model.EventUser;
) )
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
//@TransactionManagement(value = TransactionManagementType.CONTAINER) //@TransactionManagement(value = TransactionManagementType.CONTAINER)
public class MoyaEventSender { public class MoyaEventSender implements LoggingBeanLocal {
static final String MOYA_EVENT_TOPIC_DESTINATION = "moyaEventTopic"; static final String MOYA_EVENT_TOPIC_DESTINATION = "moyaEventTopic";
...@@ -48,11 +51,13 @@ public class MoyaEventSender { ...@@ -48,11 +51,13 @@ public class MoyaEventSender {
private static final Logger logger = LoggerFactory.getLogger(MoyaEventSender.class); private static final Logger logger = LoggerFactory.getLogger(MoyaEventSender.class);
@Override
public void sendMessage(MoyaEventMessage moyaMessage) { public void sendMessage(MoyaEventMessage moyaMessage) {
ObjectMessage msg = context.createObjectMessage(moyaMessage); ObjectMessage msg = context.createObjectMessage(moyaMessage);
context.createProducer().send(topic, msg); context.createProducer().send(topic, msg);
} }
@Override
public void sendMessage(MoyaEventType type, EventUser user, String message) { public void sendMessage(MoyaEventType type, EventUser user, String message) {
MoyaEventMessage msg = new MoyaEventMessage(); MoyaEventMessage msg = new MoyaEventMessage();
...@@ -65,4 +70,5 @@ public class MoyaEventSender { ...@@ -65,4 +70,5 @@ public class MoyaEventSender {
logger.info("Sending Moya message {} with description ", type, message); logger.info("Sending Moya message {} with description ", type, message);
sendMessage(msg); sendMessage(msg);
} }
} }
...@@ -44,6 +44,7 @@ import fi.codecrew.moya.model.LanEvent; ...@@ -44,6 +44,7 @@ import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LogEntry; import fi.codecrew.moya.model.LogEntry;
import fi.codecrew.moya.model.LogEntryType; import fi.codecrew.moya.model.LogEntryType;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
/** /**
* Session Bean implementation class SercurityBean * Session Bean implementation class SercurityBean
......
...@@ -50,8 +50,6 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> { ...@@ -50,8 +50,6 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
cq.where(cb.equal(root.get(EventMap_.event), eventbean.getCurrentEvent()), cq.where(cb.equal(root.get(EventMap_.event), eventbean.getCurrentEvent()),
cb.isTrue(root.get(EventMap_.active))); cb.isTrue(root.get(EventMap_.active)));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
}
return ret;
} }
......
package fi.codecrew.moya.beans.moyamessage; package fi.codecrew.moya.utilities.moyamessage;
import java.io.Serializable; import java.io.Serializable;
import java.util.Calendar; import java.util.Calendar;
......
package fi.codecrew.moya.beans.moyamessage; package fi.codecrew.moya.utilities.moyamessage;
public enum MoyaEventType { public enum MoyaEventType {
LOGIN_FAILED(MoyaEventSource.USER), LOGIN_FAILED(MoyaEventSource.USER),
...@@ -6,6 +6,12 @@ public enum MoyaEventType { ...@@ -6,6 +6,12 @@ public enum MoyaEventType {
USER_INSUFFICIENT_PERMISSIONS(MoyaEventSource.USER), USER_INSUFFICIENT_PERMISSIONS(MoyaEventSource.USER),
BILL_CREATED(MoyaEventSource.SHOP), BILL_CREATED(MoyaEventSource.SHOP),
BILL_PAID(MoyaEventSource.SHOP), BILL_PAID(MoyaEventSource.SHOP),
BILL_ERROR(MoyaEventSource.SHOP),
BANKING_ERROR(MoyaEventSource.SHOP),
BANKING_MESSAGE(MoyaEventSource.SHOP),
PLACE_ERROR(MoyaEventSource.PLACEMAP),
ACCOUNTEVENT_INFO(MoyaEventSource.USER),
USER_PERMISSION_VIOLATION(MoyaEventSource.USER),
; ;
...@@ -20,7 +26,7 @@ public enum MoyaEventType { ...@@ -20,7 +26,7 @@ public enum MoyaEventType {
} }
private static enum MoyaEventSource { private static enum MoyaEventSource {
USER, EVENT, SHOP USER, EVENT, SHOP, PLACEMAP
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!