Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Antti Väyrynen
/
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 085306f6
authored
Mar 21, 2010
by
Juho Juopperi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
security logging: permission denied
1 parent
ae4b2d53
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
12 deletions
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/SecurityBean.java
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/facade/LogEntryTypeFacade.java
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/beans/SecurityBeanLocal.java
code/LanBortalDatabase/src/fi/insomnia/bortal/model/LogEntryType.java
code/LanBortalWeb/src/fi/insomnia/bortal/exceptions/PermissionDeniedException.java
code/LanBortalWeb/src/fi/insomnia/bortal/view/UserView.java
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/SecurityBean.java
View file @
085306f
package
fi
.
insomnia
.
bortal
.
beans
;
import
java.util.Calendar
;
import
javax.ejb.EJB
;
import
javax.ejb.Stateless
;
import
org.hibernate.validator.util.LoggerFactory
;
import
org.slf4j.Logger
;
import
fi.insomnia.bortal.facade.LogEntryFacade
;
import
fi.insomnia.bortal.facade.LogEntryTypeFacade
;
import
fi.insomnia.bortal.model.LogEntry
;
import
fi.insomnia.bortal.model.LogEntryType
;
import
fi.insomnia.bortal.model.User
;
/**
* Session Bean implementation class SercurityBean
...
...
@@ -9,17 +20,28 @@ import javax.ejb.Stateless;
@Stateless
public
class
SecurityBean
implements
SecurityBeanLocal
{
private
final
Logger
logger
=
org
.
slf4j
.
LoggerFactory
.
getLogger
(
SecurityBean
.
class
);
@EJB
LogEntryTypeFacade
typeFacade
;
@EJB
LogEntryFacade
entryFacade
;
/**
* Default constructor.
* Default constructor.
*/
public
SecurityBean
()
{
// TODO Auto-generated constructor stub
}
@Override
public
void
log
(
Exception
permissionDeniedException
)
{
// TODO Auto-generated method stub
public
void
logPermissionDenied
(
User
user
,
Exception
exception
)
{
LogEntryType
type
=
typeFacade
.
findOrCreate
(
SecurityLogType
.
permissionDenied
);
LogEntry
entry
=
new
LogEntry
();
entry
.
setType
(
type
);
entry
.
setTime
(
Calendar
.
getInstance
());
entry
.
setDescription
(
exception
.
getMessage
());
entry
.
setUser
(
user
);
logger
.
debug
(
entry
.
toString
(),
exception
);
entryFacade
.
create
(
entry
);
}
}
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/facade/LogEntryTypeFacade.java
View file @
085306f
...
...
@@ -4,6 +4,9 @@ import javax.ejb.LocalBean;
import
javax.ejb.Stateless
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
javax.persistence.TypedQuery
;
import
fi.insomnia.bortal.beans.SecurityLogType
;
import
fi.insomnia.bortal.model.LogEntryType
;
@Stateless
...
...
@@ -21,4 +24,21 @@ public class LogEntryTypeFacade extends GenericFacade<LogEntryType> {
return
em
;
}
public
LogEntryType
findOrCreate
(
SecurityLogType
type
)
{
// Fetch log entry type
TypedQuery
<
LogEntryType
>
q
=
em
.
createNamedQuery
(
"LogEntryType.findByName"
,
LogEntryType
.
class
);
q
.
setParameter
(
"login"
,
type
.
name
());
LogEntryType
logEntryType
=
q
.
getSingleResult
();
// Might not exist yet
if
(
logEntryType
==
null
)
{
logEntryType
=
new
LogEntryType
();
logEntryType
.
setName
(
type
.
name
());
em
.
persist
(
logEntryType
);
}
return
logEntryType
;
}
}
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/beans/SecurityBeanLocal.java
View file @
085306f
...
...
@@ -2,9 +2,11 @@ package fi.insomnia.bortal.beans;
import
javax.ejb.Local
;
import
fi.insomnia.bortal.model.User
;
@Local
public
interface
SecurityBeanLocal
{
void
log
(
Exception
permissionDeniedException
);
void
log
PermissionDenied
(
User
user
,
Exception
permissionDeniedException
);
}
code/LanBortalDatabase/src/fi/insomnia/bortal/model/LogEntryType.java
View file @
085306f
...
...
@@ -24,15 +24,18 @@ import javax.persistence.Version;
@Table
(
name
=
"event_log_types"
)
@NamedQueries
(
{
@NamedQuery
(
name
=
"LogEntryType.findAll"
,
query
=
"SELECT l FROM LogEntryType l"
),
@NamedQuery
(
name
=
"LogEntryType.findByName"
,
query
=
"SELECT l FROM LogEntryType l WHERE l.name = :name"
),
@NamedQuery
(
name
=
"LogEntryType.findByDescription"
,
query
=
"SELECT l FROM LogEntryType l WHERE l.description = :description"
)
})
public
class
LogEntryType
implements
EventChildInterface
{
public
class
LogEntryType
implements
EventChildInterface
{
private
static
final
long
serialVersionUID
=
1L
;
@EmbeddedId
private
EventPk
id
;
@Column
(
name
=
"event_type_name"
,
nullable
=
false
)
private
String
name
;
@Lob
@Column
(
name
=
"event_type_description"
,
nullable
=
false
)
private
String
description
;
...
...
@@ -132,4 +135,12 @@ public class LogEntryType implements EventChildInterface{
public
void
setJpaVersionField
(
int
jpaVersionField
)
{
this
.
jpaVersionField
=
jpaVersionField
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getName
()
{
return
name
;
}
}
code/LanBortalWeb/src/fi/insomnia/bortal/exceptions/PermissionDeniedException.java
View file @
085306f
package
fi
.
insomnia
.
bortal
.
exceptions
;
import
fi.insomnia.bortal.beans.SecurityBeanLocal
;
import
fi.insomnia.bortal.model.User
;
public
class
PermissionDeniedException
extends
RuntimeException
{
public
PermissionDeniedException
(
S
tring
message
,
SecurityBeanLocal
bean
)
{
public
PermissionDeniedException
(
S
ecurityBeanLocal
bean
,
User
user
,
String
message
)
{
super
(
message
);
bean
.
log
(
this
);
bean
.
log
PermissionDenied
(
user
,
this
);
}
/**
...
...
code/LanBortalWeb/src/fi/insomnia/bortal/view/UserView.java
View file @
085306f
...
...
@@ -23,7 +23,6 @@ public class UserView {
@ManagedProperty
(
"#{sessionHandler}"
)
private
SessionHandler
sessionhandler
;
@EJB
private
UserBeanLocal
userBean
;
...
...
@@ -47,7 +46,7 @@ public class UserView {
public
String
createUser
()
{
if
(!
sessionhandler
.
canWrite
(
"userManagement"
))
{
// Give message to administration what happened here.
throw
new
PermissionDeniedException
(
"User "
+
sessionhandler
.
getUser
()
+
" does not have permission to create user!"
,
securitybean
);
throw
new
PermissionDeniedException
(
securitybean
,
sessionhandler
.
getUser
(),
"User "
+
sessionhandler
.
getUser
()
+
" does not have permission to create user!"
);
}
logger
.
info
(
"Saving user"
);
...
...
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