/*
- * Sone - FcpInterface.java - Copyright © 2011–2016 David Roden
+ * Sone - FcpInterface.java - Copyright © 2011–2019 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/**
* Implementation of an FCP interface for other clients or plugins to
* communicate with Sone.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
@Singleton
public class FcpInterface {
/**
* The action level that full access for the FCP connection is required.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
public enum FullAccessRequired {
private final AtomicBoolean active = new AtomicBoolean();
/** What function full access is required for. */
- private final AtomicReference<FullAccessRequired> fullAccessRequired = new AtomicReference<FullAccessRequired>(FullAccessRequired.ALWAYS);
+ private final AtomicReference<FullAccessRequired> fullAccessRequired = new AtomicReference<>(FullAccessRequired.ALWAYS);
/** All available FCP commands. */
private final Map<String, AbstractSoneCommand> commands;
* {@link FredPluginFCP#ACCESS_FCP_RESTRICTED}
*/
public void handle(PluginReplySender pluginReplySender, SimpleFieldSet parameters, Bucket data, int accessType) {
+ String identifier = parameters.get("Identifier");
+ if ((identifier == null) || (identifier.length() == 0)) {
+ sendErrorReply(pluginReplySender, null, 400, "Missing Identifier.");
+ return;
+ }
if (!active.get()) {
- sendErrorReply(pluginReplySender, null, 503, "FCP Interface deactivated");
+ sendErrorReply(pluginReplySender, identifier, 503, "FCP Interface deactivated");
return;
}
AbstractSoneCommand command = commands.get(parameters.get("Message"));
if (command == null) {
- sendErrorReply(pluginReplySender, null, 404, "Unrecognized Message: " + parameters.get("Message"));
+ sendErrorReply(pluginReplySender, identifier, 404, "Unrecognized Message: " + parameters.get("Message"));
return;
}
if (!accessAuthorizer.authorized(AccessType.values()[accessType], fullAccessRequired.get(), command.requiresWriteAccess())) {
- sendErrorReply(pluginReplySender, null, 401, "Not authorized");
- return;
- }
- String identifier = parameters.get("Identifier");
- if ((identifier == null) || (identifier.length() == 0)) {
- sendErrorReply(pluginReplySender, null, 400, "Missing Identifier.");
+ sendErrorReply(pluginReplySender, identifier, 401, "Not authorized");
return;
}
try {