src/org/sonews/daemon/NNTPConnection.java
changeset 119 f5b57e221e38
parent 108 fdc075324ef3
     1.1 --- a/src/org/sonews/daemon/NNTPConnection.java	Tue Oct 25 10:39:57 2011 +0200
     1.2 +++ b/src/org/sonews/daemon/NNTPConnection.java	Thu Jul 05 13:19:19 2012 +0200
     1.3 @@ -31,6 +31,7 @@
     1.4  import java.util.Timer;
     1.5  import java.util.TimerTask;
     1.6  import java.util.logging.Level;
     1.7 +import org.sonews.acl.User;
     1.8  import org.sonews.daemon.command.Command;
     1.9  import org.sonews.storage.Article;
    1.10  import org.sonews.storage.Group;
    1.11 @@ -62,9 +63,7 @@
    1.12  	private int readLock = 0;
    1.13  	private final Object readLockGate = new Object();
    1.14  	private SelectionKey writeSelKey = null;
    1.15 -	
    1.16 -	private String username;
    1.17 -	private boolean userAuthenticated = false;
    1.18 +	private User user;
    1.19  
    1.20  	public NNTPConnection(final SocketChannel channel)
    1.21  			throws IOException {
    1.22 @@ -148,7 +147,7 @@
    1.23  			// will be received and a timeout can be triggered.
    1.24  			this.channel.socket().shutdownInput();
    1.25  		} catch (IOException ex) {
    1.26 -			Log.get().warning("Exception in NNTPConnection.shutdownInput(): " + ex);
    1.27 +			Log.get().log(Level.WARNING, "Exception in NNTPConnection.shutdownInput(): {0}", ex);
    1.28  		}
    1.29  	}
    1.30  
    1.31 @@ -162,9 +161,9 @@
    1.32  					channel.close();
    1.33  				} catch (SocketException ex) {
    1.34  					// Socket was already disconnected
    1.35 -					Log.get().info("NNTPConnection.shutdownOutput(): " + ex);
    1.36 +					Log.get().log(Level.INFO, "NNTPConnection.shutdownOutput(): {0}", ex);
    1.37  				} catch (Exception ex) {
    1.38 -					Log.get().warning("NNTPConnection.shutdownOutput(): " + ex);
    1.39 +					Log.get().log(Level.WARNING, "NNTPConnection.shutdownOutput(): {0}", ex);
    1.40  				}
    1.41  			}
    1.42  		}, 3000);
    1.43 @@ -227,7 +226,7 @@
    1.44  			raw = Arrays.copyOf(raw, raw.length - 1);
    1.45  		}
    1.46  
    1.47 -		Log.get().fine("<< " + line);
    1.48 +		Log.get().log(Level.FINE, "<< {0}", line);
    1.49  
    1.50  		if (command == null) {
    1.51  			command = parseCommandLine(line);
    1.52 @@ -344,7 +343,7 @@
    1.53  			CharSequence debugLine)
    1.54  			throws IOException {
    1.55  		if (!charset.canEncode()) {
    1.56 -			Log.get().severe("FATAL: Charset " + charset + " cannot encode!");
    1.57 +			Log.get().log(Level.SEVERE, "FATAL: Charset {0} cannot encode!", charset);
    1.58  			return;
    1.59  		}
    1.60  
    1.61 @@ -362,14 +361,14 @@
    1.62  			ChannelWriter.getInstance().getSelector().wakeup();
    1.63  		} catch (Exception ex) // CancelledKeyException and ChannelCloseException
    1.64  		{
    1.65 -			Log.get().warning("NNTPConnection.writeToChannel(): " + ex);
    1.66 +			Log.get().log(Level.WARNING, "NNTPConnection.writeToChannel(): {0}", ex);
    1.67  			return;
    1.68  		}
    1.69  
    1.70  		// Update last activity timestamp
    1.71  		this.lastActivity = System.currentTimeMillis();
    1.72  		if (debugLine != null) {
    1.73 -			Log.get().fine(">> " + debugLine);
    1.74 +			Log.get().log(Level.FINE, ">> {0}", debugLine);
    1.75  		}
    1.76  	}
    1.77  
    1.78 @@ -392,34 +391,17 @@
    1.79  	}
    1.80  
    1.81  	/**
    1.82 -	 * @return Current username. 
    1.83 -	 * But user may not have been authenticated yet.
    1.84 -	 * You must check {@link #isUserAuthenticated()}
    1.85 +	 * @return Currently logged user (but you should check {@link User#isAuthenticated()}, if user is athenticated, or we just trust him)
    1.86  	 */
    1.87 -	public String getUsername() {
    1.88 -		return username;
    1.89 +	public User getUser() {
    1.90 +		return user;
    1.91  	}
    1.92  
    1.93  	/**
    1.94  	 * This method is to be called from AUTHINFO USER Command implementation.
    1.95  	 * @param username username from AUTHINFO USER username.
    1.96  	 */
    1.97 -	public void setUsername(String username) {
    1.98 -		this.username = username;
    1.99 -	}
   1.100 -
   1.101 -	/**
   1.102 -	 * @return true if current user (see {@link #getUsername()}) has been succesfully authenticated.
   1.103 -	 */
   1.104 -	public boolean isUserAuthenticated() {
   1.105 -		return userAuthenticated;
   1.106 -	}
   1.107 -
   1.108 -	/**
   1.109 -	 * This method is to be called from AUTHINFO PASS Command implementation.
   1.110 -	 * @param userAuthenticated true if user has provided right password in AUTHINFO PASS password.
   1.111 -	 */
   1.112 -	public void setUserAuthenticated(boolean userAuthenticated) {
   1.113 -		this.userAuthenticated = userAuthenticated;
   1.114 +	public void setUser(User user) {
   1.115 +		this.user = user;
   1.116  	}
   1.117  }