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;
import javax.ejb.Local;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LogEntry;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@Local
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 @@
*/
package fi.codecrew.moya.exceptions;
public class BortalCatchableException extends Exception {
import javax.ejb.EJBException;
public class BortalCatchableException extends EJBException {
private String i18nMessage;
......
......@@ -58,6 +58,7 @@ import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class BillBean
......@@ -96,7 +97,7 @@ public class BillBean implements BillBeanLocal {
@EJB
private DiscountBean discountBean;
@EJB
private LoggingBeanLocal logbean;
......@@ -229,10 +230,9 @@ public class BillBean implements BillBeanLocal {
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 when
......@@ -243,61 +243,57 @@ public class BillBean implements BillBeanLocal {
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private Bill markPaidSafeTransaction(Bill bill, Calendar when, boolean useCredits) throws BillException {
bill = billFacade.reload(bill);
if (bill.getAccountEvent() != null || bill.getPaidDate() != null) {
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());
logbean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Tried to mark already paid bill as paid: " + 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();
EventUser user = bill.getUser();
if(useCredits) {
if (useCredits) {
// check if there is enought credits
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());
throw new BillExceptionNotEnoughtCredits("There is not enought credits to pay. , BillID: "+bill.getId());
if (bill.getUser().getAccountBalance().compareTo(bill.getTotalPrice()) < 1) {
logbean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Trying to pay bill with accountevents, and there is no saldo, 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 {
AccountEvent ac = productBean.createAccountEvent(creditproduct, bill.totalPrice(), user);
logger.info("Created creditentry. {}, userproducts {}", ac, user.getAccountEvents().size());
ac.setEventTime(when);
ac.setBill(bill);
ac.setSeller(permbean.getCurrentUser());
bill.setAccountEvent(ac);
}
bill.setPaidDate(when.getTime());
return bill;
}
@Override
@RolesAllowed({ BillPermission.S_WRITE_ALL,
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();
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");
}
// bill = billFacade.merge(bill);
......@@ -315,9 +311,9 @@ public class BillBean implements BillBeanLocal {
}
}
billFacade.flush();
/*
MailMessage msg = new MailMessage();
......@@ -329,11 +325,11 @@ public class BillBean implements BillBeanLocal {
msg.setTo(bill.getUser().getUser());
utilbean.sendMail(msg);
*/
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());
return bill;
}
......@@ -341,7 +337,7 @@ public class BillBean implements BillBeanLocal {
@RolesAllowed({ BillPermission.S_CREATE_BILL, BillPermission.S_WRITE_ALL })
public Bill createBill(Bill bill) {
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");
}
billFacade.create(bill);
......@@ -358,7 +354,7 @@ public class BillBean implements BillBeanLocal {
@RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_READ_ALL })
public List<Bill> find(EventUser user) {
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");
}
return billFacade.find(user);
......@@ -368,7 +364,7 @@ public class BillBean implements BillBeanLocal {
@RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL })
public Bill expireBill(Bill bill) {
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");
}
......
......@@ -65,6 +65,7 @@ import fi.codecrew.moya.model.LanEventPrivatePropertyKey;
import fi.codecrew.moya.util.CheckoutBank;
import fi.codecrew.moya.util.CheckoutReturnType;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class CheckoutFiBean
......@@ -308,7 +309,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
String[] splittedStamp = stamp.split(STAMP_SPLITCHAR);
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;
}
......@@ -321,17 +322,17 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
switch (returnType)
{
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
ret = true;
break;
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
ret = true;
break;
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
ret = true;
break;
......@@ -352,29 +353,29 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
{
logger.info("Trying to mark bill {} paid", bill);
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;
} 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;
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;
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!");
}
}
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 {
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;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class SessionHandlerBean
......@@ -65,9 +66,6 @@ public class JaasBean implements MoyaRealmBeanRemote {
private EventUserFacade eventUserFacade;
@EJB
private LoggingBeanLocal secubean;
@EJB
private UserBean userbean;
@EJB
private PermissionBeanLocal permbean;
......@@ -83,6 +81,9 @@ public class JaasBean implements MoyaRealmBeanRemote {
@EJB
private EventBean eventorgbean;
@EJB
private LoggingBeanLocal secubean;
public EventUser tryLogin(String username, String password) {
// username = username.trim().toLowerCase();
......@@ -104,7 +105,8 @@ public class JaasBean implements MoyaRealmBeanRemote {
if (user.isAnonymous()) {
logger.info("logging in as anonymous!!!");
} 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;
user = null;
}
......@@ -124,7 +126,7 @@ public class JaasBean implements MoyaRealmBeanRemote {
eventUser.setCreator(eventUser);
}
} 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;
......
......@@ -75,6 +75,7 @@ import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
*
......@@ -303,7 +304,7 @@ public class PlaceBean implements PlaceBeanLocal {
user = permbean.getCurrentUser();
} else {
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");
}
user = eventUserFacade.reload(user);
......@@ -564,7 +565,8 @@ public class PlaceBean implements PlaceBeanLocal {
place.getGroup().getPlaces().remove(place);
}
place.setGroup(null);
place.setCurrentUser(null);
if (place.getPlaceReserver() != null)
{
GroupMembership res = place.getPlaceReserver();
......@@ -700,6 +702,8 @@ public class PlaceBean implements PlaceBeanLocal {
@Override
public List<EventMap> getMaps() {
return eventMapFacade.getMaps();
}
@Override
public List<PlaceSlot> getFreePlaceslots(EventUser user) {
user = eventUserFacade.reload(user);
......
......@@ -52,6 +52,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.BarcodeUtils;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class PlaceGroupBean
......@@ -293,7 +294,7 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal {
gmem = gmemfacade.reload(gmem);
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");
}
gmem.setUser(null);
......
......@@ -62,6 +62,7 @@ import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.model.ProductLimitation;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class ProductBean
......@@ -462,7 +463,7 @@ public class ProductBean implements ProductBeanLocal {
EventUser ret = acco.getUser();
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.getUser().getAccountEvents().remove(acco);
if (acco.getBill() != null) {
......
......@@ -47,6 +47,7 @@ import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.ApplicationPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
*
......@@ -241,7 +242,7 @@ public class RoleBean implements RoleBeanLocal {
@RolesAllowed(SpecialPermission.S_USER)
public List<Role> getRoles(EventUser selectedUser) {
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");
}
return roleFacade.findForUser(selectedUser);
......
......@@ -92,6 +92,7 @@ import fi.codecrew.moya.utilities.I18n;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.SearchQuery;
import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@LocalBean
@Stateless
......@@ -185,7 +186,7 @@ public class UserBean implements UserBeanLocal {
@RolesAllowed(SpecialPermission.S_USER)
public EventUser mergeChanges(EventUser user) {
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");
}
......@@ -200,7 +201,7 @@ public class UserBean implements UserBeanLocal {
EventUser currusr = permbean.getCurrentUser();
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");
}
......@@ -286,7 +287,7 @@ public class UserBean implements UserBeanLocal {
EventUser curruser = permbean.getCurrentUser();
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");
}
......
......@@ -62,6 +62,7 @@ import fi.codecrew.moya.model.LanEventPrivatePropertyKey;
import fi.codecrew.moya.util.SvmReturnType;
import fi.codecrew.moya.util.VerkkomaksutReturnEntry;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
import fi.codecrew.moya.verkkomaksutfi.PaymentEntry;
/**
......@@ -122,22 +123,22 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
{
// If bill is unpaid, mark it paid...
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
&& bill.getPaidDate() == null
&& (SvmReturnType.NOTIFICATION.equals(type) || SvmReturnType.SUCCESS.equals(type))) {
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;
} 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;
}
} 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 {
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 {
VerkkomaksutReturnEntry ret = sendMessage(message, merchantid, merchantPassword);
if (ret != null)
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 {
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;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.BotBean;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
/**
* Message-Driven Bean implementation class for: IrcBotTopicListener
......
......@@ -17,8 +17,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@Stateless
@JMSDestinationDefinition(name = MoyaEventSender.MOYA_EVENT_SENDER_TOPIC,
......@@ -29,7 +32,7 @@ import fi.codecrew.moya.model.EventUser;
)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
//@TransactionManagement(value = TransactionManagementType.CONTAINER)
public class MoyaEventSender {
public class MoyaEventSender implements LoggingBeanLocal {
static final String MOYA_EVENT_TOPIC_DESTINATION = "moyaEventTopic";
......@@ -48,11 +51,13 @@ public class MoyaEventSender {
private static final Logger logger = LoggerFactory.getLogger(MoyaEventSender.class);
@Override
public void sendMessage(MoyaEventMessage moyaMessage) {
ObjectMessage msg = context.createObjectMessage(moyaMessage);
context.createProducer().send(topic, msg);
}
@Override
public void sendMessage(MoyaEventType type, EventUser user, String message) {
MoyaEventMessage msg = new MoyaEventMessage();
......@@ -65,4 +70,5 @@ public class MoyaEventSender {
logger.info("Sending Moya message {} with description ", type, message);
sendMessage(msg);
}
}
......@@ -44,6 +44,7 @@ import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LogEntry;
import fi.codecrew.moya.model.LogEntryType;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
/**
* Session Bean implementation class SercurityBean
......
......@@ -50,8 +50,6 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
cq.where(cb.equal(root.get(EventMap_.event), eventbean.getCurrentEvent()),
cb.isTrue(root.get(EventMap_.active)));
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.util.Calendar;
......
package fi.codecrew.moya.beans.moyamessage;
package fi.codecrew.moya.utilities.moyamessage;
public enum MoyaEventType {
LOGIN_FAILED(MoyaEventSource.USER),
......@@ -6,6 +6,12 @@ public enum MoyaEventType {
USER_INSUFFICIENT_PERMISSIONS(MoyaEventSource.USER),
BILL_CREATED(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 {
}
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!