Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extended EnterpriseWifi class #83

Merged
merged 9 commits into from
Oct 30, 2016
Merged

Conversation

Fleker
Copy link
Contributor

@Fleker Fleker commented Oct 28, 2016

Adds support for connecting to enterprise wi-fi networks that have both a username and password. This is a fix for #82.

@kenglxn
Copy link
Owner

kenglxn commented Oct 28, 2016

Cool. Although the changes are not mergable at this time due to compile errors.
Also I would like to have some tests for this code. You could look at https://github.com/kenglxn/QRGen/blob/master/core/src/test/java/net/glxn/qrgen/core/scheme/WifiTest.java for example.

Took a quick look at the compile errors and this should solve the issue:

diff --git a/core/src/main/java/net/glxn/qrgen/core/scheme/EnterpriseWifi.java b/core/src/main/java/net/glxn/qrgen/core/scheme/EnterpriseWifi.java
index a9ec9ef..aee8bc1 100644
--- a/core/src/main/java/net/glxn/qrgen/core/scheme/EnterpriseWifi.java
+++ b/core/src/main/java/net/glxn/qrgen/core/scheme/EnterpriseWifi.java
@@ -25,7 +25,7 @@ public class EnterpriseWifi extends Wifi {
             throw new IllegalArgumentException(
                     "this is not a valid WIFI code: " + wifiCode);
         }
-        Wifi wifi = new Wifi();
+        EnterpriseWifi wifi = new EnterpriseWifi();
         Map<String, String> parameters = getParameters(
                 wifiCode.substring(WIFI_PROTOCOL_HEADER.length()), "(?<!\\\\);");
         if (parameters.containsKey(SSID)) {
@@ -35,7 +35,7 @@ public class EnterpriseWifi extends Wifi {
             wifi.setPsk(unescape(parameters.get(PSK)));
         }
         if (parameters.containsKey(USER)) {
-            wifi.setUser(unescape(parameters.get(USER)));
+            wifi.setUsername(unescape(parameters.get(USER)));
         }
         if (parameters.containsKey(EAP)) {
             wifi.setEap(unescape(parameters.get(EAP)));
@@ -64,20 +64,20 @@ public class EnterpriseWifi extends Wifi {
     }

     public EnterpriseWifi setUsername(String username) {
-        withUsername(username);
+        return withUsername(username);
     }

     public String getUsername() {
         return username;
     }

-    public EnterpriseWifi withEap(Strin eap) {
+    public EnterpriseWifi withEap(String eap) {
         this.eap = eap;
         return this;
     }

     public EnterpriseWifi setEap(String eap) {
-        withEap(eap);
+        return withEap(eap);
     }

     public String getEap() {

@Fleker
Copy link
Contributor Author

Fleker commented Oct 28, 2016

I'll definitely take a look at fixing this over the weekend.

On Oct 28, 2016 9:26 AM, "Ken Gullaksen" [email protected] wrote:

Cool. Although the changes are not mergable at this time due to compile
errors.
Also I would like to have some tests for this code. You could look at
https://github.com/kenglxn/QRGen/blob/master/core/src/
test/java/net/glxn/qrgen/core/scheme/WifiTest.java for example.

Took a quick look at the compile errors and this should solve the issue:

diff --git a/core/src/main/java/net/glxn/qrgen/core/scheme/EnterpriseWifi.java b/core/src/main/java/net/glxn/qrgen/core/scheme/EnterpriseWifi.java
index a9ec9ef..aee8bc1 100644--- a/core/src/main/java/net/glxn/qrgen/core/scheme/EnterpriseWifi.java+++ b/core/src/main/java/net/glxn/qrgen/core/scheme/EnterpriseWifi.java@@ -25,7 +25,7 @@ public class EnterpriseWifi extends Wifi {
throw new IllegalArgumentException(
"this is not a valid WIFI code: " + wifiCode);
}- Wifi wifi = new Wifi();+ EnterpriseWifi wifi = new EnterpriseWifi();
Map<String, String> parameters = getParameters(
wifiCode.substring(WIFI_PROTOCOL_HEADER.length()), "(?<!\);");
if (parameters.containsKey(SSID)) {@@ -35,7 +35,7 @@ public class EnterpriseWifi extends Wifi {
wifi.setPsk(unescape(parameters.get(PSK)));
}
if (parameters.containsKey(USER)) {- wifi.setUser(unescape(parameters.get(USER)));+ wifi.setUsername(unescape(parameters.get(USER)));
}
if (parameters.containsKey(EAP)) {
wifi.setEap(unescape(parameters.get(EAP)));@@ -64,20 +64,20 @@ public class EnterpriseWifi extends Wifi {
}

 public EnterpriseWifi setUsername(String username) {-        withUsername(username);+        return withUsername(username);
 }

 public String getUsername() {
     return username;
 }
  • public EnterpriseWifi withEap(Strin eap) {+ public EnterpriseWifi withEap(String eap) {
    this.eap = eap;
    return this;
    }

public EnterpriseWifi setEap(String eap) {- withEap(eap);+ return withEap(eap);
}

public String getEap() {


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#83 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ADI580UvfQT5gIk2qru-oVJusrP_urTfks5q4fgVgaJpZM4Ki-oY
.

@Fleker
Copy link
Contributor Author

Fleker commented Oct 29, 2016

Build compiles and the tests pass 👍

Copy link
Owner

@kenglxn kenglxn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you. I have two small things I would like changed before I merge this :)

protected static final String AUTHENTICATION = "T";
protected static final String SSID = "S";
protected static final String PSK = "P";
protected static final String HIDDEN = "H";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer these to be public static final:

    public static final String WIFI_PROTOCOL_HEADER = "WIFI:";
    public static final String AUTHENTICATION = "T";
    public static final String SSID = "S";
    public static final String PSK = "P";
    public static final String HIDDEN = "H";

protected String authentication;
protected String ssid;
protected String psk;
protected boolean hidden = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can remain private:

    private String authentication;
    private String ssid;
    private String psk;
    private boolean hidden = false;

@Fleker
Copy link
Contributor Author

Fleker commented Oct 30, 2016

👍

@kenglxn kenglxn merged commit c778c19 into kenglxn:master Oct 30, 2016
@kenglxn
Copy link
Owner

kenglxn commented Oct 30, 2016

Thank you for the PR. I will publish it as part of a new minor tomorrow👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants