📄 usermanager.java
字号:
public Principal[] listWikiNames() throws WikiSecurityException { return getUserDatabase().getWikiNames(); } /** * This is a database that gets used if nothing else is available. It does * nothing of note - it just mostly thorws NoSuchPrincipalExceptions if * someone tries to log in. */ public static class DummyUserDatabase extends AbstractUserDatabase { /** * No-op. * @throws WikiSecurityException never... */ @SuppressWarnings("deprecation") public void commit() throws WikiSecurityException { // No operation } /** * No-op. * @param loginName the login name to delete * @throws WikiSecurityException never... */ public void deleteByLoginName( String loginName ) throws WikiSecurityException { // No operation } /** * No-op; always throws <code>NoSuchPrincipalException</code>. * @param index the name to search for * @return the user profile * @throws NoSuchPrincipalException never... */ public UserProfile findByEmail(String index) throws NoSuchPrincipalException { throw new NoSuchPrincipalException("No user profiles available"); } /** * No-op; always throws <code>NoSuchPrincipalException</code>. * @param index the name to search for * @return the user profile * @throws NoSuchPrincipalException never... */ public UserProfile findByFullName(String index) throws NoSuchPrincipalException { throw new NoSuchPrincipalException("No user profiles available"); } /** * No-op; always throws <code>NoSuchPrincipalException</code>. * @param index the name to search for * @return the user profile * @throws NoSuchPrincipalException never... */ public UserProfile findByLoginName(String index) throws NoSuchPrincipalException { throw new NoSuchPrincipalException("No user profiles available"); } /** * No-op; always throws <code>NoSuchPrincipalException</code>. * @param uid the unique identifier to search for * @return the user profile * @throws NoSuchPrincipalException never... */ public UserProfile findByUid( String uid ) throws NoSuchPrincipalException { throw new NoSuchPrincipalException("No user profiles available"); } /** * No-op; always throws <code>NoSuchPrincipalException</code>. * @param index the name to search for * @return the user profile * @throws NoSuchPrincipalException never... */ public UserProfile findByWikiName(String index) throws NoSuchPrincipalException { throw new NoSuchPrincipalException("No user profiles available"); } /** * No-op. * @return a zero-length array * @throws WikiSecurityException never... */ public Principal[] getWikiNames() throws WikiSecurityException { return new Principal[0]; } /** * No-op. * @param engine the wiki engine * @param props the properties used to initialize the wiki engine * @throws NoRequiredPropertyException never... */ public void initialize(WikiEngine engine, Properties props) throws NoRequiredPropertyException { } /** * No-op; always throws <code>NoSuchPrincipalException</code>. * @param loginName the login name * @param newName the proposed new login name * @throws DuplicateUserException never... * @throws WikiSecurityException never... */ public void rename( String loginName, String newName ) throws DuplicateUserException, WikiSecurityException { throw new NoSuchPrincipalException("No user profiles available"); } /** * No-op. * @param profile the user profile * @throws WikiSecurityException never... */ public void save( UserProfile profile ) throws WikiSecurityException { } } // workflow task inner classes.................................................... /** * Inner class that handles the actual profile save action. Instances * of this class are assumed to have been added to an approval workflow via * {@link com.ecyrd.jspwiki.workflow.WorkflowBuilder#buildApprovalWorkflow(Principal, String, Task, String, com.ecyrd.jspwiki.workflow.Fact[], Task, String)}; * they will not function correctly otherwise. * * @author Andrew Jaquith */ public static class SaveUserProfileTask extends Task { private static final long serialVersionUID = 6994297086560480285L; private final UserDatabase m_db; private final WikiEngine m_engine; /** * Constructs a new Task for saving a user profile. * @param engine the wiki engine */ public SaveUserProfileTask( WikiEngine engine ) { super( SAVE_TASK_MESSAGE_KEY ); m_engine = engine; m_db = engine.getUserManager().getUserDatabase(); } /** * Saves the user profile to the user database. * @return {@link com.ecyrd.jspwiki.workflow.Outcome#STEP_COMPLETE} if the * task completed successfully * @throws WikiException if the save did not complete for some reason */ public Outcome execute() throws WikiException { // Retrieve user profile UserProfile profile = (UserProfile) getWorkflow().getAttribute( SAVED_PROFILE ); // Save the profile (userdatabase will take care of timestamps for us) m_db.save( profile ); // Send e-mail if user supplied an e-mail address if ( profile.getEmail() != null ) { try { String app = m_engine.getApplicationName(); String to = profile.getEmail(); String subject = "Welcome to " + app; String content = "Congratulations! Your new profile on " + app + " has been created. Your profile details are as follows: \n\n" + "Login name: " + profile.getLoginName() + "\n" + "Your name : " + profile.getFullname() + "\n" + "E-mail : " + profile.getEmail() + "\n\n" + "If you forget your password, you can reset it at " + m_engine.getURL(WikiContext.LOGIN, null, null, true); MailUtil.sendMessage( m_engine, to, subject, content); } catch ( AddressException e) { } catch ( MessagingException e ) { log.error( "Could not send registration confirmation e-mail. Is the e-mail server running?" ); } } return Outcome.STEP_COMPLETE; } } // events processing ....................................................... /** * Registers a WikiEventListener with this instance. * This is a convenience method. * @param listener the event listener */ public final synchronized void addWikiEventListener( WikiEventListener listener ) { WikiEventManager.addWikiEventListener( this, listener ); } /** * Un-registers a WikiEventListener with this instance. * This is a convenience method. * @param listener the event listener */ public final synchronized void removeWikiEventListener( WikiEventListener listener ) { WikiEventManager.removeWikiEventListener( this, listener ); } /** * Fires a WikiSecurityEvent of the provided type, Principal and target Object * to all registered listeners. * * @see com.ecyrd.jspwiki.event.WikiSecurityEvent * @param type the event type to be fired * @param session the wiki session supporting the event * @param profile the user profile (or array of user profiles), which may be <code>null</code> */ protected final void fireEvent( int type, WikiSession session, Object profile ) { if ( WikiEventManager.isListening(this) ) { WikiEventManager.fireEvent(this,new WikiSecurityEvent(session,type,profile)); } } /** * Implements the JSON API for usermanager. * <p> * Even though this gets serialized whenever container shuts down/restarts, * this gets reinstalled to the session when JSPWiki starts. This means * that it's not actually necessary to save anything. */ public static final class JSONUserModule implements RPCCallable, Serializable { private static final long serialVersionUID = 1L; private volatile UserManager m_manager; /** * Create a new JSONUserModule. * @param mgr Manager */ public JSONUserModule( UserManager mgr ) { m_manager = mgr; } /** * Directly returns the UserProfile object attached to an uid. * * @param uid The user id (e.g. WikiName) * @return A UserProfile object * @throws NoSuchPrincipalException If such a name does not exist. */ public UserProfile getUserInfo( String uid ) throws NoSuchPrincipalException { if( m_manager != null ) { UserProfile prof = m_manager.getUserDatabase().find( uid ); return prof; } throw new IllegalStateException("The manager is offline."); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -