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 b7957051
authored
Mar 20, 2010
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented SessionHandlerBean.hasPermission()
1 parent
1ac734f9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
16 deletions
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/SessionHandlerBean.java
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/RolePermission.java
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/SessionHandlerBeanLocal.java
code/LanBortalWeb/src/fi/insomnia/bortal/handler/SessionHandler.java
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/SessionHandlerBean.java
View file @
b795705
package
fi
.
insomnia
.
bortal
.
beans
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
javax.ejb.EJB
;
import
javax.ejb.Stateless
;
...
...
@@ -16,10 +20,11 @@ import fi.insomnia.bortal.model.User;
@Stateless
public
class
SessionHandlerBean
implements
SessionHandlerBeanLocal
{
@EJB
@EJB
private
UserFacade
userfacade
;
/**
* Default constructor.
* Default constructor.
*/
public
SessionHandlerBean
()
{
// TODO Auto-generated constructor stub
...
...
@@ -28,16 +33,53 @@ public class SessionHandlerBean implements SessionHandlerBeanLocal {
@Override
public
boolean
hasPermission
(
String
target
,
User
user
,
RolePermission
permission
)
{
User
dbusr
=
userfacade
.
find
(
user
.
getId
());
for
(
Role
r
:
dbusr
.
getRoles
())
Set
<
Role
>
checkedRoles
=
new
HashSet
<
Role
>();
for
(
Role
r
:
dbusr
.
getRoles
())
{
if
(
getRights
(
r
,
target
,
permission
,
checkedRoles
))
{
return
true
;
}
}
return
false
;
}
private
static
boolean
getRights
(
Role
role
,
String
target
,
RolePermission
permission
,
Set
<
Role
>
checkedRoles
)
{
if
(
checkedRoles
.
contains
(
role
))
{
for
(
RoleRight
rr
:
r
.
getRoleRights
())
return
false
;
}
for
(
RoleRight
rr
:
role
.
getRoleRights
())
{
if
(
rr
.
getAccessRight
().
getAccessRight
().
equals
(
target
))
{
switch
(
permission
)
{
case
READ:
if
(
rr
.
getRead
())
{
return
true
;
}
break
;
case
WRITE:
if
(
rr
.
getWrite
())
{
return
true
;
}
break
;
case
EXECUTE:
if
(
rr
.
isExecute
())
{
return
true
;
}
}
}
}
checkedRoles
.
add
(
role
);
for
(
Role
r
:
role
.
getParents
())
{
if
(
getRights
(
r
,
target
,
permission
,
checkedRoles
))
{
if
(
rr
.
get
)
return
true
;
}
}
return
false
;
}
}
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/RolePermission.java
View file @
b795705
package
fi
.
insomnia
.
bortal
;
public
enum
RolePermission
{
READ
,
WRITE
,
EXECUTE
}
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/SessionHandlerBeanLocal.java
View file @
b795705
package
fi
.
insomnia
.
bortal
;
import
javax.ejb.Local
;
import
fi.insomnia.bortal.beans.RolePermission
;
import
fi.insomnia.bortal.model.User
;
@Local
...
...
code/LanBortalWeb/src/fi/insomnia/bortal/handler/SessionHandler.java
View file @
b795705
...
...
@@ -10,28 +10,42 @@ import javax.ejb.EJB;
import
javax.enterprise.context.SessionScoped
;
import
javax.faces.bean.ManagedBean
;
import
fi.insomnia.bortal.RolePermission
;
import
fi.insomnia.bortal.SessionHandlerBeanLocal
;
import
fi.insomnia.bortal.model.User
;
/**
*
*
* @author tuukka
*/
@ManagedBean
(
name
=
"SessionHandler"
)
@ManagedBean
(
name
=
"SessionHandler"
)
@SessionScoped
public
class
SessionHandler
{
@EJB
private
SessionHandlerBeanLocal
handlerbean
;
private
User
user
;
/** Creates a new instance of SessionHandler */
public
SessionHandler
()
{
}
public
boolean
hasPermission
(
String
target
)
{
handlerbean
.
hasPermission
(
target
,
getUser
());
throw
new
UnsupportedOperationException
(
"Not yet implemented"
);
public
boolean
hasPermission
(
String
target
,
String
permission
)
{
RolePermission
perm
=
RolePermission
.
READ
;
if
(
permission
.
equals
(
"write"
))
{
perm
=
RolePermission
.
WRITE
;
}
else
if
(
permission
.
equals
(
"execute"
))
{
perm
=
RolePermission
.
EXECUTE
;
}
return
hasPermission
(
target
,
perm
);
}
public
boolean
hasPermission
(
String
target
,
RolePermission
permission
)
{
return
handlerbean
.
hasPermission
(
target
,
getUser
(),
permission
);
}
public
void
setUser
(
User
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