Skip to content
Snippets Groups Projects
Commit 06d67ed4 authored by Adrian Damian's avatar Adrian Damian
Browse files

Added the core authorization classes - code review changes

parent d6c8a952
No related branches found
No related tags found
No related merge requests found
projects/cadcUtil/doc/uml/UserAuth.png

16 KiB | W: | H:

projects/cadcUtil/doc/uml/UserAuth.png

16.8 KiB | W: | H:

projects/cadcUtil/doc/uml/UserAuth.png
projects/cadcUtil/doc/uml/UserAuth.png
projects/cadcUtil/doc/uml/UserAuth.png
projects/cadcUtil/doc/uml/UserAuth.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -76,7 +76,8 @@ public class Group ...@@ -76,7 +76,8 @@ public class Group
* Ctor. * Ctor.
* *
* @param groupID * @param groupID
* Unique ID for the group * Unique ID for the group. Must be a valid URI fragment component,
* so it's restricted to alphanumeric and "-", ".","_","~" characters.
* @param owner * @param owner
* Owner/Creator of the group. * Owner/Creator of the group.
*/ */
...@@ -87,6 +88,12 @@ public class Group ...@@ -87,6 +88,12 @@ public class Group
{ {
throw new IllegalArgumentException("Null groupID"); throw new IllegalArgumentException("Null groupID");
} }
// check for invalid path characters in groupID
if(!groupID.matches("^[a-zA-Z0-9\\-\\.~_]*$"))
throw new IllegalArgumentException("Invalid group ID " + groupID
+ ": may not contain space ( ), slash (/), escape (\\), or percent (%)");
this.groupID = groupID; this.groupID = groupID;
if(owner == null) if(owner == null)
{ {
......
...@@ -140,9 +140,6 @@ public class GroupProperty ...@@ -140,9 +140,6 @@ public class GroupProperty
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode()); result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + (readOnly ? 1231 : 1237);
result = prime * result
+ ((value == null) ? 0 : value.hashCode());
return result; return result;
} }
...@@ -165,26 +162,7 @@ public class GroupProperty ...@@ -165,26 +162,7 @@ public class GroupProperty
return false; return false;
} }
GroupProperty other = (GroupProperty) obj; GroupProperty other = (GroupProperty) obj;
if (key == null) return key.equals(other.key);
{
if (other.key != null)
{
return false;
}
}
else if (!key.equals(other.key))
{
return false;
}
if (readOnly != other.readOnly)
{
return false;
}
if (!value.equals(other.value))
{
return false;
}
return true;
} }
@Override @Override
......
...@@ -37,7 +37,7 @@ package ca.nrc.cadc.auth.model; ...@@ -37,7 +37,7 @@ package ca.nrc.cadc.auth.model;
/** /**
* Represents the posix account details associated with a user account. * Represents the posix account details associated with a user account.
*/ */
public class PosixDetails public class PosixDetails implements UserDetails
{ {
private long uid; private long uid;
private long gid; private long gid;
......
...@@ -46,8 +46,7 @@ public class User<T extends Principal> ...@@ -46,8 +46,7 @@ public class User<T extends Principal>
private Set<Principal> principals = new HashSet<Principal>(); private Set<Principal> principals = new HashSet<Principal>();
public UserDetails userDetails; public Set<UserDetails> details = new HashSet<UserDetails>();
public PosixDetails posixDetails;
public User(final T userID) public User(final T userID)
...@@ -79,8 +78,7 @@ public class User<T extends Principal> ...@@ -79,8 +78,7 @@ public class User<T extends Principal>
{ {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result result = prime * result + userID.hashCode();
+ ((userID == null) ? 0 : userID.hashCode());
return result; return result;
} }
......
...@@ -34,169 +34,23 @@ ...@@ -34,169 +34,23 @@
package ca.nrc.cadc.auth.model; package ca.nrc.cadc.auth.model;
public class UserDetails public interface UserDetails
{ {
private String firstName;
private String lastName;
private String email;
private String address;
private String institute;
private String city;
private String country;
public UserDetails(String firstName, String lastName, String email,
String address, String institute, String city, String country)
{
if (firstName == null)
{
throw new IllegalArgumentException("null firstName");
}
if (lastName == null)
{
throw new IllegalArgumentException("null lastName");
}
if (email == null)
{
throw new IllegalArgumentException("null email");
}
if (address == null)
{
throw new IllegalArgumentException("null address");
}
if (institute == null)
{
throw new IllegalArgumentException("null institute");
}
if (city == null)
{
throw new IllegalArgumentException("null city");
}
if (country == null)
{
throw new IllegalArgumentException("null country");
}
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.address = address;
this.institute = institute;
this.city = city;
this.country = country;
}
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public String getEmail()
{
return email;
}
public String getAddress()
{
return address;
}
public String getInstitute()
{
return institute;
}
public String getCity()
{
return city;
}
public String getCountry()
{
return country;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see java.lang.Object#hashCode() * @see java.lang.Object#hashCode()
*/ */
@Override public int hashCode();
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + address.hashCode();
result = prime * result + city.hashCode();
result = prime * result + country.hashCode();
result = prime * result + email.hashCode();
result = prime * result + firstName.hashCode();
result = prime * result + institute.hashCode();
result = prime * result + lastName.hashCode();
return result;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#equals(java.lang.Object)
*/ */
@Override public boolean equals(Object obj);
public boolean equals(Object obj)
{ public String toString();
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (!(obj instanceof UserDetails))
{
return false;
}
UserDetails other = (UserDetails) obj;
if (!firstName.equals(other.firstName))
{
return false;
}
if (!lastName.equals(other.lastName))
{
return false;
}
if (!email.equals(other.email))
{
return false;
}
if (!institute.equals(other.institute))
{
return false;
}
if (!address.equals(other.address))
{
return false;
}
if (!city.equals(other.city))
{
return false;
}
if (!country.equals(other.country))
{
return false;
}
return true;
}
@Override }
public String toString() \ No newline at end of file
{
return getClass().getSimpleName() + "[" + firstName + ", "
+ lastName + ", " + email + ", " + address + ", "
+ institute + ", " + city + ", " + country + "]";
}
}
...@@ -92,7 +92,7 @@ public class GroupTest ...@@ -92,7 +92,7 @@ public class GroupTest
assertEquals(group1.hashCode(), group2.hashCode()); assertEquals(group1.hashCode(), group2.hashCode());
assertEquals(group1,group2); assertEquals(group1,group2);
group2 = new Group("NewTestGroup", owner); group2 = new Group("NewTestGroup-._~.", owner);
assertFalse(group1.hashCode() == group2.hashCode()); assertFalse(group1.hashCode() == group2.hashCode());
assertFalse(group1.equals(group2)); assertFalse(group1.equals(group2));
...@@ -125,5 +125,39 @@ public class GroupTest ...@@ -125,5 +125,39 @@ public class GroupTest
thrown = true; thrown = true;
} }
assertTrue(thrown); assertTrue(thrown);
// invavlid group IDs
thrown = false;
try
{
new Group("New/Test/Group", new User<HttpPrincipal>(new HttpPrincipal("owner")));
}
catch(IllegalArgumentException e)
{
thrown = true;
}
assertTrue(thrown);
thrown = false;
try
{
new Group("New%Test%Group", new User<HttpPrincipal>(new HttpPrincipal("owner")));
}
catch(IllegalArgumentException e)
{
thrown = true;
}
assertTrue(thrown);
thrown = false;
try
{
new Group("New\\Test\\Group", new User<HttpPrincipal>(new HttpPrincipal("owner")));
}
catch(IllegalArgumentException e)
{
thrown = true;
}
assertTrue(thrown);
} }
} }
...@@ -65,8 +65,8 @@ public class UserTest ...@@ -65,8 +65,8 @@ public class UserTest
assertEquals(user1, user2); assertEquals(user1, user2);
assertEquals(user1.hashCode(), user2.hashCode()); assertEquals(user1.hashCode(), user2.hashCode());
user1.userDetails = new UserDetails("Joe", "Raymond", user1.details.add(new PersonalDetails("Joe", "Raymond",
"jr@email.com", "123 Street", "CADC", "Victoria", "CA"); "jr@email.com", "123 Street", "CADC", "Victoria", "CA"));
assertEquals(user1, user2); assertEquals(user1, user2);
assertEquals(user1.hashCode(), user2.hashCode()); assertEquals(user1.hashCode(), user2.hashCode());
...@@ -82,8 +82,8 @@ public class UserTest ...@@ -82,8 +82,8 @@ public class UserTest
assertEquals(user1, user2); assertEquals(user1, user2);
assertEquals(user1.hashCode(), user2.hashCode()); assertEquals(user1.hashCode(), user2.hashCode());
user1.posixDetails = new PosixDetails(12, 23, user1.details.add(new PosixDetails(12, 23,
"/home/myhome"); "/home/myhome"));
assertEquals(user1, user2); assertEquals(user1, user2);
assertEquals(user1.hashCode(), user2.hashCode()); assertEquals(user1.hashCode(), user2.hashCode());
...@@ -93,8 +93,9 @@ public class UserTest ...@@ -93,8 +93,9 @@ public class UserTest
// visual test of toString // visual test of toString
System.out.println(user1); System.out.println(user1);
System.out.println(user1.userDetails); System.out.println(new PersonalDetails("Joe", "Raymond",
System.out.println(user1.posixDetails); "jr@email.com", "123 Street", "CADC", "Victoria", "CA"));
System.out.println(new PosixDetails(12, 23,"/home/myhome"));
} }
...@@ -115,7 +116,7 @@ public class UserTest ...@@ -115,7 +116,7 @@ public class UserTest
thrown = false; thrown = false;
try try
{ {
new UserDetails(null, "Raymond", new PersonalDetails(null, "Raymond",
"jr@email.com", "123 Street", "CADC", "Victoria", "CA"); "jr@email.com", "123 Street", "CADC", "Victoria", "CA");
} }
catch(IllegalArgumentException e) catch(IllegalArgumentException e)
...@@ -127,7 +128,7 @@ public class UserTest ...@@ -127,7 +128,7 @@ public class UserTest
thrown = false; thrown = false;
try try
{ {
new UserDetails("Joe", null, new PersonalDetails("Joe", null,
"jr@email.com", "123 Street", "CADC", "Victoria", "CA"); "jr@email.com", "123 Street", "CADC", "Victoria", "CA");
} }
catch(IllegalArgumentException e) catch(IllegalArgumentException e)
...@@ -139,7 +140,7 @@ public class UserTest ...@@ -139,7 +140,7 @@ public class UserTest
thrown = false; thrown = false;
try try
{ {
new UserDetails("Joe", "Raymond", new PersonalDetails("Joe", "Raymond",
null, "123 Street", "CADC", "Victoria", "CA"); null, "123 Street", "CADC", "Victoria", "CA");
} }
catch(IllegalArgumentException e) catch(IllegalArgumentException e)
...@@ -151,7 +152,7 @@ public class UserTest ...@@ -151,7 +152,7 @@ public class UserTest
thrown = false; thrown = false;
try try
{ {
new UserDetails("Joe", "Raymond", new PersonalDetails("Joe", "Raymond",
"jr@email.com", null, "CADC", "Victoria", "CA"); "jr@email.com", null, "CADC", "Victoria", "CA");
} }
catch(IllegalArgumentException e) catch(IllegalArgumentException e)
...@@ -163,7 +164,7 @@ public class UserTest ...@@ -163,7 +164,7 @@ public class UserTest
thrown = false; thrown = false;
try try
{ {
new UserDetails("Joe", "Raymond", new PersonalDetails("Joe", "Raymond",
"jr@email.com", "123 Street", null, "Victoria", "CA"); "jr@email.com", "123 Street", null, "Victoria", "CA");
} }
catch(IllegalArgumentException e) catch(IllegalArgumentException e)
...@@ -175,7 +176,7 @@ public class UserTest ...@@ -175,7 +176,7 @@ public class UserTest
thrown = false; thrown = false;
try try
{ {
new UserDetails("Joe", "Raymond", new PersonalDetails("Joe", "Raymond",
"jr@email.com", "123 Street", "CADC", null, "CA"); "jr@email.com", "123 Street", "CADC", null, "CA");
} }
catch(IllegalArgumentException e) catch(IllegalArgumentException e)
...@@ -187,7 +188,7 @@ public class UserTest ...@@ -187,7 +188,7 @@ public class UserTest
thrown = false; thrown = false;
try try
{ {
new UserDetails("Joe", "Raymond", new PersonalDetails("Joe", "Raymond",
"jr@email.com", "123 Street", "CADC", "Victoria", null); "jr@email.com", "123 Street", "CADC", "Victoria", null);
} }
catch(IllegalArgumentException e) catch(IllegalArgumentException e)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment