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

Add equals and hashCode to WindowsPrincipal #310

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sup with this changelog losing all the convention of having a period at the end and the name of the contributor? Maybe not in this PR, but someone please make it look more consistent :)

Copy link
Member

Choose a reason for hiding this comment

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

I can look into fixing it. I'd love to automate it. I'll look into that as well. It's otherwise prone to human error ;)

Sent from Outlook Mobile

On Wed, Jan 13, 2016 at 4:08 AM -0800, "Daniel Doubrovkine (dB.) @dblockdotorg" notifications@github.com wrote:

@@ -11,6 +11,7 @@

  • #268: Cannot log in automatically on machine where Tomcat service is running
  • #274: Update WindowsSecurityContextImpl.java to handle SEC_E_BUFFER_TOO_SMALL
  • #128: Update WindowsSecurityContext.cs to handle SEC_E_BUFFER_TOO_SMALL
    +* #310: Add equals and hashCode to WindowsPrincipal

Sup with this changelog losing all the convention of having a period at the end and the name of the contributor? Maybe not in this PR, but someone please make it look more consistent :)


Reply to this email directly or view it on GitHub:
https://github.com/dblock/waffle/pull/310/files#r49582512

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Personally I think automation makes it hard to read. I generally pay a lot of attention to change logs in projects and I want something closer to a human explanation of what has changed. Just my 0.02c.


1.8.0 (09/10/15)
================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the class be marked as final for immutability?

Copy link
Member

Choose a reason for hiding this comment

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

It appears it could be but that just stops extending it and overriding methods in it. Since it doesn't contain anything to change mutability other than a new instance it's probably ok. I'll have to look further to see why it has two non final fields. Feel free to investigate a bit further. Thanks.

Sent from Outlook Mobile

On Mon, Jan 11, 2016 at 12:13 PM -0800, "Sergey Podolsky" notifications@github.com wrote:

@@ -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) {

Shouldn't the class be marked as final for immutability?


Reply to this email directly or view it on GitHub:
https://github.com/dblock/waffle/pull/310/files#r49372072

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, what I meant is that inheritance should be forbidden in general on a class that implements equals. One potential problem though is that it can break backwards compatibility for people who mock this class, but I can argue that data types should be stubbed rather than mocked.

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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,31 @@ public void testToString() {
this.result = WindowsPrincipalTest.TEST_FQN;
WindowsPrincipalTest.this.windowsIdentity.getGroups();
this.result = new IWindowsAccount[0];

}
});
final WindowsPrincipal principal = new WindowsPrincipal(this.windowsIdentity);
Assert.assertEquals(WindowsPrincipalTest.TEST_FQN, principal.getName());
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());
}

}