Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public class InetOrgPerson extends Person {

private @Nullable String uid;

public String getUid() {
return Objects.requireNonNull(this.uid, "uid cannot be null");
public @Nullable String getUid() {
return this.uid;
}

public @Nullable String getMail() {
Expand Down Expand Up @@ -222,8 +222,9 @@ public Essence(DirContextOperations ctx) {
setStreet(ctx.getStringAttribute("street"));
setTitle(ctx.getStringAttribute("title"));
String uid = ctx.getStringAttribute("uid");
Assert.notNull(uid, "uid cannot be null");
setUid(uid);
if (uid != null) {
setUid(uid);
}
Comment on lines 224 to +227

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
String uid = ctx.getStringAttribute("uid");
Assert.notNull(uid, "uid cannot be null");
setUid(uid);
if (uid != null) {
setUid(uid);
}
setUid(ctx.getStringAttribute("uid"));

I would just restore the original code, also to be consistent with the other attributes:

}

@Override
Expand All @@ -236,11 +237,10 @@ public void setMail(@Nullable String email) {
((InetOrgPerson) this.instance).mail = email;
}

public void setUid(String uid) {
public void setUid(@Nullable String uid) {
Assert.notNull(this.instance, "Essence can only be used to create a single instance");
((InetOrgPerson) this.instance).uid = uid;

if (this.username == null) {
if (this.username == null && uid != null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (this.username == null && uid != null) {
if (this.instance.getUsername() == null) {

Directly check the instance.getUsername(). The check for uid != null is not necessary.

setUsername(uid);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public void attributesMapCorrectlyFromContext() {
assertThat(p.getDisplayName()).isEqualTo("Ghengis McCann");
assertThat(p.getInitials()).isEqualTo("G");
}
@Test
public void testNullUidIsAllowed() {
DirContextAdapter ctx = createUserContext();
ctx.setAttributeValue("uid", null);
InetOrgPerson.Essence essence = new InetOrgPerson.Essence(ctx);
InetOrgPerson p = (InetOrgPerson) essence.createUserDetails();
assertThat(p.getUid()).isNull();
}

@Test
public void testPasswordIsSetFromContextUserPassword() {
Expand Down