Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Linnea Samila
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 43830184
authored
Dec 09, 2014
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master' into emailLogin
2 parents
33ce6414
af3f4f0f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
188 additions
and
62 deletions
code/moya-beans/ejbModule/fi/codecrew/moya/beans/JaasBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/moyamessage/IrcBotMoyaEventTopicListener.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/moyamessage/MoyaEventSender.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/moyamessage/MoyaEventTopicLoggingBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/facade/LanEventFacade.java
code/moya-beans/ejbModule/fi/codecrew/moya/facade/LogEntryTypeFacade.java
code/moya-parent/pom.xml
code/moya-utils/src/main/java/fi/codecrew/moya/utilities/SystemProperty.java
code/moya-utils/src/main/java/fi/codecrew/moya/utilities/moyamessage/MoyaEventMessage.java
code/moya-web/src/main/java/fi/codecrew/moya/servlet/IrcServlet.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/JaasBean.java
View file @
4383018
...
...
@@ -139,7 +139,10 @@ public class JaasBean implements MoyaRealmBeanRemote {
eventUserFacade
.
flush
();
eventUser
.
setCreator
(
eventUser
);
}
secubean
.
sendMessage
(
MoyaEventType
.
LOGIN_SUCCESSFULL
,
eventUser
,
"User logged in with username: '"
,
username
,
"' eventuser: "
,
eventUser
);
// jos logitetaan anomuumi, niin uuden tapahtuman luominen hajoaa jännästi.
if
(!
user
.
isAnonymous
())
secubean
.
sendMessage
(
MoyaEventType
.
LOGIN_SUCCESSFULL
,
eventUser
,
"User logged in with username: '"
,
username
,
"' eventuser: "
,
eventUser
);
}
else
{
secubean
.
sendMessage
(
MoyaEventType
.
LOGIN_FAILED
,
eventUserFacade
.
findByLogin
(
User
.
ANONYMOUS_LOGINNAME
),
"Login failed: Username not found: "
,
username
);
}
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/beans/moyamessage/IrcBotMoyaEventTopicListener.java
View file @
4383018
package
fi
.
codecrew
.
moya
.
beans
.
moyamessage
;
import
javax.ejb.ActivationConfigProperty
;
import
javax.ejb.EJB
;
import
javax.ejb.MessageDriven
;
import
javax.jms.JMSException
;
import
javax.jms.Message
;
import
javax.jms.MessageListener
;
import
javax.jms.ObjectMessage
;
import
javax.jms.TextMessage
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.beans.BotBean
;
import
fi.codecrew.moya.facade.EventFacade
;
import
fi.codecrew.moya.model.LanEvent
;
import
fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage
;
/**
...
...
@@ -26,13 +25,22 @@ public class IrcBotMoyaEventTopicListener implements MessageListener {
@EJB
private
BotBean
botbean
;
@EJB
private
EventFacade
eventfacade
;
/**
* @see MessageListener#onMessage(Message)
*/
public
void
onMessage
(
Message
message
)
{
try
{
MoyaEventMessage
msg
=
message
.
getBody
(
MoyaEventMessage
.
class
);
botbean
.
getBot
().
say
(
toString
(
"Got Message "
,
msg
.
getEventtype
(),
" msg: "
,
msg
.
getDescription
()));
String
event
=
"unknown event"
;
if
(
msg
.
getEventId
()
!=
null
)
{
LanEvent
e
=
eventfacade
.
find
(
msg
.
getEventId
());
if
(
e
!=
null
)
event
=
e
.
getName
();
}
botbean
.
getBot
().
say
(
toString
(
event
,
" "
,
msg
.
getEventtype
(),
" msg: "
,
msg
.
getDescription
()));
logger
.
warn
(
"Received moya event message for irc bot {}"
,
message
);
}
catch
(
JMSException
e
)
{
logger
.
warn
(
"Exception while getting jms message for IRCbot"
);
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/beans/moyamessage/MoyaEventSender.java
View file @
4383018
...
...
@@ -63,7 +63,7 @@ public class MoyaEventSender implements LoggingBeanLocal {
MoyaEventMessage
msg
=
new
MoyaEventMessage
();
msg
.
setEventtype
(
type
);
msg
.
setTime
(
Calendar
.
getInstance
());
msg
.
setUserId
(
user
.
getId
());
msg
.
set
Event
UserId
(
user
.
getId
());
msg
.
setCurrentUserId
(
permbean
.
getCurrentUser
().
getUser
().
getId
());
msg
.
setEventId
(
eventbean
.
getCurrentEvent
().
getId
());
msg
.
setDescription
(
message
);
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/beans/moyamessage/MoyaEventTopicLoggingBean.java
View file @
4383018
...
...
@@ -20,31 +20,26 @@ 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.beans.EventBeanLocal
;
import
fi.codecrew.moya.facade.EventUserFacade
;
import
fi.codecrew.moya.facade.LanEventFacade
;
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
;
import
fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage
;
import
fi.codecrew.moya.utilities.moyamessage.MoyaEventType
;
/**
* Session Bean implementation class SercurityBean
...
...
@@ -55,13 +50,26 @@ public class MoyaEventTopicLoggingBean implements MessageListener {
private
static
final
boolean
DEBUG
=
true
;
private
final
Logger
logger
=
org
.
slf4j
.
LoggerFactory
.
getLogger
(
MoyaEventTopicLoggingBean
.
class
);
@EJB
private
LanEventFacade
eventfacade
;
@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
());
LanEvent
event
=
null
;
if
(
msg
.
getEventId
()
!=
null
)
event
=
eventfacade
.
find
(
msg
.
getEventId
());
User
user
=
null
;
if
(
msg
.
getEventUserId
()
!=
null
)
{
EventUser
euser
=
eventUserfacade
.
find
(
msg
.
getEventUserId
());
if
(
euser
!=
null
)
user
=
euser
.
getUser
();
}
logMessage
(
msg
.
getEventtype
(),
event
,
user
,
msg
.
getDescription
());
}
catch
(
JMSException
e
)
{
logger
.
warn
(
"Exception whie receiving Moya EventTopic"
,
e
);
}
...
...
@@ -69,27 +77,34 @@ public class MoyaEventTopicLoggingBean implements MessageListener {
}
@EJB
private
EventUserFacade
eventUserfacade
;
@EJB
private
EventBeanLocal
eventbean
;
public
LogEntry
logMessage
(
SecurityLogType
paramType
,
LanEvent
event
,
User
user
,
Object
...
description
)
{
@EJB
private
LogEntryFacade
entryFacade
;
@EJB
private
LogEntryTypeFacade
typeFacade
;
private
LogEntry
logMessage
(
MoyaEventType
moyaEventType
,
LanEvent
event
,
User
user
,
String
desc
)
{
LogEntry
entry
=
null
;
if
(
event
==
null
)
{
event
=
eventbean
.
getCurrentEvent
();
}
try
{
String
desc
=
toString
(
description
);
logger
.
warn
(
"Sending logmsg {}"
,
desc
);
//LogEntryType type = typeFacade.findOrCreate(param
Type);
//
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: \""
+
param
Type
.
name
()
+
"\" user \""
+
param
Type
.
name
()
+
"\", description \""
+
((
user
==
null
)
?
"null"
:
user
.
getLogin
())
+
"\""
+
desc
;
LogEntryType
type
=
typeFacade
.
findOrCreate
(
moyaEvent
Type
);
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: \"" + moyaEvent
Type.name() +
// "\" user \"" + moyaEvent
Type.name() +
//
"\", description \"" + ((user == null) ? "null" : user.getLogin()) + "\"" + desc;
// sender.sendMessage(msg);
// utx.commit();
}
catch
(
Exception
e
)
{
...
...
@@ -98,23 +113,12 @@ public class MoyaEventTopicLoggingBean implements MessageListener {
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
();
}
// private static final String toString(Object... desc) {
// StringBuilder msg = new StringBuilder();
// for (Object msgpart : desc) {
// msg.append(msgpart);
// }
// return msg.toString();
// }
}
code/moya-beans/ejbModule/fi/codecrew/moya/facade/LanEventFacade.java
0 → 100644
View file @
4383018
/*
* 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
.
facade
;
import
javax.ejb.LocalBean
;
import
javax.ejb.Stateless
;
import
javax.persistence.TypedQuery
;
import
javax.persistence.criteria.CriteriaBuilder
;
import
javax.persistence.criteria.CriteriaQuery
;
import
javax.persistence.criteria.Path
;
import
javax.persistence.criteria.Root
;
import
fi.codecrew.moya.model.LanEvent
;
import
fi.codecrew.moya.model.LanEventDomain_
;
import
fi.codecrew.moya.model.LanEvent_
;
import
fi.codecrew.moya.model.LanEventDomain
;
@Stateless
@LocalBean
public
class
LanEventFacade
extends
IntegerPkGenericFacade
<
LanEvent
>
{
public
LanEventFacade
()
{
super
(
LanEvent
.
class
);
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/facade/LogEntryTypeFacade.java
View file @
4383018
...
...
@@ -24,6 +24,7 @@ import javax.persistence.TypedQuery;
import
fi.codecrew.moya.beans.SecurityLogType
;
import
fi.codecrew.moya.model.LogEntryType
;
import
fi.codecrew.moya.utilities.moyamessage.MoyaEventType
;
@Stateless
@LocalBean
...
...
@@ -34,18 +35,18 @@ public class LogEntryTypeFacade extends IntegerPkGenericFacade<LogEntryType> {
super
(
LogEntryType
.
class
);
}
public
LogEntryType
findOrCreate
(
SecurityLogType
t
ype
)
{
public
LogEntryType
findOrCreate
(
MoyaEventType
moyaEventT
ype
)
{
// Fetch log entry type
TypedQuery
<
LogEntryType
>
q
=
getEm
().
createNamedQuery
(
"LogEntryType.findByName"
,
LogEntryType
.
class
);
q
.
setParameter
(
"name"
,
t
ype
.
name
());
q
.
setParameter
(
"name"
,
moyaEventT
ype
.
name
());
LogEntryType
logEntryType
=
getSingleNullableResult
(
q
);
// Might not exist yet
if
(
logEntryType
==
null
)
{
logEntryType
=
new
LogEntryType
();
logEntryType
.
setName
(
t
ype
.
name
());
logEntryType
.
setName
(
moyaEventT
ype
.
name
());
getEm
().
persist
(
logEntryType
);
}
...
...
code/moya-parent/pom.xml
View file @
4383018
...
...
@@ -66,7 +66,7 @@
<dependency>
<groupId>
fi.iudex
</groupId>
<artifactId>
utils-standalone
</artifactId>
<version>
1.0.
9
</version>
<version>
1.0.
10
</version>
</dependency>
<dependency>
<groupId>
net.sf.barcode4j
</groupId>
...
...
@@ -118,7 +118,7 @@
<dependency>
<groupId>
fi.iudex
</groupId>
<artifactId>
jerklib
</artifactId>
<version>
1.0.
1
</version>
<version>
1.0.
2
</version>
</dependency>
<dependency>
<groupId>
net.matlux
</groupId>
...
...
code/moya-utils/src/main/java/fi/codecrew/moya/utilities/SystemProperty.java
0 → 100644
View file @
4383018
package
fi
.
codecrew
.
moya
.
utilities
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Gather all system properties in here as enums, so we have some kind of
* understanding what kind of properties there are.
*
* @author tuomari
*
*/
public
enum
SystemProperty
{
MOYA_IRC_SERVER
,
MOYA_IRC_CHANNEL
(
"#moya-debug"
)
;
private
final
String
defaultValue
;
private
final
Integer
defaultIntegerValue
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SystemProperty
.
class
);
private
SystemProperty
()
{
defaultValue
=
null
;
defaultIntegerValue
=
null
;
}
private
SystemProperty
(
String
value
)
{
defaultValue
=
value
;
defaultIntegerValue
=
null
;
}
private
SystemProperty
(
Integer
value
)
{
defaultIntegerValue
=
value
;
defaultValue
=
null
;
}
public
String
getDefaultValue
()
{
return
defaultValue
;
}
public
String
getValueOrDefault
()
{
String
val
=
System
.
getProperty
(
this
.
name
());
if
(
val
==
null
)
{
val
=
defaultValue
;
}
return
val
;
}
public
Integer
getIntvalueOrDefault
()
{
String
val
=
System
.
getProperty
(
this
.
name
());
Integer
intval
=
null
;
try
{
intval
=
Integer
.
parseInt
(
val
);
}
catch
(
Throwable
t
)
{
intval
=
null
;
logger
.
warn
(
"Unable to parse system property '{}' value '{}' as integer. Defaulting to {}"
,
name
(),
val
,
defaultIntegerValue
);
}
if
(
val
==
null
)
{
intval
=
defaultIntegerValue
;
}
return
intval
;
}
}
code/moya-utils/src/main/java/fi/codecrew/moya/utilities/moyamessage/MoyaEventMessage.java
View file @
4383018
...
...
@@ -11,7 +11,7 @@ public class MoyaEventMessage implements Serializable {
private
Calendar
time
;
private
MoyaEventType
eventtype
;
private
String
description
;
private
Integer
u
serId
;
private
Integer
eventU
serId
;
private
Integer
eventId
;
private
Integer
currentUserId
;
...
...
@@ -27,8 +27,8 @@ public class MoyaEventMessage implements Serializable {
this
.
description
=
description
;
}
public
void
set
UserId
(
Integer
u
serId
)
{
this
.
userId
=
u
serId
;
public
void
set
EventUserId
(
Integer
eventU
serId
)
{
this
.
eventUserId
=
eventU
serId
;
}
public
void
setEventId
(
Integer
eventId
)
{
...
...
@@ -47,8 +47,8 @@ public class MoyaEventMessage implements Serializable {
return
description
;
}
public
Integer
getUserId
()
{
return
u
serId
;
public
Integer
get
Event
UserId
()
{
return
eventU
serId
;
}
public
Integer
getEventId
()
{
...
...
code/moya-web/src/main/java/fi/codecrew/moya/servlet/IrcServlet.java
View file @
4383018
...
...
@@ -49,7 +49,6 @@ import javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
fi.codecrew.moya.clientutils.BortalLocalContextHolder
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -57,6 +56,7 @@ import fi.codecrew.moya.beans.BotBeanLocal;
import
fi.codecrew.moya.beans.EventBeanLocal
;
import
fi.codecrew.moya.beans.PermissionBeanLocal
;
import
fi.codecrew.moya.beans.PlaceBeanLocal
;
import
fi.codecrew.moya.utilities.SystemProperty
;
import
fi.iudex.utils.irc.IrcBot
;
import
fi.iudex.utils.irc.IrcBotListener
;
...
...
@@ -94,14 +94,17 @@ public class IrcServlet extends HttpServlet {
*/
public
void
init
(
ServletConfig
config
)
throws
ServletException
{
// tuotannossa rakastan tätä, devauspuolella en.
if
(!
BortalLocalContextHolder
.
isInDevelopmentMode
())
{
IrcBot
bot
=
new
IrcBot
(
"irc.cc.tut.fi"
,
"#moya-debug"
,
"moya-bot"
);
String
ircserver
=
SystemProperty
.
MOYA_IRC_SERVER
.
getValueOrDefault
();
logger
.
info
(
"Got irc server system property {}"
,
ircserver
);
if
(
ircserver
!=
null
)
{
logger
.
info
(
"Starting IRC client with server {}"
,
ircserver
);
IrcBot
bot
=
new
IrcBot
(
ircserver
,
SystemProperty
.
MOYA_IRC_CHANNEL
.
getValueOrDefault
(),
"moya-bot"
);
botbean
.
add
(
bot
);
bots
.
add
(
bot
);
bot
.
start
();
}
}
/**
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment