MoyaEventTopicLoggingBean.java
3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.beans.moyamessage;
import java.util.Calendar;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.transaction.UserTransaction;
import org.slf4j.Logger;
import fi.codecrew.moya.facade.LogEntryFacade;
import fi.codecrew.moya.facade.LogEntryTypeFacade;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.beans.SecurityLogType;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LogEntry;
import fi.codecrew.moya.model.LogEntryType;
import fi.codecrew.moya.model.User;
/**
* Session Bean implementation class SercurityBean
*/
@MessageDriven(mappedName = MoyaEventSender.MOYA_EVENT_SENDER_TOPIC)
public class MoyaEventTopicLoggingBean implements MessageListener {
private static final boolean DEBUG = true;
private final Logger logger = org.slf4j.LoggerFactory.getLogger(MoyaEventTopicLoggingBean.class);
@Override
public void onMessage(Message message) {
if (message != null) {
try {
MoyaEventMessage msg = message.getBody(MoyaEventMessage.class);
logger.warn("Got message at TopicLogging {}, {}", msg.getEventtype(), msg.getDescription());
} catch (JMSException e) {
logger.warn("Exception whie receiving Moya EventTopic", e);
}
}
}
@EJB
private EventBeanLocal eventbean;
public LogEntry logMessage(SecurityLogType paramType, LanEvent event, User user, Object... description) {
LogEntry entry = null;
if (event == null) {
event = eventbean.getCurrentEvent();
}
try {
String desc = toString(description);
logger.warn("Sending logmsg {}", desc);
//LogEntryType type = typeFacade.findOrCreate(paramType);
// entry = new LogEntry(Calendar.getInstance());
// entry.setParentEvent(event);
// entry.setType(type);
// entry.setDescription(desc);
// entry.setUser(user);
// entryFacade.create(entry);
String msg = "SECURITY DEBUG: Type: \"" + paramType.name() +
"\" user \"" + paramType.name() +
"\", description \"" + ((user == null) ? "null" : user.getLogin()) + "\"" + desc;
// sender.sendMessage(msg);
// utx.commit();
} catch (Exception e) {
logger.warn("Exception at SecurityBean", e);
}
return entry;
}
public LogEntry logMessage(SecurityLogType paramType, EventUser user, Object... description) {
LanEvent event = null;
User usr = null;
if (user != null)
{
event = user.getEvent();
usr = user.getUser();
}
return logMessage(paramType, event, usr, description);
}
private static final String toString(Object... desc) {
StringBuilder msg = new StringBuilder();
for (Object msgpart : desc) {
msg.append(msgpart);
}
return msg.toString();
}
}