Skip to content

Commit

Permalink
Add equals and hashCode to WindowsPrincipal
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-m committed Jan 7, 2016
1 parent 35e90a0 commit 7eee2f0
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 57 deletions.
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

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

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Waffle (https://github.com/dblock/waffle)
*
* Copyright (c) 2010 - 2015 Application Security, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Application Security, Inc.
*/
package waffle.servlet;

import org.junit.Assert;
import org.junit.Test;

import mockit.Expectations;
import mockit.Mocked;
import waffle.windows.auth.IWindowsAccount;
import waffle.windows.auth.IWindowsIdentity;

/**
* The Class WindowsPrincipalTest.
*
* @author dblock[at]dblock[dot]org
*/
public class WindowsPrincipalTests {

/** The Constant TEST_FQN. */
private static final String TEST_FQN = "ACME\\john.smith";

/** The windows identity. */
@Mocked
IWindowsIdentity windowsIdentity;

/**
* Test to string.
*/
@Test
public void testToString() {
Assert.assertNotNull(new Expectations() {
{
WindowsPrincipalTests.this.windowsIdentity.getFqn();
this.result = WindowsPrincipalTests.TEST_FQN;
WindowsPrincipalTests.this.windowsIdentity.getGroups();
this.result = new IWindowsAccount[0];
}
});
final WindowsPrincipal principal = new WindowsPrincipal(this.windowsIdentity);
Assert.assertEquals(WindowsPrincipalTests.TEST_FQN, principal.getName());
Assert.assertEquals(WindowsPrincipalTests.TEST_FQN, principal.toString());
}

/**
* Test equals and hash code.
*/
@Test
public void testEqualsAndHashCode() {
Assert.assertNotNull(new Expectations() {
{
WindowsPrincipalTests.this.windowsIdentity.getFqn();
this.result = WindowsPrincipalTests.TEST_FQN;
WindowsPrincipalTests.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(), WindowsPrincipalTests.TEST_FQN.hashCode());
}

}

0 comments on commit 7eee2f0

Please sign in to comment.