Commit e5e5b82c by Tuomas Riihimäki

logging fixes after merge

1 parent 45d28884
...@@ -37,6 +37,7 @@ import fi.codecrew.moya.model.EventUser; ...@@ -37,6 +37,7 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.FoodWave; import fi.codecrew.moya.model.FoodWave;
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 ProductPBean * Session Bean implementation class ProductPBean
...@@ -59,9 +60,8 @@ public class ProductPBean { ...@@ -59,9 +60,8 @@ public class ProductPBean {
@EJB @EJB
private ProductFacade productFacade; private ProductFacade productFacade;
@EJB @EJB
private LoggingBean lbean; private LoggingBeanLocal lbean;
private static final Logger logger = LoggerFactory private static final Logger logger = LoggerFactory
.getLogger(ProductPBean.class); .getLogger(ProductPBean.class);
...@@ -104,24 +104,23 @@ public class ProductPBean { ...@@ -104,24 +104,23 @@ public class ProductPBean {
throw new EJBException("Trying to create accountevent for different event in user and product"); throw new EJBException("Trying to create accountevent for different event in user and product");
} }
BigDecimal unitPrice = product.getPrice().negate(); BigDecimal unitPrice = product.getPrice().negate();
List<Discount> discounts = new ArrayList<>(); List<Discount> discounts = new ArrayList<>();
if(overriddenUnitPrice != null && BigDecimal.ZERO.compareTo(overriddenUnitPrice) < 0) { if (overriddenUnitPrice != null && BigDecimal.ZERO.compareTo(overriddenUnitPrice) < 0) {
unitPrice = overriddenUnitPrice; unitPrice = overriddenUnitPrice;
lbean.sendMessage(MoyaEventType.ACCOUNTEVENT_INFO, permbean.getCurrentUser(), "User creating accountevent with discount");
// lbean.logMessage(SecurityLogType.accountEvent, permbean.getCurrentUser(), "User creating accountevent with discount");
} else {
lbean.logMessage(SecurityLogType.accountEvent, permbean.getCurrentUser(), "User creating accountevent with discount"); // no discounts if custom price
} else { discounts = discountBean.getActiveDiscountsByProduct(product, quantity, date, user);
for (Discount d : discounts) {
// no discounts if custom price unitPrice = unitPrice.multiply(d.getPercentage());
discounts = discountBean.getActiveDiscountsByProduct(product, quantity, date, user); }
for (Discount d : discounts) { }
unitPrice = unitPrice.multiply(d.getPercentage());
}
}
AccountEvent ret = new AccountEvent(user, product, unitPrice, quantity, Calendar.getInstance()); AccountEvent ret = new AccountEvent(user, product, unitPrice, quantity, Calendar.getInstance());
...@@ -159,7 +158,7 @@ public class ProductPBean { ...@@ -159,7 +158,7 @@ public class ProductPBean {
// flush changes to db. // flush changes to db.
// userFacade.flush(); // userFacade.flush();
lbean.logMessage(SecurityLogType.accountEvent, permbean.getCurrentUser(), "User created accountevent: ", ret.getId()); lbean.sendMessage(MoyaEventType.ACCOUNTEVENT_INFO, permbean.getCurrentUser(), "User created accountevent: ", ret.getId());
return ret; return ret;
} }
} }
...@@ -406,7 +406,7 @@ public class UserBean implements UserBeanLocal { ...@@ -406,7 +406,7 @@ public class UserBean implements UserBeanLocal {
} else { } else {
ret = userimagefacade.find(id); ret = userimagefacade.find(id);
if (ret != null && !permbean.isCurrentUser(ret.getUser()) && permbean.hasPermission(UserPermission.MODIFY)) { if (ret != null && !permbean.isCurrentUser(ret.getUser()) && permbean.hasPermission(UserPermission.MODIFY)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enough rights to access image id: " + id + " for user " + ret.getUser()); loggerbean.sendMessage(MoyaEventType.USER_INSUFFICIENT_PERMISSIONS, permbean.getCurrentUser(), "Not enough rights to access image id: ", id, " for user ", ret.getUser());
throw new EJBAccessException("Not enough permissions to fetch image"); throw new EJBAccessException("Not enough permissions to fetch image");
} }
...@@ -698,7 +698,7 @@ public class UserBean implements UserBeanLocal { ...@@ -698,7 +698,7 @@ public class UserBean implements UserBeanLocal {
// At the very least it safeguards the situation if user gets another // At the very least it safeguards the situation if user gets another
// users gameid in somehow.. // users gameid in somehow..
if (!permbean.isCurrentUser(gi.getEventUser())) { if (!permbean.isCurrentUser(gi.getEventUser())) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to remove GameID from another user: " + gi.getEventUser()); loggerbean.sendMessage(MoyaEventType.USER_INSUFFICIENT_PERMISSIONS, permbean.getCurrentUser(), "User tried to remove GameID from another user: ", gi.getEventUser());
throw new EJBAccessException("Not enough rights to remove another users' GameIDs"); throw new EJBAccessException("Not enough rights to remove another users' GameIDs");
} }
...@@ -727,7 +727,7 @@ public class UserBean implements UserBeanLocal { ...@@ -727,7 +727,7 @@ public class UserBean implements UserBeanLocal {
@RolesAllowed(SpecialPermission.S_USER) @RolesAllowed(SpecialPermission.S_USER)
public EventUser mergeEventUserChanges(EventUser user) { public EventUser mergeEventUserChanges(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_INSUFFICIENT_PERMISSIONS, 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");
} }
......
...@@ -71,4 +71,14 @@ public class MoyaEventSender implements LoggingBeanLocal { ...@@ -71,4 +71,14 @@ public class MoyaEventSender implements LoggingBeanLocal {
sendMessage(msg); sendMessage(msg);
} }
@Override
public void sendMessage(MoyaEventType type, EventUser user, Object... message) {
StringBuilder sb = new StringBuilder();
for (Object m : message) {
sb.append(m);
}
sendMessage(type, user, sb.toString());
}
} }
...@@ -54,6 +54,7 @@ import fi.codecrew.moya.enums.apps.MapPermission; ...@@ -54,6 +54,7 @@ import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap; import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place; import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
* *
...@@ -145,7 +146,7 @@ public class PlaceMapServlet extends HttpServlet { ...@@ -145,7 +146,7 @@ public class PlaceMapServlet extends HttpServlet {
if (!permbean.hasPermission(MapPermission.VIEW)) if (!permbean.hasPermission(MapPermission.VIEW))
{ {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), loggerbean.sendMessage(MoyaEventType.USER_INSUFFICIENT_PERMISSIONS, permbean.getCurrentUser(),
"User tried to print the placemap to stream without sufficient permissions"); "User tried to print the placemap to stream without sufficient permissions");
throw new EJBAccessException("Not enough permissions to print placemap"); throw new EJBAccessException("Not enough permissions to print placemap");
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!