You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@guacamole.apache.org by GitBox <gi...@apache.org> on 2020/01/26 11:37:46 UTC

[GitHub] [guacamole-client] necouchman commented on a change in pull request #374: GUACAMOLE-513: Implement Wake-on-LAN extension

necouchman commented on a change in pull request #374: GUACAMOLE-513: Implement Wake-on-LAN extension
URL: https://github.com/apache/guacamole-client/pull/374#discussion_r370992052
 
 

 ##########
 File path: extensions/guacamole-auth-wol/src/main/java/org/apache/guacamole/auth/wol/connection/WOLConnection.java
 ##########
 @@ -0,0 +1,210 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.guacamole.auth.wol.connection;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.form.Form;
+import org.apache.guacamole.form.TextField;
+import org.apache.guacamole.wol.WOLException;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.net.auth.DelegatingConnection;
+import org.apache.guacamole.wol.WakeOnLAN;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A Connection which delegates functionality to an underlying connection, but
+ * which supplies attributes specific to Wake-on-LAN functionality.
+ */
+public class WOLConnection extends DelegatingConnection {
+    
+    /**
+     * The logger for this class.
+    */
+    private static final Logger logger = LoggerFactory.getLogger(WOLConnection.class);
+
+    /**
+     * The name of the attribute for the MAC address of this host.
+     */
+    public static final String WOL_ATTRIBUTE_MAC_ADDRESS = "wol-mac-address";
+
+    /**
+     * The name of the attribute that stores the network address to use
+     * to broadcast the WOL packet.
+     */
+    public static final String WOL_ATTRIBUTE_NET_BROADCAST = "wol-net-broadcast";
+
+    /**
+     * The default broadcast address to use if none is configured.
+     */
+    public static final String WOL_DEFAULT_BROADCAST = "255.255.255.255";
+    
+    /**
+     * The form containing Wake-on-LAN attributes.
+     */
+    public static final Form WOL_ATTRIBUTE_FORM = new Form("wol-attributes",
+        Arrays.asList(
+                new TextField(WOL_ATTRIBUTE_MAC_ADDRESS),
+                new TextField(WOL_ATTRIBUTE_NET_BROADCAST)
+        )
+    );
+    
+    /**
+     * The collection of forms for Wake-on-LAN configuration.
+     */
+    public static final Collection<Form> ATTRIBUTES =
+            Collections.unmodifiableCollection(Arrays.asList(
+                    WOL_ATTRIBUTE_FORM
+        )
+    );
+
+    /**
+     * The array containing all of the WOL-specific attributes.
+     */
+    public static final List<String> WOL_ATTRIBUTES = Arrays.asList(
+            WOL_ATTRIBUTE_MAC_ADDRESS,
+            WOL_ATTRIBUTE_NET_BROADCAST
+    );
+
+    /**
+     * The attributes for this connection.
+     */
+    private final Map<String, String> attributes;
+
+    /**
+     * The undecorated connection object used as the base of this WOLConnection.
+     */
+    private final Connection undecorated;
+    
+    /**
+     * Whether or not the user has access to update the data for this connection.
+     */
+    private final Boolean canUpdate;
+
+    /**
+     * Create a WOLConnection with the specified Connection object as the
+     * base, and indicate whether the user has privileges to update this
+     * connection.
+     *
+     * @param connection
+     *     The Connection object to decorate.
+     * 
+     * @param canUpdate
+     *     Whether or not the user can update this connection.
+     */
+    public WOLConnection(Connection connection, Boolean canUpdate) {
+
+        super(connection);
+        this.undecorated = connection;
+        this.attributes = super.getAttributes();
+        this.canUpdate = canUpdate;
+
+    }
+
+    /**
+     * Get the undecorated version of the object represented by this
+     * WOLConnection.
+     *
+     * @return
+     *     The undecorated version of the Connection represented by this
+     *     WOLConnection.
+     */
+    public Connection getUndecorated() {
+        return undecorated;
+    }
+
+    @Override
+    public Map<String, String> getAttributes() {
+        
+        // Create a mutable copy of the attributes
+        Map<String, String> effectiveAttributes = new HashMap<>(attributes);
+        
+        // Check to see if any need to be added or removed
+        for (String attr : WOL_ATTRIBUTES) {
+            if (canUpdate && !effectiveAttributes.containsKey(attr))
+                effectiveAttributes.put(attr, null);
+            else if (!canUpdate && effectiveAttributes.containsKey(attr))
 
 Review comment:
   Safety, first.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services