Java Doc for WikiSession.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Wiki Engine » JSPWiki » com.ecyrd.jspwiki 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.ecyrd.jspwiki.WikiSession

WikiSession
final public class WikiSession implements WikiEventListener(Code)

Represents a long-running wiki session, with an associated user Principal, user Subject, and authentication status. This class is initialized with minimal, default-deny values: authentication is set to false, and the user principal is set to null.

The WikiSession class allows callers to:

To keep track of the Principals each user posseses, each WikiSession stores a JAAS Subject. Various login processes add or remove Principals when users authenticate or log out.

WikiSession implements the com.ecyrd.jspwiki.event.WikiEventListener interface and listens for group add/change/delete events fired by event sources the WikiSession is registered with. Normally, com.ecyrd.jspwiki.auth.AuthenticationManager registers each WikiSession with the com.ecyrd.jspwiki.auth.authorize.GroupManager so it can catch group events. Thus, when a user is added to a com.ecyrd.jspwiki.auth.authorize.Group , a corresponding com.ecyrd.jspwiki.auth.GroupPrincipal is injected into the Subject's Principal set. Likewise, when the user is removed from the Group or the Group is deleted, the GroupPrincipal is removed from the Subject. The effect that this strategy produces is extremely beneficial: when someone adds a user to a wiki group, that user immediately gains the privileges associated with that group; he or she does not need to re-authenticate.

In addition to methods for examining individual WikiSession objects, this class also contains a number of static methods for managing WikiSessions for an entire wiki. These methods allow callers to find, query and remove WikiSession objects, and to obtain a list of the current wiki session users.

WikiSession encloses a protected static class, SessionMonitor , to keep track of WikiSessions registered with each wiki.


author:
   Andrew R. Jaquith


Field Summary
final public static  StringANONYMOUS
     An anonymous user's session status.
final public static  StringASSERTED
     An asserted user's session status.
final public static  StringAUTHENTICATED
     An authenticated user's session status.


Method Summary
final public  voidactionPerformed(WikiEvent event)
     Listens for WikiEvents generated by source objects such as the GroupManager.
final public  voidaddMessage(String message)
     Adds a message to the generic list of messages associated with the session.
final public  voidaddMessage(String topic, String message)
     Adds a message to the specific set of messages associated with the session.
final public  voidclearMessages()
     Clears all messages associated with this session.
final public  voidclearMessages(String topic)
     Clears all messages associated with a session topic.
final public static  ObjectdoPrivileged(WikiSession session, PrivilegedAction action)
     Wrapper for javax.security.auth.Subject.doAsPrivileged(Subjectjava.security.PrivilegedExceptionActionjava.security.AccessControlContext) that executes an action with the privileges posssessed by a WikiSession's Subject.
final public  LocalegetLocale()
     Returns a cached Locale object for this user.
final public  LoginContextgetLoginContext(String application, CallbackHandler handler)
     Creates and returns a new login context for this wiki session.
final public  PrincipalgetLoginPrincipal()
    

Returns the Principal used to log in to an authenticated session.

final public  String[]getMessages()
     Returns all generic messages associated with this session.
final public  String[]getMessages(String topic)
     Returns all messages associated with a session topic.
final public  Principal[]getPrincipals()
     Returns all user Principals associated with this session.
final public  Principal[]getRoles()
     Returns an array of Principal objects that represents the groups and roles that the user associated with a WikiSession possesses.
final public  StringgetStatus()
    

Returns the status of the wiki session as a text string.

final public  PrincipalgetUserPrincipal()
    

Returns the primary user Principal associated with this session.

final public static  WikiSessiongetWikiSession(WikiEngine engine, HttpServletRequest request)
    

Static factory method that returns the WikiSession object associated with the current HTTP request.

final public static  WikiSessionguestSession(WikiEngine engine)
     Static factory method that creates a new "guest" session containing a single user Principal com.ecyrd.jspwiki.auth.WikiPrincipal.GUEST , plus the role principals Role.ALL and Role.ANONYMOUS .
final public  booleanhasPrincipal(Principal principal)
     Returns true if the WikiSession's Subject possess a supplied Principal.
final protected  voidinjectRolePrincipals()
     Injects GroupPrincipal and Role objects into the user's Principal set based on the groups and roles the user belongs to. For Roles, the algorithm first calls the Authorizer.getRoles to obtain the array of Principals the authorizer knows about.
