diff --git a/CHANGELOG.md b/CHANGELOG.md index 325465a3b5..755cb3d8e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * [#268](https://github.com/dblock/waffle/pull/301): Cannot log in automatically on machine where Tomcat service is running * [#274](https://github.com/dblock/waffle/pull/274): Update WindowsSecurityContextImpl.java to handle SEC_E_BUFFER_TOO_SMALL * [#128](https://github.com/dblock/waffle/pull/128): Update WindowsSecurityContext.cs to handle SEC_E_BUFFER_TOO_SMALL +* [#310](https://github.com/dblock/waffle/pull/310): Add equals and hashCode to WindowsPrincipal 1.8.0 (09/10/15) ================ diff --git a/Source/JNA/waffle-jna/src/main/java/waffle/servlet/WindowsPrincipal.java b/Source/JNA/waffle-jna/src/main/java/waffle/servlet/WindowsPrincipal.java index 319d46981b..a59e4c3b62 100644 --- a/Source/JNA/waffle-jna/src/main/java/waffle/servlet/WindowsPrincipal.java +++ b/Source/JNA/waffle-jna/src/main/java/waffle/servlet/WindowsPrincipal.java @@ -255,4 +255,30 @@ public String toString() { return this.getName(); } + /* + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o instanceof WindowsPrincipal) { + return this.getName().equals(((WindowsPrincipal) o).getName()); + } + + return false; + } + + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return this.getName().hashCode(); + } + } diff --git a/Source/JNA/waffle-jna/src/test/java/waffle/servlet/WindowsPrincipalTest.java b/Source/JNA/waffle-jna/src/test/java/waffle/servlet/WindowsPrincipalTest.java index b42980cbb3..cf244f4386 100644 --- a/Source/JNA/waffle-jna/src/test/java/waffle/servlet/WindowsPrincipalTest.java +++ b/Source/JNA/waffle-jna/src/test/java/waffle/servlet/WindowsPrincipalTest.java @@ -46,7 +46,6 @@ public void testToString() { this.result = WindowsPrincipalTest.TEST_FQN; WindowsPrincipalTest.this.windowsIdentity.getGroups(); this.result = new IWindowsAccount[0]; - } }); final WindowsPrincipal principal = new WindowsPrincipal(this.windowsIdentity); @@ -54,4 +53,24 @@ public void testToString() { Assert.assertEquals(WindowsPrincipalTest.TEST_FQN, principal.toString()); } + /** + * Test equals and hash code. + */ + @Test + public void testEqualsAndHashCode() { + Assert.assertNotNull(new Expectations() { + { + WindowsPrincipalTest.this.windowsIdentity.getFqn(); + this.result = WindowsPrincipalTest.TEST_FQN; + WindowsPrincipalTest.this.windowsIdentity.getGroups(); + this.result = new IWindowsAccount[0]; + } + }); + WindowsPrincipal principal = new WindowsPrincipal(this.windowsIdentity); + WindowsPrincipal principal2 = new WindowsPrincipal(this.windowsIdentity); + Assert.assertTrue(principal.equals(principal2) && principal2.equals(principal)); + Assert.assertEquals(principal.hashCode(), principal2.hashCode()); + Assert.assertEquals(principal.hashCode(), WindowsPrincipalTest.TEST_FQN.hashCode()); + } + }