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 cfb52bff
authored
Apr 02, 2015
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add hostname to session management functions. Update session list ui.
1 parent
4a56db43
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
60 deletions
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/SessionMgmtBeanLocal.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/SessionMgmtBean.java
code/moya-web/WebContent/auth/userSessionList.xhtml
code/moya-web/src/main/java/fi/codecrew/moya/HostnameFilter.java
code/moya-web/src/main/java/fi/codecrew/moya/web/cdiview/user/UserSessionView.java
code/moya-web/src/main/java/fi/codecrew/moya/web/converter/SessionToHostnameConverter.java
code/moya-web/src/main/java/fi/codecrew/moya/web/converter/SessionToUsernameConverter.java
code/moya-web/src/main/java/fi/codecrew/moya/web/helper/HttpSessionWrapper.java
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/SessionMgmtBeanLocal.java
View file @
cfb52bf
...
...
@@ -39,6 +39,24 @@ public interface SessionMgmtBeanLocal {
void
updateSessionUser
(
String
sessionId
,
String
user
);
String
getUsername
(
String
sessionId
);
UserContainer
getUsername
(
String
sessionId
);
public
static
class
UserContainer
{
private
final
String
hostname
;
private
final
String
username
;
public
UserContainer
(
String
hostname
,
String
username
)
{
this
.
hostname
=
hostname
;
this
.
username
=
username
;
}
public
String
getHostname
()
{
return
hostname
;
}
public
String
getUsername
()
{
return
username
;
}
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/beans/SessionMgmtBean.java
View file @
cfb52bf
...
...
@@ -36,6 +36,7 @@ import javax.servlet.http.HttpSession;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.clientutils.BortalLocalContextHolder
;
import
fi.codecrew.moya.enums.apps.UserPermission
;
/**
...
...
@@ -55,7 +56,7 @@ public class SessionMgmtBean implements SessionMgmtBeanLocal {
// TODO Auto-generated constructor stub
}
private
final
ConcurrentHashMap
<
String
,
String
>
sessionUsers
=
new
ConcurrentHashMap
<
String
,
String
>();
private
final
ConcurrentHashMap
<
String
,
UserContainer
>
sessionUsers
=
new
ConcurrentHashMap
<
>();
private
final
Set
<
HttpSession
>
sessions
=
Collections
.
newSetFromMap
(
new
ConcurrentHashMap
<
HttpSession
,
Boolean
>());
@SuppressWarnings
(
"unused"
)
...
...
@@ -65,7 +66,7 @@ public class SessionMgmtBean implements SessionMgmtBeanLocal {
public
void
updateSessionUser
(
String
sessionId
,
String
user
)
{
if
(!
sessionUsers
.
containsKey
(
sessionId
))
{
sessionUsers
.
put
(
sessionId
,
user
);
sessionUsers
.
put
(
sessionId
,
new
UserContainer
(
BortalLocalContextHolder
.
getHostname
(),
user
)
);
}
}
...
...
@@ -87,7 +88,7 @@ public class SessionMgmtBean implements SessionMgmtBeanLocal {
}
@Override
public
String
getUsername
(
String
sessionId
)
{
public
UserContainer
getUsername
(
String
sessionId
)
{
return
sessionUsers
.
get
(
sessionId
);
}
...
...
code/moya-web/WebContent/auth/userSessionList.xhtml
View file @
cfb52bf
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
>
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:p=
"http://primefaces.org/ui"
>
<h:body>
<ui:composition
template=
"#{sessionHandler.template}"
>
<f:metadata>
...
...
@@ -11,59 +10,48 @@
<ui:define
name=
"content"
>
<h:form>
<h:dataTable
value=
"#{userSessionView.sessions}"
var=
"sess"
>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"#{i18n['httpsession.id']}"
/>
</f:facet>
<p:dataTable
sort
value=
"#{userSessionView.sessions}"
var=
"sess"
sortBy=
"#{sess.id}"
>
<p:column
headerText=
"#{i18n['httpsession.id']}"
>
<h:outputText
value=
"#{sess.id}"
/>
</
h
:column>
<h:column>
<f:facet
name=
"header
"
>
<h:outputText
value=
"#{i18n['httpsession.user']
}"
/>
</f:facet
>
<h:outputText
value=
"#{sess.id}"
converter=
"#{sessionToUsernameConverter}"
/>
<
/h:column
>
<h:column
>
<f:facet
name=
"header"
>
<h:outputText
value=
"#{i18n['httpsession.creationTime']}"
/>
</f:facet
>
</
p
:column>
<p:column
headerText=
"#{i18n['httpsession.user']}"
sortBy=
"#{sess.username}
"
>
<h:outputText
value=
"#{sess.username
}"
/>
</p:column
>
<
p:column
headerText=
"#{i18n['httpsession.hostname']}"
sortBy=
"#{sess.hostname}"
>
<h:outputText
value=
"#{sess.hostname}"
/
>
</p:column
>
<p:column
sortBy=
"#{sessionHandler.creationDateTime}"
headerText=
"#{i18n['httpsession.creationTime']}"
>
<h:outputText
value=
"#{sess.creationDateTime}"
>
<f:convertDateTime
pattern=
"#{sessionHandler.shortDatetimeFormat}"
timeZone=
"#{sessionHandler.timezone}"
/>
</h:outputText>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"#{i18n['httpsession.lastAccessedTime']}"
/>
</f:facet>
</p:column>
<p:column
sortBy=
"#{sessionHandler.lastAccessedDateTime}"
headerText=
"#{i18n['httpsession.lastAccessedTime']}"
>
<h:outputText
value=
"#{sess.lastAccessedDateTime}"
>
<f:convertDateTime
pattern=
"#{sessionHandler.shortDatetimeFormat}"
timeZone=
"#{sessionHandler.timezone}"
/>
</h:outputText>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"#{i18n['httpsession.sessionHasExisted']}"
/>
</f:facet>
</p:column>
<p:column
headerText=
"#{i18n['httpsession.sessionHasExisted']}"
>
<h:outputText
value=
"#{sess.lastAccessedTime - sess.creationTime}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"#{i18n['httpsession.maxInactiveInterval']}"
/>
</f:facet>
</p:column>
<p:column
headerText=
"#{i18n['httpsession.maxInactiveInterval']}"
>
<h:outputText
value=
"#{sess.maxInactiveInterval}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"#{i18n['httpsession.isSessionNew']}"
/>
</f:facet>
</p:column>
<p:column
headerText=
"#{i18n['httpsession.isSessionNew']}"
>
<h:outputText
value=
"#{sess.new}"
/>
</h:column>
<h:column>
</p:column>
<p:column>
<h:commandButton
action=
"#{userSessionView.invalidateSession}"
value=
"#{i18n['httpsession.invalidate']}"
/>
</
h
:column>
</
p
:column>
</
h
:dataTable>
</
p
:dataTable>
</h:form>
</ui:define>
...
...
code/moya-web/src/main/java/fi/codecrew/moya/HostnameFilter.java
View file @
cfb52bf
...
...
@@ -107,6 +107,9 @@ public class HostnameFilter implements Filter {
* @param authType
*/
void
insertLoggingContext
(
HttpServletRequest
request
,
AuthType
authType
)
{
if
(
request
==
null
)
return
;
Principal
userPrincipal
=
request
.
getUserPrincipal
();
if
(
userPrincipal
!=
null
)
{
String
userString
=
userPrincipal
.
getName
();
...
...
@@ -187,7 +190,7 @@ public class HostnameFilter implements Filter {
}
// pass the request along the filter chain
try
{
insertLoggingContext
(
(
HttpServletRequest
)
r
equest
,
authtype
);
insertLoggingContext
(
httpR
equest
,
authtype
);
chain
.
doFilter
(
request
,
response
);
}
catch
(
Exception
t
)
{
if
(
AuthType
.
REST
==
authtype
)
{
...
...
code/moya-web/src/main/java/fi/codecrew/moya/web/cdiview/user/UserSessionView.java
View file @
cfb52bf
...
...
@@ -48,9 +48,8 @@ public class UserSessionView extends GenericCDIView {
public
void
initView
()
{
if
(
super
.
requirePermissions
(
UserPermission
.
MANAGE_HTTP_SESSION
)
&&
sessions
==
null
)
{
sessions
=
new
ListDataModel
<>(
HttpSessionWrapper
.
wrap
(
sessionMgmt
.
getSessions
()));
if
(
super
.
requirePermissions
(
UserPermission
.
MANAGE_HTTP_SESSION
)
&&
sessions
==
null
)
{
sessions
=
new
ListDataModel
<>(
HttpSessionWrapper
.
wrap
(
sessionMgmt
.
getSessions
(),
sessionMgmt
));
super
.
beginConversation
();
}
}
...
...
code/moya-web/src/main/java/fi/codecrew/moya/web/converter/SessionToHostnameConverter.java
0 → 100644
View file @
cfb52bf
/*
* 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
.
web
.
converter
;
import
javax.ejb.EJB
;
import
javax.faces.component.UIComponent
;
import
javax.faces.context.FacesContext
;
import
javax.faces.convert.Converter
;
import
javax.inject.Named
;
import
fi.codecrew.moya.beans.SessionMgmtBeanLocal
;
import
fi.codecrew.moya.beans.SessionMgmtBeanLocal.UserContainer
;
import
fi.codecrew.moya.utilities.I18n
;
@Named
()
public
class
SessionToHostnameConverter
implements
Converter
{
@EJB
private
SessionMgmtBeanLocal
sessbean
;
@Override
public
Object
getAsObject
(
FacesContext
context
,
UIComponent
component
,
String
value
)
{
return
null
;
}
@Override
public
String
getAsString
(
FacesContext
context
,
UIComponent
component
,
Object
value
)
{
String
ret
=
""
;
if
(
value
!=
null
)
{
UserContainer
retCont
=
sessbean
.
getUsername
(
value
.
toString
());
if
(
retCont
!=
null
)
ret
=
retCont
.
getHostname
();
}
if
(
ret
==
null
||
ret
.
isEmpty
())
{
ret
=
I18n
.
get
(
"user.unauthenticated"
);
}
return
ret
;
}
}
code/moya-web/src/main/java/fi/codecrew/moya/web/converter/SessionToUsernameConverter.java
View file @
cfb52bf
...
...
@@ -25,6 +25,7 @@ import javax.faces.convert.Converter;
import
javax.inject.Named
;
import
fi.codecrew.moya.beans.SessionMgmtBeanLocal
;
import
fi.codecrew.moya.beans.SessionMgmtBeanLocal.UserContainer
;
import
fi.codecrew.moya.utilities.I18n
;
@Named
()
...
...
@@ -41,12 +42,12 @@ public class SessionToUsernameConverter implements Converter {
@Override
public
String
getAsString
(
FacesContext
context
,
UIComponent
component
,
Object
value
)
{
String
ret
=
""
;
if
(
value
!=
null
)
{
ret
=
sessbean
.
getUsername
(
value
.
toString
());
if
(
value
!=
null
)
{
UserContainer
retCont
=
sessbean
.
getUsername
(
value
.
toString
());
if
(
retCont
!=
null
)
ret
=
retCont
.
getUsername
();
}
if
(
ret
==
null
||
ret
.
isEmpty
())
{
if
(
ret
==
null
||
ret
.
isEmpty
())
{
ret
=
I18n
.
get
(
"user.unauthenticated"
);
}
return
ret
;
...
...
code/moya-web/src/main/java/fi/codecrew/moya/web/helper/HttpSessionWrapper.java
View file @
cfb52bf
...
...
@@ -30,12 +30,19 @@ import javax.servlet.ServletContext;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSessionContext
;
import
fi.codecrew.moya.beans.SessionMgmtBeanLocal
;
import
fi.codecrew.moya.beans.SessionMgmtBeanLocal.UserContainer
;
public
class
HttpSessionWrapper
implements
HttpSession
{
private
final
HttpSession
session
;
private
final
String
hostname
;
private
final
String
username
;
public
HttpSessionWrapper
(
HttpSession
session
)
public
HttpSessionWrapper
(
HttpSession
session
,
String
username
,
String
hostname
)
{
this
.
username
=
username
;
this
.
hostname
=
hostname
;
this
.
session
=
session
;
}
...
...
@@ -146,22 +153,31 @@ public class HttpSessionWrapper implements HttpSession
session
.
setMaxInactiveInterval
(
arg0
);
}
public
static
List
<
HttpSessionWrapper
>
wrap
(
Set
<
HttpSession
>
sessions
)
{
public
static
List
<
HttpSessionWrapper
>
wrap
(
Set
<
HttpSession
>
sessions
,
SessionMgmtBeanLocal
sessionMgmt
)
{
ArrayList
<
HttpSessionWrapper
>
ret
=
new
ArrayList
<>();
for
(
HttpSession
s
:
sessions
)
{
ret
.
add
(
new
HttpSessionWrapper
(
s
));
UserContainer
uc
=
sessionMgmt
.
getUsername
(
s
.
getId
());
ret
.
add
(
new
HttpSessionWrapper
(
s
,
uc
.
getUsername
(),
uc
.
getHostname
()));
}
Collections
.
sort
(
ret
,
new
LastSeenComparator
());
return
ret
;
}
public
String
getUsername
()
{
return
username
;
}
public
String
getHostname
()
{
return
hostname
;
}
private
static
class
LastSeenComparator
implements
Comparator
<
HttpSessionWrapper
>
{
@Override
public
int
compare
(
HttpSessionWrapper
o1
,
HttpSessionWrapper
o2
)
{
return
Long
.
compare
(
o
1
.
getLastAccessedTime
(),
o2
.
getLastAccessedTime
());
return
Long
.
compare
(
o
2
.
getLastAccessedTime
(),
o1
.
getLastAccessedTime
());
}
}
...
...
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