diff -r fdc075324ef3 -r f5b57e221e38 src/org/sonews/daemon/NNTPConnection.java --- a/src/org/sonews/daemon/NNTPConnection.java Tue Oct 25 10:39:57 2011 +0200 +++ b/src/org/sonews/daemon/NNTPConnection.java Thu Jul 05 13:19:19 2012 +0200 @@ -31,6 +31,7 @@ import java.util.Timer; import java.util.TimerTask; import java.util.logging.Level; +import org.sonews.acl.User; import org.sonews.daemon.command.Command; import org.sonews.storage.Article; import org.sonews.storage.Group; @@ -62,9 +63,7 @@ private int readLock = 0; private final Object readLockGate = new Object(); private SelectionKey writeSelKey = null; - - private String username; - private boolean userAuthenticated = false; + private User user; public NNTPConnection(final SocketChannel channel) throws IOException { @@ -148,7 +147,7 @@ // will be received and a timeout can be triggered. this.channel.socket().shutdownInput(); } catch (IOException ex) { - Log.get().warning("Exception in NNTPConnection.shutdownInput(): " + ex); + Log.get().log(Level.WARNING, "Exception in NNTPConnection.shutdownInput(): {0}", ex); } } @@ -162,9 +161,9 @@ channel.close(); } catch (SocketException ex) { // Socket was already disconnected - Log.get().info("NNTPConnection.shutdownOutput(): " + ex); + Log.get().log(Level.INFO, "NNTPConnection.shutdownOutput(): {0}", ex); } catch (Exception ex) { - Log.get().warning("NNTPConnection.shutdownOutput(): " + ex); + Log.get().log(Level.WARNING, "NNTPConnection.shutdownOutput(): {0}", ex); } } }, 3000); @@ -227,7 +226,7 @@ raw = Arrays.copyOf(raw, raw.length - 1); } - Log.get().fine("<< " + line); + Log.get().log(Level.FINE, "<< {0}", line); if (command == null) { command = parseCommandLine(line); @@ -344,7 +343,7 @@ CharSequence debugLine) throws IOException { if (!charset.canEncode()) { - Log.get().severe("FATAL: Charset " + charset + " cannot encode!"); + Log.get().log(Level.SEVERE, "FATAL: Charset {0} cannot encode!", charset); return; } @@ -362,14 +361,14 @@ ChannelWriter.getInstance().getSelector().wakeup(); } catch (Exception ex) // CancelledKeyException and ChannelCloseException { - Log.get().warning("NNTPConnection.writeToChannel(): " + ex); + Log.get().log(Level.WARNING, "NNTPConnection.writeToChannel(): {0}", ex); return; } // Update last activity timestamp this.lastActivity = System.currentTimeMillis(); if (debugLine != null) { - Log.get().fine(">> " + debugLine); + Log.get().log(Level.FINE, ">> {0}", debugLine); } } @@ -392,34 +391,17 @@ } /** - * @return Current username. - * But user may not have been authenticated yet. - * You must check {@link #isUserAuthenticated()} + * @return Currently logged user (but you should check {@link User#isAuthenticated()}, if user is athenticated, or we just trust him) */ - public String getUsername() { - return username; + public User getUser() { + return user; } /** * This method is to be called from AUTHINFO USER Command implementation. * @param username username from AUTHINFO USER username. */ - public void setUsername(String username) { - this.username = username; - } - - /** - * @return true if current user (see {@link #getUsername()}) has been succesfully authenticated. - */ - public boolean isUserAuthenticated() { - return userAuthenticated; - } - - /** - * This method is to be called from AUTHINFO PASS Command implementation. - * @param userAuthenticated true if user has provided right password in AUTHINFO PASS password. - */ - public void setUserAuthenticated(boolean userAuthenticated) { - this.userAuthenticated = userAuthenticated; + public void setUser(User user) { + this.user = user; } }