final protected  voidinjectUserProfilePrincipals()
     Adds Principal objects to the Subject that correspond to the logged-in user's profile attributes for the wiki name, full name and login name.
final public  voidinvalidate()
     Invalidates the WikiSession and resets its Subject's Principals to the equivalent of a "guest session".
final public  booleanisAnonymous()
    

Determines whether the current session is anonymous.

final public  booleanisAsserted()
     Returns true if the user is considered asserted via a session cookie; that is, the Subject contains the Principal Role.ASSERTED.
final public  booleanisAuthenticated()
     Returns the authentication status of the user's session.
final protected  booleanisContainerStatusChanged(HttpServletRequest request)
     Returns whether the HTTP servlet container's authentication status has changed.
final protected static  booleanisIPV4Address(String name)
     Verifies whether a String represents an IPv4 address.
final protected  booleanisInGroup(Group group)
     Returns true if one of this WikiSession's user Principals can be shown to belong to a particular wiki group.
final protected  booleanisNew()
     Returns true if the wiki session is newly initialized.
final public static  voidremoveWikiSession(WikiEngine engine, HttpServletRequest request)
     Removes the wiki session associated with the user's HTTP request from the cache of wiki sessions, typically as part of a logout process.
final public static  intsessions(WikiEngine engine)
     Returns the total number of active wiki sessions for a particular wiki.
final protected  voidsetNew(boolean isNew)
     Sets the status of this wiki session.
final protected  voidupdatePrincipals()
     Updates the internally cached principals returned by WikiSession.getUserPrincipal() and WikiSession.getLoginPrincipal() .
final public static  Principal[]userPrincipals(WikiEngine engine)
     Returns Principals representing the current users known to a particular wiki.

Field Detail
ANONYMOUS
final public static String ANONYMOUS(Code)
An anonymous user's session status.



ASSERTED
final public static String ASSERTED(Code)
An asserted user's session status.



AUTHENTICATED
final public static String AUTHENTICATED(Code)
An authenticated user's session status.





Method Detail
actionPerformed
final public void actionPerformed(WikiEvent event)(Code)
Listens for WikiEvents generated by source objects such as the GroupManager. This method adds Principals to the private Subject managed by the WikiSession.
See Also:   com.ecyrd.jspwiki.event.WikiEventListener.actionPerformed(com.ecyrd.jspwiki.event.WikiEvent)



addMessage
final public void addMessage(String message)(Code)
Adds a message to the generic list of messages associated with the session. These messages retain their order of insertion and remain until the WikiSession.clearMessages() method is called.
Parameters:
  message - the message to add; if null it is ignored.



addMessage
final public void addMessage(String topic, String message)(Code)
Adds a message to the specific set of messages associated with the session. These messages retain their order of insertion and remain until the WikiSession.clearMessages() method is called.
Parameters:
  topic - the topic to associate the message to;
Parameters:
  message - the message to add



clearMessages
final public void clearMessages()(Code)
Clears all messages associated with this session.



clearMessages
final public void clearMessages(String topic)(Code)
Clears all messages associated with a session topic.
Parameters:
  topic - the topic whose messages should be cleared.



doPrivileged
final public static Object doPrivileged(WikiSession session, PrivilegedAction action) throws AccessControlException(Code)
Wrapper for javax.security.auth.Subject.doAsPrivileged(Subjectjava.security.PrivilegedExceptionActionjava.security.AccessControlContext) that executes an action with the privileges posssessed by a WikiSession's Subject. The action executes with a null AccessControlContext, which has the effect of running it "cleanly" without the AccessControlContexts of the caller.
Parameters:
  session - the wiki session
Parameters:
  action - the privileged action the result of the privileged action; may be null
throws:
  java.security.AccessControlException - if the action is not permittedby the security policy



getLocale
final public Locale getLocale()(Code)
Returns a cached Locale object for this user. It's better to use WikiContext's corresponding getBundle() method, since that will actually react if the user changes the locale in the middle, but if that's not available (or, for some reason, you need the speed), this method can also be used. The Locale expires when the WikiSession expires, and currently there is no way to reset the Locale. A cached Locale object
since:
   2.5.96



getLoginContext
final public LoginContext getLoginContext(String application, CallbackHandler handler) throws LoginException(Code)
Creates and returns a new login context for this wiki session. This method is called by com.ecyrd.jspwiki.auth.AuthenticationManager .
Parameters:
  application - the name of the application
