Unverified 提交 d4ed1a5d authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1230 from grandinj/cleanup1

clean up some javadoc and some throws clauses
...@@ -11,7 +11,6 @@ import java.sql.SQLException; ...@@ -11,7 +11,6 @@ import java.sql.SQLException;
import java.sql.SQLWarning; import java.sql.SQLWarning;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.engine.SessionInterface; import org.h2.engine.SessionInterface;
...@@ -944,8 +943,8 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme ...@@ -944,8 +943,8 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
* *
* @param sql the SQL statement * @param sql the SQL statement
* @param autoGeneratedKeys * @param autoGeneratedKeys
* {@link Statement.RETURN_GENERATED_KEYS} if generated keys should * {@link Statement#RETURN_GENERATED_KEYS} if generated keys should
* be available for retrieval, {@link Statement.NO_GENERATED_KEYS} if * be available for retrieval, {@link Statement#NO_GENERATED_KEYS} if
* generated keys should not be available * generated keys should not be available
* @return the update count (number of row affected by an insert, * @return the update count (number of row affected by an insert,
* update or delete, or 0 if no rows or the statement was a * update or delete, or 0 if no rows or the statement was a
...@@ -971,8 +970,8 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme ...@@ -971,8 +970,8 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
* *
* @param sql the SQL statement * @param sql the SQL statement
* @param autoGeneratedKeys * @param autoGeneratedKeys
* {@link Statement.RETURN_GENERATED_KEYS} if generated keys should * {@link Statement#RETURN_GENERATED_KEYS} if generated keys should
* be available for retrieval, {@link Statement.NO_GENERATED_KEYS} if * be available for retrieval, {@link Statement#NO_GENERATED_KEYS} if
* generated keys should not be available * generated keys should not be available
* @return the update count (number of row affected by an insert, * @return the update count (number of row affected by an insert,
* update or delete, or 0 if no rows or the statement was a * update or delete, or 0 if no rows or the statement was a
...@@ -1097,8 +1096,8 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme ...@@ -1097,8 +1096,8 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
* *
* @param sql the SQL statement * @param sql the SQL statement
* @param autoGeneratedKeys * @param autoGeneratedKeys
* {@link Statement.RETURN_GENERATED_KEYS} if generated keys should * {@link Statement#RETURN_GENERATED_KEYS} if generated keys should
* be available for retrieval, {@link Statement.NO_GENERATED_KEYS} if * be available for retrieval, {@link Statement#NO_GENERATED_KEYS} if
* generated keys should not be available * generated keys should not be available
* @return the update count (number of row affected by an insert, * @return the update count (number of row affected by an insert,
* update or delete, or 0 if no rows or the statement was a * update or delete, or 0 if no rows or the statement was a
......
...@@ -59,8 +59,6 @@ public class AuthenticationInfo { ...@@ -59,8 +59,6 @@ public class AuthenticationInfo {
/** /**
* get nested identity * get nested identity
*
* @return
*/ */
public Object getNestedIdentity() { public Object getNestedIdentity() {
return nestedIdentity; return nestedIdentity;
......
...@@ -16,11 +16,8 @@ public interface Authenticator { ...@@ -16,11 +16,8 @@ public interface Authenticator {
/** /**
* Perform user authentication. * Perform user authentication.
* *
* @param authenticationInfo
* @param database
* @return valid database user or null if user doesn't exists in the * @return valid database user or null if user doesn't exists in the
* database * database
* @throws AuthenticationException
*/ */
User authenticate(AuthenticationInfo authenticationInfo, Database database) throws AuthenticationException; User authenticate(AuthenticationInfo authenticationInfo, Database database) throws AuthenticationException;
...@@ -28,9 +25,7 @@ public interface Authenticator { ...@@ -28,9 +25,7 @@ public interface Authenticator {
* Initialize the authenticator. This method is invoked by databases when * Initialize the authenticator. This method is invoked by databases when
* the authenticator is set when the authenticator is set. * the authenticator is set when the authenticator is set.
* *
* @param database * @param database target database
* target database
* @throws AuthConfigException
*/ */
void init(Database database) throws AuthConfigException; void init(Database database) throws AuthConfigException;
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
*/ */
package org.h2.security.auth; package org.h2.security.auth;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -13,7 +14,7 @@ import java.util.HashSet; ...@@ -13,7 +14,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import org.h2.api.CredentialsValidator; import org.h2.api.CredentialsValidator;
import org.h2.api.UserToRolesMapper; import org.h2.api.UserToRolesMapper;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -26,6 +27,7 @@ import org.h2.message.Trace; ...@@ -26,6 +27,7 @@ import org.h2.message.Trace;
import org.h2.security.auth.impl.AssignRealmNameRole; import org.h2.security.auth.impl.AssignRealmNameRole;
import org.h2.security.auth.impl.JaasCredentialsValidator; import org.h2.security.auth.impl.JaasCredentialsValidator;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.xml.sax.SAXException;
/** /**
* Default authenticator implementation. * Default authenticator implementation.
...@@ -93,8 +95,6 @@ public class DefaultAuthenticator implements Authenticator { ...@@ -93,8 +95,6 @@ public class DefaultAuthenticator implements Authenticator {
/** /**
* If set save users externals defined during the authentication. * If set save users externals defined during the authentication.
*
* @return
*/ */
public boolean isPersistUsers() { public boolean isPersistUsers() {
return persistUsers; return persistUsers;
...@@ -106,8 +106,6 @@ public class DefaultAuthenticator implements Authenticator { ...@@ -106,8 +106,6 @@ public class DefaultAuthenticator implements Authenticator {
/** /**
* If set create external users in the database if not present. * If set create external users in the database if not present.
*
* @return
*/ */
public boolean isAllowUserRegistration() { public boolean isAllowUserRegistration() {
return allowUserRegistration; return allowUserRegistration;
...@@ -120,8 +118,6 @@ public class DefaultAuthenticator implements Authenticator { ...@@ -120,8 +118,6 @@ public class DefaultAuthenticator implements Authenticator {
/** /**
* When set create roles not found in the database. If not set roles not * When set create roles not found in the database. If not set roles not
* found in the database are silently skipped * found in the database are silently skipped
*
* @return
*/ */
public boolean isCreateMissingRoles() { public boolean isCreateMissingRoles() {
return createMissingRoles; return createMissingRoles;
...@@ -170,9 +166,7 @@ public class DefaultAuthenticator implements Authenticator { ...@@ -170,9 +166,7 @@ public class DefaultAuthenticator implements Authenticator {
* <li>Use the default configuration hard coded</li> * <li>Use the default configuration hard coded</li>
* </ol> * </ol>
* *
* @param database * @param database where authenticator is initialized
* where authenticator is initialized
* @throws AuthConfigException
*/ */
@Override @Override
public void init(Database database) throws AuthConfigException { public void init(Database database) throws AuthConfigException {
...@@ -230,23 +224,22 @@ public class DefaultAuthenticator implements Authenticator { ...@@ -230,23 +224,22 @@ public class DefaultAuthenticator implements Authenticator {
/** /**
* Configure the authenticator from a configuration file * Configure the authenticator from a configuration file
* *
* @param configUrl * @param configUrl URL of configuration file
* URL of configuration file
* @throws Exception
*/ */
public void configureFromUrl(URL configUrl) throws Exception { public void configureFromUrl(URL configUrl) throws AuthenticationException,
SAXException, IOException, ParserConfigurationException {
H2AuthConfig config = H2AuthConfigXml.parseFrom(configUrl); H2AuthConfig config = H2AuthConfigXml.parseFrom(configUrl);
configureFrom(config); configureFrom(config);
} }
void configureFrom(H2AuthConfig config) throws Exception { void configureFrom(H2AuthConfig config) throws AuthenticationException {
allowUserRegistration = config.isAllowUserRegistration(); allowUserRegistration = config.isAllowUserRegistration();
createMissingRoles = config.isCreateMissingRoles(); createMissingRoles = config.isCreateMissingRoles();
Map<String, CredentialsValidator> newRealms = new HashMap<>(); Map<String, CredentialsValidator> newRealms = new HashMap<>();
for (RealmConfig currentRealmConfig : config.getRealms()) { for (RealmConfig currentRealmConfig : config.getRealms()) {
String currentRealmName = currentRealmConfig.getName(); String currentRealmName = currentRealmConfig.getName();
if (currentRealmName == null) { if (currentRealmName == null) {
throw new Exception("Missing realm name"); throw new AuthenticationException("Missing realm name");
} }
currentRealmName = currentRealmName.toUpperCase(); currentRealmName = currentRealmName.toUpperCase();
CredentialsValidator currentValidator = null; CredentialsValidator currentValidator = null;
...@@ -254,11 +247,11 @@ public class DefaultAuthenticator implements Authenticator { ...@@ -254,11 +247,11 @@ public class DefaultAuthenticator implements Authenticator {
currentValidator = (CredentialsValidator) Class.forName(currentRealmConfig.getValidatorClass()) currentValidator = (CredentialsValidator) Class.forName(currentRealmConfig.getValidatorClass())
.newInstance(); .newInstance();
} catch (Exception e) { } catch (Exception e) {
throw new Exception("invalid validator class fo realm " + currentRealmName, e); throw new AuthenticationException("invalid validator class fo realm " + currentRealmName, e);
} }
currentValidator.configure(new ConfigProperties(currentRealmConfig.getProperties())); currentValidator.configure(new ConfigProperties(currentRealmConfig.getProperties()));
if (newRealms.put(currentRealmConfig.getName().toUpperCase(), currentValidator) != null) { if (newRealms.put(currentRealmConfig.getName().toUpperCase(), currentValidator) != null) {
throw new Exception("Duplicate realm " + currentRealmConfig.getName()); throw new AuthenticationException("Duplicate realm " + currentRealmConfig.getName());
} }
} }
this.realms = newRealms; this.realms = newRealms;
...@@ -269,7 +262,7 @@ public class DefaultAuthenticator implements Authenticator { ...@@ -269,7 +262,7 @@ public class DefaultAuthenticator implements Authenticator {
currentUserToRolesMapper = (UserToRolesMapper) Class currentUserToRolesMapper = (UserToRolesMapper) Class
.forName(currentUserToRolesMapperConfig.getClassName()).newInstance(); .forName(currentUserToRolesMapperConfig.getClassName()).newInstance();
} catch (Exception e) { } catch (Exception e) {
throw new Exception("Invalid class in UserToRolesMapperConfig", e); throw new AuthenticationException("Invalid class in UserToRolesMapperConfig", e);
} }
currentUserToRolesMapper.configure(new ConfigProperties(currentUserToRolesMapperConfig.getProperties())); currentUserToRolesMapper.configure(new ConfigProperties(currentUserToRolesMapperConfig.getProperties()));
newUserToRolesMapper.add(currentUserToRolesMapper); newUserToRolesMapper.add(currentUserToRolesMapper);
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
*/ */
package org.h2.security.auth; package org.h2.security.auth;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
...@@ -91,20 +91,19 @@ public class H2AuthConfigXml extends DefaultHandler{ ...@@ -91,20 +91,19 @@ public class H2AuthConfigXml extends DefaultHandler{
/** /**
* Parse the xml * Parse the xml
* @param url
* @return
* @throws Exception
*/ */
public static H2AuthConfig parseFrom(URL url) throws Exception{ public static H2AuthConfig parseFrom(URL url)
try (InputStream inputStream= url.openStream()) { throws SAXException, IOException, ParserConfigurationException {
try (InputStream inputStream = url.openStream()) {
return parseFrom(inputStream); return parseFrom(inputStream);
} }
} }
public static H2AuthConfig parseFrom(InputStream inputStream) throws Exception{ public static H2AuthConfig parseFrom(InputStream inputStream)
throws SAXException, IOException, ParserConfigurationException {
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
H2AuthConfigXml xmlHandler = new H2AuthConfigXml(); H2AuthConfigXml xmlHandler = new H2AuthConfigXml();
saxParser.parse(inputStream,xmlHandler); saxParser.parse(inputStream, xmlHandler);
return xmlHandler.getResult(); return xmlHandler.getResult();
} }
} }
...@@ -30,7 +30,6 @@ import java.sql.Types; ...@@ -30,7 +30,6 @@ import java.sql.Types;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Properties; import java.util.Properties;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.engine.ConnectionInfo; import org.h2.engine.ConnectionInfo;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -508,7 +507,7 @@ public class PgServerThread implements Runnable { ...@@ -508,7 +507,7 @@ public class PgServerThread implements Runnable {
sendMessage(); sendMessage();
} }
private void sendDataRow(ResultSet rs, int[] formatCodes) throws Exception { private void sendDataRow(ResultSet rs, int[] formatCodes) throws IOException, SQLException {
ResultSetMetaData metaData = rs.getMetaData(); ResultSetMetaData metaData = rs.getMetaData();
int columns = metaData.getColumnCount(); int columns = metaData.getColumnCount();
startMessage('D'); startMessage('D');
...@@ -535,7 +534,7 @@ public class PgServerThread implements Runnable { ...@@ -535,7 +534,7 @@ public class PgServerThread implements Runnable {
} }
private void writeDataColumn(ResultSet rs, int column, int pgType, boolean text) private void writeDataColumn(ResultSet rs, int column, int pgType, boolean text)
throws Exception { throws IOException {
Value v = ((JdbcResultSet) rs).get(column); Value v = ((JdbcResultSet) rs).get(column);
if (v == ValueNull.INSTANCE) { if (v == ValueNull.INSTANCE) {
writeInt(-1); writeInt(-1);
...@@ -758,7 +757,7 @@ public class PgServerThread implements Runnable { ...@@ -758,7 +757,7 @@ public class PgServerThread implements Runnable {
sendMessage(); sendMessage();
} }
private void sendRowDescription(ResultSetMetaData meta) throws Exception { private void sendRowDescription(ResultSetMetaData meta) throws IOException, SQLException {
if (meta == null) { if (meta == null) {
sendNoData(); sendNoData();
} else { } else {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论