Skip to content

Commit

Permalink
Rename ConfigurationException in InvalidConfigurationException
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jul 2, 2019
1 parent 27c449b commit 3899a90
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.eclipse.leshan.server.bootstrap.BootstrapConfig;
import org.eclipse.leshan.server.bootstrap.BootstrapStore;
import org.eclipse.leshan.server.bootstrap.ConfigurationChecker;
import org.eclipse.leshan.server.bootstrap.ConfigurationChecker.ConfigurationException;
import org.eclipse.leshan.server.bootstrap.InvalidConfigurationException;
import org.eclipse.leshan.util.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -79,7 +79,7 @@ public BootstrapConfig getBootstrap(String endpoint, Identity deviceIdentity) {
return bootstrapByEndpoint.get(endpoint);
}

public void addConfig(String endpoint, BootstrapConfig config) throws ConfigurationException {
public void addConfig(String endpoint, BootstrapConfig config) throws InvalidConfigurationException {
configChecker.verify(config);
bootstrapByEndpoint.put(endpoint, config);
saveToFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import org.apache.commons.lang.StringUtils;
import org.eclipse.leshan.server.bootstrap.BootstrapConfig;
import org.eclipse.leshan.server.bootstrap.ConfigurationChecker.ConfigurationException;
import org.eclipse.leshan.server.bootstrap.InvalidConfigurationException;
import org.eclipse.leshan.server.bootstrap.demo.BootstrapStoreImpl;

import com.google.gson.Gson;
Expand Down Expand Up @@ -114,7 +114,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
bsStore.addConfig(endpoint, cfg);
resp.setStatus(HttpServletResponse.SC_OK);
}
} catch (JsonSyntaxException | ConfigurationException e) {
} catch (JsonSyntaxException | InvalidConfigurationException e) {
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public ConfigurationChecker(String[] algorithms) {
/**
* Verify if the {@link BootstrapConfig} is valid and consistent.
* <p>
* Raise a {@link ConfigurationException} if config is not OK.
* Raise a {@link InvalidConfigurationException} if config is not OK.
*
* @param config the bootstrap configuration to check.
* @throws ConfigurationException if bootstrap configuration is not invalid.
* @throws InvalidConfigurationException if bootstrap configuration is not invalid.
*/
public void verify(BootstrapConfig config) throws ConfigurationException {
public void verify(BootstrapConfig config) throws InvalidConfigurationException {
// check security configurations
for (Map.Entry<Integer, BootstrapConfig.ServerSecurity> e : config.security.entrySet()) {
BootstrapConfig.ServerSecurity sec = e.getValue();
Expand Down Expand Up @@ -97,18 +97,18 @@ public void verify(BootstrapConfig config) throws ConfigurationException {
validateOneSecurityByServer(config);
}

protected void checkNoSec(ServerSecurity sec) throws ConfigurationException {
protected void checkNoSec(ServerSecurity sec) throws InvalidConfigurationException {
assertIf(!isEmpty(sec.secretKey), "NO-SEC mode, secret key must be empty");
assertIf(!isEmpty(sec.publicKeyOrId), "NO-SEC mode, public key or ID must be empty");
assertIf(!isEmpty(sec.serverPublicKey), "NO-SEC mode, server public key must be empty");
}

protected void checkPSK(ServerSecurity sec) throws ConfigurationException {
protected void checkPSK(ServerSecurity sec) throws InvalidConfigurationException {
assertIf(isEmpty(sec.secretKey), "pre-shared-key mode, secret key must not be empty");
assertIf(isEmpty(sec.publicKeyOrId), "pre-shared-key mode, public key or id must not be empty");
}

protected void checkRPK(ServerSecurity sec) throws ConfigurationException {
protected void checkRPK(ServerSecurity sec) throws InvalidConfigurationException {
assertIf(isEmpty(sec.secretKey), "raw-public-key mode, secret key must not be empty");
assertIf(decodeRfc5958PrivateKey(sec.secretKey) == null,
"raw-public-key mode, secret key must be RFC5958 encoded private key");
Expand All @@ -120,7 +120,7 @@ protected void checkRPK(ServerSecurity sec) throws ConfigurationException {
"raw-public-key mode, server public key must be RFC7250 encoded public key");
}

protected void checkX509(ServerSecurity sec) throws ConfigurationException {
protected void checkX509(ServerSecurity sec) throws InvalidConfigurationException {
assertIf(isEmpty(sec.secretKey), "x509 mode, secret key must not be empty");
assertIf(decodeRfc5958PrivateKey(sec.secretKey) == null,
"x509 mode, secret key must be RFC5958 encoded private key");
Expand All @@ -132,39 +132,39 @@ protected void checkX509(ServerSecurity sec) throws ConfigurationException {
"x509 mode, server public key must be DER encoded X.509 certificate");
}

protected void validateMandatoryField(ServerSecurity sec) throws ConfigurationException {
protected void validateMandatoryField(ServerSecurity sec) throws InvalidConfigurationException {
// checks mandatory fields
if (StringUtils.isEmpty(sec.uri))
throw new ConfigurationException("LwM2M Server URI is mandatory");
throw new InvalidConfigurationException("LwM2M Server URI is mandatory");
if (sec.securityMode == null)
throw new ConfigurationException("Security Mode is mandatory");
throw new InvalidConfigurationException("Security Mode is mandatory");

}

/**
* Each server entry must have 1 security entry.
*
* @param config the bootstrap configuration to check.
* @throws ConfigurationException if bootstrap configuration is not invalid.
* @throws InvalidConfigurationException if bootstrap configuration is not invalid.
*/
protected void validateOneSecurityByServer(BootstrapConfig config) throws ConfigurationException {
protected void validateOneSecurityByServer(BootstrapConfig config) throws InvalidConfigurationException {
for (Map.Entry<Integer, BootstrapConfig.ServerConfig> e : config.servers.entrySet()) {
BootstrapConfig.ServerConfig srvCfg = e.getValue();

// shortId checks
if (srvCfg.shortId == 0) {
throw new ConfigurationException("short ID must not be 0");
throw new InvalidConfigurationException("short ID must not be 0");
}

// look for security entry
BootstrapConfig.ServerSecurity security = getSecurityEntry(config, srvCfg.shortId);

if (security == null) {
throw new ConfigurationException("no security entry for server instance: " + e.getKey());
throw new InvalidConfigurationException("no security entry for server instance: " + e.getKey());
}

if (security.bootstrapServer) {
throw new ConfigurationException(
throw new InvalidConfigurationException(
"the security entry for server " + e.getKey() + " should not be a bootstrap server");
}
}
Expand Down Expand Up @@ -219,9 +219,9 @@ protected Certificate decodeCertificate(byte[] encodedCert) {
}
}

protected static void assertIf(boolean condition, String message) throws ConfigurationException {
protected static void assertIf(boolean condition, String message) throws InvalidConfigurationException {
if (condition) {
throw new ConfigurationException(message);
throw new InvalidConfigurationException(message);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@
/**
* Exception raised when {@link BootstrapConfig} is invalid.
*/
public class ConfigurationException extends Exception {
public class InvalidConfigurationException extends Exception {

private static final long serialVersionUID = 1L;

public ConfigurationException() {
public InvalidConfigurationException() {
}

public ConfigurationException(String m) {
public InvalidConfigurationException(String m) {
super(m);
}

public ConfigurationException(String m, Object... args) {
public InvalidConfigurationException(String m, Object... args) {
super(String.format(m, args));
}

public ConfigurationException(Throwable e) {
public InvalidConfigurationException(Throwable e) {
super(e);
}

public ConfigurationException(String m, Throwable e) {
public InvalidConfigurationException(String m, Throwable e) {
super(m, e);
}

public ConfigurationException(Throwable e, String m, Object... args) {
public InvalidConfigurationException(Throwable e, String m, Object... args) {
super(String.format(m, args), e);
}
}

0 comments on commit 3899a90

Please sign in to comment.