Parameters:
  handler - the callback handler A new login context
throws:
  LoginException - If the login context cannot be created



getLoginPrincipal
final public Principal getLoginPrincipal()(Code)

Returns the Principal used to log in to an authenticated session. The login principal is determined by examining the Subject's Principal set for PrincipalWrappers or WikiPrincipals with type designator LOGIN_NAME; the first one found is the login principal. If one is not found, this method returns the first principal that isn't of type Role or GroupPrincipal. If neither of these conditions hold, this method returns com.ecyrd.jspwiki.auth.WikiPrincipal.GUEST . the login Principal. If it is a PrincipalWrapper containing anexternally-provided Principal, the object returned is the Principal, notthe wrapper around it.




getMessages
final public String[] getMessages()(Code)
Returns all generic messages associated with this session. The messages stored with the session persist throughout the session unless they have been reset with WikiSession.clearMessages() . the current messsages.



getMessages
final public String[] getMessages(String topic)(Code)
Returns all messages associated with a session topic. The messages stored with the session persist throughout the session unless they have been reset with WikiSession.clearMessages(String) . the current messsages.
Parameters:
  topic - The topic



getPrincipals
final public Principal[] getPrincipals()(Code)
Returns all user Principals associated with this session. User principals are those in the Subject's principal collection that aren't of type Role or of type GroupPrincipal. This is a defensive copy. Returns the user principal
See Also:   com.ecyrd.jspwiki.auth.AuthenticationManager.isUserPrincipal(Principal)



getRoles
final public Principal[] getRoles()(Code)
Returns an array of Principal objects that represents the groups and roles that the user associated with a WikiSession possesses. The array is built by iterating through the Subject's Principal set and extracting all Role and GroupPrincipal objects into a list. The list is returned as an array sorted in the natural order implied by each Principal's getName method. Note that this method does not consult the external Authorizer or GroupManager; it relies on the Principals that have been injected into the user's Subject at login time, or after group creation/modification/deletion. an array of Principal objects corresponding to the roles theSubject possesses



getStatus
final public String getStatus()(Code)

Returns the status of the wiki session as a text string. Valid values are:

the user's session status



getUserPrincipal
final public Principal getUserPrincipal()(Code)

Returns the primary user Principal associated with this session. The primary user principal is determined as follows:

  1. If the Subject's Principal set contains WikiPrincipals, the first WikiPrincipal with type designator WIKI_NAME or (alternatively) FULL_NAME is the primary Principal.
  2. For all other cases, the first Principal in the Subject's principal collection that that isn't of type Role or GroupPrincipal is the primary.
If no primary user Principal is found, this method returns com.ecyrd.jspwiki.auth.WikiPrincipal.GUEST . the primary user Principal



getWikiSession
final public static WikiSession getWikiSession(WikiEngine engine, HttpServletRequest request)(Code)

Static factory method that returns the WikiSession object associated with the current HTTP request. This method looks up the associated HttpSession in an internal WeakHashMap and attempts to retrieve the WikiSession. If not found, one is created. This method is guaranteed to always return a WikiSession, although the authentication status is unpredictable until the user attempts to log in. If the servlet request parameter is null, a synthetic WikiSession.guestSession(WikiEngine) is returned.

When a session is created, this method attaches a WikiEventListener to the GroupManager so that changes to groups are detected automatically.


Parameters:
  engine - the wiki engine
Parameters:
  request - the servlet request object the existing (or newly created) wiki session



guestSession
final public static WikiSession guestSession(WikiEngine engine)(Code)
Static factory method that creates a new "guest" session containing a single user Principal com.ecyrd.jspwiki.auth.WikiPrincipal.GUEST , plus the role principals Role.ALL and Role.ANONYMOUS . This method also adds the session as a listener for GroupManager, AuthenticationManager and UserManager events.
Parameters:
  engine - the wiki engine the guest wiki session



hasPrincipal
final public boolean hasPrincipal(Principal principal)(Code)
Returns true if the WikiSession's Subject possess a supplied Principal. This method eliminates the need to externally request and inspect the JAAS subject.
Parameters:
  principal - the Principal to test the result



