diff -r 1feed5fbf147 -r d54786065fa3 src/org/sonews/storage/impl/DrupalDatabase.java --- a/src/org/sonews/storage/impl/DrupalDatabase.java Wed Oct 12 00:25:14 2011 +0200 +++ b/src/org/sonews/storage/impl/DrupalDatabase.java Wed Oct 19 21:40:51 2011 +0200 @@ -28,6 +28,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.sonews.config.Config; +import org.sonews.daemon.Connections; import org.sonews.feed.Subscription; import org.sonews.storage.Article; import org.sonews.storage.ArticleHead; @@ -387,9 +388,41 @@ return Collections.emptyList(); } + /** + * Checks username and password. + * @param username + * @param password + * @return true if credentials are valid | false otherwise + * @throws StorageBackendException it there is any error during authentication process + * (but should not be thrown if only bad thing is wrong username or password) + */ + @Override + public boolean authenticateUser(String username, char[] password) throws StorageBackendException { + PreparedStatement ps = null; + ResultSet rs = null; + try { + ps = conn.prepareStatement("SELECT nntp_login(?, ?)"); + ps.setString(1, username); + ps.setString(2, String.copyValueOf(password)); + rs = ps.executeQuery(); + rs.next(); + return rs.getInt(1) == 1; + } catch (Exception e) { + throw new StorageBackendException(e); + } finally { + close(null, ps, rs); + } + } + @Override public void addArticle(Article art) throws StorageBackendException { - log.log(Level.SEVERE, "TODO: addArticle {0}", new Object[]{art}); + if (art.getAuthenticatedUser() == null) { + log.log(Level.SEVERE, "User was not authenticated, so his article was rejected."); + throw new StorageBackendException("User must be authenticated to post articles"); + } else { + + log.log(Level.INFO, "User ''{0}'' has posted an article", art.getAuthenticatedUser()); + } } @Override