ACL: uživatel v Article bude jako User ne jen jako String.
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon Nov 07 17:35:43 2011 +0100 (2011-11-07)
changeset 11779ce65d63cce
parent 116 4ddc1020a154
child 118 ba7ea56fd672
ACL: uživatel v Article bude jako User ne jen jako String.
src/org/sonews/daemon/command/PostCommand.java
src/org/sonews/storage/Article.java
src/org/sonews/storage/impl/DrupalDatabase.java
     1.1 --- a/src/org/sonews/daemon/command/PostCommand.java	Sun Nov 06 00:08:05 2011 +0100
     1.2 +++ b/src/org/sonews/daemon/command/PostCommand.java	Mon Nov 07 17:35:43 2011 +0100
     1.3 @@ -213,9 +213,7 @@
     1.4  
     1.5  	private void postArticle(NNTPConnection conn, Article article)
     1.6  			throws IOException {
     1.7 -		if (conn.getUser() != null && conn.getUser().isAuthenticated()) {
     1.8 -			article.setAuthenticatedUser(conn.getUser().getUserName());
     1.9 -		}
    1.10 +		article.setUser(conn.getUser());
    1.11  
    1.12  		if (article.getHeader(Headers.CONTROL)[0].length() > 0) {
    1.13  			controlMessage(conn, article);
     2.1 --- a/src/org/sonews/storage/Article.java	Sun Nov 06 00:08:05 2011 +0100
     2.2 +++ b/src/org/sonews/storage/Article.java	Mon Nov 07 17:35:43 2011 +0100
     2.3 @@ -31,6 +31,7 @@
     2.4  import javax.mail.Message;
     2.5  import javax.mail.MessagingException;
     2.6  import javax.mail.internet.InternetHeaders;
     2.7 +import org.sonews.acl.User;
     2.8  import org.sonews.config.Config;
     2.9  import org.sonews.util.Log;
    2.10  
    2.11 @@ -42,7 +43,7 @@
    2.12   */
    2.13  public class Article extends ArticleHead {
    2.14  	
    2.15 -	private String authenticatedUser;
    2.16 +	private User sender;
    2.17  
    2.18  	/**
    2.19  	 * Loads the Article identified by the given ID from the JDBCDatabase.
    2.20 @@ -224,17 +225,17 @@
    2.21  	}
    2.22  
    2.23  	/**
    2.24 -	 * @return username of currently logged user – or null, if user is not authenticated.
    2.25 +	 * @return sender – currently logged user – or null, if user is not authenticated.
    2.26  	 */
    2.27 -	public String getAuthenticatedUser() {
    2.28 -		return authenticatedUser;
    2.29 +	public User getUser() {
    2.30 +		return sender;
    2.31  	}
    2.32  	
    2.33  	/**
    2.34  	 * This method is to be called from POST Command implementation.
    2.35 -	 * @param authenticatedUser current username – or null, if user is not authenticated.
    2.36 +	 * @param sender current username – or null, if user is not authenticated.
    2.37  	 */
    2.38 -	public void setAuthenticatedUser(String authenticatedUser) {
    2.39 -		this.authenticatedUser = authenticatedUser;
    2.40 +	public void setUser(User sender) {
    2.41 +		this.sender = sender;
    2.42  	}
    2.43  }
     3.1 --- a/src/org/sonews/storage/impl/DrupalDatabase.java	Sun Nov 06 00:08:05 2011 +0100
     3.2 +++ b/src/org/sonews/storage/impl/DrupalDatabase.java	Mon Nov 07 17:35:43 2011 +0100
     3.3 @@ -401,10 +401,8 @@
     3.4  	 */
     3.5  	@Override
     3.6  	public void addArticle(Article article) throws StorageBackendException {
     3.7 -		if (article.getAuthenticatedUser() == null) {
     3.8 -			log.log(Level.SEVERE, "User was not authenticated, so his article was rejected.");
     3.9 -			throw new StorageBackendException("User must be authenticated to post articles");
    3.10 -		} else {
    3.11 +		if (article.getUser() != null && article.getUser().isAuthenticated()) {
    3.12 +			
    3.13  			try {
    3.14  				DrupalMessage m = new DrupalMessage(article);
    3.15  
    3.16 @@ -426,12 +424,16 @@
    3.17  						}
    3.18  					}
    3.19  
    3.20 -					insertArticle(article.getAuthenticatedUser(), subject, text, parentID, groupID);
    3.21 -					log.log(Level.INFO, "User ''{0}'' has posted an article", article.getAuthenticatedUser());
    3.22 +					insertArticle(article.getUser().getUserName(), subject, text, parentID, groupID);
    3.23 +					log.log(Level.INFO, "User ''{0}'' has posted an article", article.getUser().getUserName());
    3.24  				}
    3.25  			} catch (Exception e) {
    3.26  				throw new StorageBackendException(e);
    3.27  			}
    3.28 +			
    3.29 +		} else {
    3.30 +			log.log(Level.SEVERE, "User was not authenticated, so his article was rejected.");
    3.31 +			throw new StorageBackendException("User must be authenticated to post articles");
    3.32  		}
    3.33  	}
    3.34