injectRolePrincipals
final protected void injectRolePrincipals()(Code)
Injects GroupPrincipal and Role objects into the user's Principal set based on the groups and roles the user belongs to. For Roles, the algorithm first calls the Authorizer.getRoles to obtain the array of Principals the authorizer knows about. Then, the method Authorizer.isUserInRole(WikiSessionPrincipal) is called for each Principal. If the user possesses the role, an equivalent role Principal is injected into the user's principal set. Reloads user Principals into the suppplied WikiSession's Subject. Existing Role principals are preserved; all other Principal types are flushed and replaced by those returned by com.ecyrd.jspwiki.auth.user.UserDatabase.getPrincipals(String) . This method should generally be called after a user's com.ecyrd.jspwiki.auth.user.UserProfile is saved. If the wiki session is null, or there is no matching user profile, the method returns silently.



injectUserProfilePrincipals
final protected void injectUserProfilePrincipals()(Code)
Adds Principal objects to the Subject that correspond to the logged-in user's profile attributes for the wiki name, full name and login name. These Principals will be WikiPrincipals, and they will replace all other WikiPrincipals in the Subject. Note: this method is never called during anonymous or asserted sessions.



invalidate
final public void invalidate()(Code)
Invalidates the WikiSession and resets its Subject's Principals to the equivalent of a "guest session".



isAnonymous
final public boolean isAnonymous()(Code)

Determines whether the current session is anonymous. This will be true if any of these conditions are true:

The criteria above are listed in the order in which they are evaluated.

whether the current user's identity is equivalent to an IPaddress



isAsserted
final public boolean isAsserted()(Code)
Returns true if the user is considered asserted via a session cookie; that is, the Subject contains the Principal Role.ASSERTED. Returns true if the user is asserted



isAuthenticated
final public boolean isAuthenticated()(Code)
Returns the authentication status of the user's session. The user is considered authenticated if the Subject contains the Principal Role.AUTHENTICATED. If this method determines that an earlier LoginModule did not inject Role.AUTHENTICATED, it will inject one if the user is not anonymous and not asserted. Returns true if the user is authenticated



isContainerStatusChanged
final protected boolean isContainerStatusChanged(HttpServletRequest request)(Code)
Returns whether the HTTP servlet container's authentication status has changed. Used to detect whether the container has logged in a user since the last call to this function. This method is stateful. After calling this function, the cached values are set to those in the current request. If the servlet request is null, this method always returns false. Note that once a user authenticates, the container status for the session will never change again, unless the session is invalidated by timeout or logout.
Parameters:
  request - the servlet request true if the status has changed, falseotherwise



isIPV4Address
final protected static boolean isIPV4Address(String name)(Code)
Verifies whether a String represents an IPv4 address. The algorithm is extremely efficient and does not allocate any objects.
Parameters:
  name - the address to test the result



isInGroup
final protected boolean isInGroup(Group group)(Code)
Returns true if one of this WikiSession's user Principals can be shown to belong to a particular wiki group. If the user is not authenticated, this method will always return false.
Parameters:
  group - the group to test the result



isNew
final protected boolean isNew()(Code)
Returns true if the wiki session is newly initialized. True, if this is a new session.



removeWikiSession
final public static void removeWikiSession(WikiEngine engine, HttpServletRequest request)(Code)
Removes the wiki session associated with the user's HTTP request from the cache of wiki sessions, typically as part of a logout process.
Parameters:
  engine - the wiki engine
Parameters:
  request - the users's HTTP request



sessions
final public static int sessions(WikiEngine engine)(Code)
Returns the total number of active wiki sessions for a particular wiki. This method delegates to the wiki's SessionMonitor.sessions method.
Parameters:
  engine - the wiki session the number of sessions



setNew
final protected void setNew(boolean isNew)(Code)
Sets the status of this wiki session.
Parameters:
  isNew - whether this session should be considered "new".



updatePrincipals
final protected void updatePrincipals()(Code)
Updates the internally cached principals returned by WikiSession.getUserPrincipal() and WikiSession.getLoginPrincipal() . This method is called when the WikiSession receives the com.ecyrd.jspwiki.event.WikiSecurityEvent.LOGIN_INITIATED message.



userPrincipals
final public static Principal[] userPrincipals(WikiEngine engine)(Code)
Returns Principals representing the current users known to a particular wiki. Each Principal will correspond to the value returned by each WikiSession's WikiSession.getUserPrincipal() method. This method delegates to SessionMonitor.userPrincipals .
Parameters:
  engine - the wiki engine an array of Principal objects, sorted by name



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.