Github user necouchman commented on a diff in the pull request:

    
https://github.com/apache/incubator-guacamole-client/pull/122#discussion_r110910803
  
    --- Diff: 
extensions/guacamole-auth-radius/src/main/java/org/apache/guacamole/auth/radius/RadiusConnectionService.java
 ---
    @@ -0,0 +1,394 @@
    +/*
    + * 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.radius;
    +
    +import com.google.inject.Inject;
    +import java.io.IOException;
    +import java.io.UnsupportedEncodingException;
    +import java.net.InetAddress;
    +import java.net.UnknownHostException;
    +import java.security.NoSuchAlgorithmException;
    +import org.apache.guacamole.GuacamoleException;
    +import org.apache.guacamole.GuacamoleUnsupportedException;
    +import org.apache.guacamole.environment.LocalEnvironment;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import net.jradius.client.RadiusClient;
    +import net.jradius.exception.RadiusException;
    +import net.jradius.packet.RadiusPacket;
    +import net.jradius.packet.AccessRequest;
    +import net.jradius.dictionary.*;
    +import net.jradius.packet.attribute.AttributeList;
    +import net.jradius.packet.attribute.RadiusAttribute;
    +import net.jradius.client.auth.EAPTLSAuthenticator;
    +import net.jradius.client.auth.EAPTTLSAuthenticator;
    +import net.jradius.client.auth.RadiusAuthenticator;
    +import net.jradius.client.auth.PEAPAuthenticator;
    +import net.jradius.packet.attribute.AttributeFactory;
    +import net.jradius.packet.AccessChallenge;
    +import net.jradius.packet.RadiusResponse;
    +
    +/**
    + * Service for creating and managing connections to RADIUS servers.
    + */
    +public class RadiusConnectionService {
    +
    +    /**
    +     * Logger for this class.
    +     */
    +    private final Logger logger = 
LoggerFactory.getLogger(RadiusConnectionService.class);
    +
    +    /**
    +     * Service for retrieving RADIUS server configuration information.
    +     */
    +    @Inject
    +    private ConfigurationService confService;
    +
    +
    +    /**
    +     * The RADIUS client;
    +     */
    +    private RadiusClient radiusClient;
    +
    +    /**
    +     * Creates a new instance of RadiusConnection, configured with 
parameters
    +     * from guacamole.properties.
    +     *
    +     * @return
    +     *     A new RadiusConnection instance which has already been 
configured 
    +     *     with parameters from guacamole.properties.
    +     *
    +     * @throws GuacamoleException
    +     *     If an error occurs while parsing guacamole.properties, or if the
    +     *     requested encryption method is actually not implemented (a bug).
    +     */
    +    private void createRadiusConnection() {
    +
    +        // Create the RADIUS client with the configuration parameters
    +        try {
    +            radiusClient = new 
RadiusClient(InetAddress.getByName(confService.getRadiusServer()),
    +                                            
confService.getRadiusSharedSecret(),
    +                                            
confService.getRadiusAuthPort(),
    +                                            
confService.getRadiusAcctPort(),
    +                                            
confService.getRadiusTimeout());
    +        }
    +        catch (GuacamoleException e) {
    +            logger.error("Unable to initialize RADIUS client: {}", 
e.getMessage());
    +            logger.debug("Failed to init RADIUS client.", e);
    +            return;
    +        }
    +        catch (UnknownHostException e) {
    +            logger.error("Unable to resolve host: {}", e.getMessage());
    +            logger.debug("Failed to resolve host.", e);
    +            return;
    +        }
    +        catch (IOException e) {
    +            logger.error("Unable to communicate with host: {}", 
e.getMessage());
    +            logger.debug("Failed to communicate with host.", e);
    +            return;
    +        }
    +
    +    }
    +
    +    /**
    +     * Creates a new instance of RadiusAuthentictor, configured with
    +     * parameters specified within guacamole.properties.
    +     *
    +     * @return
    +     *     A new RadiusAuthenticator instance which has been configured
    +     *     with parameters from guacamole.properties, or null if
    +     *     configuration fails.
    +     *
    +     */
    +    private RadiusAuthenticator setupRadiusAuthenticator() {
    +
    +        // If we don't have a radiusClient object, yet, don't go any 
further.
    +        if (radiusClient == null) {
    +            logger.error("RADIUS client hasn't been set up, yet.");
    +            logger.debug("We can't run this method until the RADIUS client 
has been set up.");
    +            return null;
    +        }
    +
    +        String radAuthName;
    +        String caFile;
    +        String caPassword;
    +        String caType;
    +        String keyFile;
    +        String keyPassword;
    +        String keyType;
    +        Boolean trustAll;
    +        String innerProtocol;
    +        LocalEnvironment guacEnv;
    +        String basePath;
    +
    +        // Pull configuration parameters from guacamole.properties
    +        try {
    +            guacEnv = new LocalEnvironment();
    +            basePath = guacEnv.getGuacamoleHome().getAbsolutePath() + '/';
    +            radAuthName = confService.getRadiusAuthProtocol();
    +            caFile = confService.getRadiusCAFile();
    +            caPassword = confService.getRadiusCAPassword();
    +            caType = confService.getRadiusCAType();
    +            keyFile = confService.getRadiusKeyFile();
    +            keyPassword = confService.getRadiusKeyPassword();
    +            keyType = confService.getRadiusKeyType();
    +            trustAll = confService.getRadiusTrustAll();
    +            innerProtocol = confService.getRadiusEAPTTLSInnerProtocol();
    +            
    +        }
    +        catch (GuacamoleException e) {
    +            logger.error("Error retrieving configuration.");
    +            logger.debug("Error getting config parameters from file.");
    +            return null;
    +        }
    +
    +        RadiusAuthenticator radAuth = 
radiusClient.getAuthProtocol(radAuthName);
    +        if (radAuth == null)
    +            return null;
    +
    +        // If we're using any of the TLS protocols, we need to configure 
them
    +        if (radAuth instanceof PEAPAuthenticator || 
    +            radAuth instanceof EAPTLSAuthenticator || 
    +            radAuth instanceof EAPTTLSAuthenticator) {
    +
    +            if (caFile != null && !caFile.isEmpty())
    --- End diff --
    
    I removed the isEmpty() checks from this, but I'm not sure removing the 
null checks from this section would really work.  It is perfectly okay to leave 
out some of these values in the configuration, and, since we're doing the 
actual RADIUS library calls here, we want to make sure we don't try to send a 
null value into one of those methods.  Some of them should never be null - for 
example keyType has a value if not specified - so I can remove those - but 
others, like the caPassword and keyPassword, could be null and we probably 
shouldn't try to send a null value, right?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to