Skip to content

Commit

Permalink
[JENKINS-72114] Fix serialization of `HudsonPrivateSecurityRealm.User…
Browse files Browse the repository at this point in the history
…DetailsImpl` (#8557)

[JENKINS-72114] Fix Serialization of HudsonPrivateSecurityRealm.UserDetailsImpl
  • Loading branch information
Vlatombe authored Oct 7, 2023
1 parent 0ca08a6 commit d1b8473
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -728,44 +728,62 @@ public boolean isEnabled() {
}

UserDetails asUserDetails() {
return new UserDetailsImpl();
}

private final class UserDetailsImpl implements UserDetails {
return new UserDetailsImpl(getAuthorities2(), getPassword(), getUsername(), isAccountNonExpired(), isAccountNonLocked(), isCredentialsNonExpired(), isEnabled());
}

private static final class UserDetailsImpl implements UserDetails {
private static final long serialVersionUID = 1L;
private final Collection<? extends GrantedAuthority> authorities;
private final String password;
private final String username;
private final boolean accountNonExpired;
private final boolean accountNonLocked;
private final boolean credentialsNonExpired;
private final boolean enabled;

UserDetailsImpl(Collection<? extends GrantedAuthority> authorities, String password, String username, boolean accountNonExpired, boolean accountNonLocked, boolean credentialsNonExpired, boolean enabled) {
this.authorities = authorities;
this.password = password;
this.username = username;
this.accountNonExpired = accountNonExpired;
this.accountNonLocked = accountNonLocked;
this.credentialsNonExpired = credentialsNonExpired;
this.enabled = enabled;
}

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return Details.this.getAuthorities2();
return authorities;
}

@Override
public String getPassword() {
return Details.this.getPassword();
return password;

Check warning on line 761 in core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 761 is not covered by tests
}

@Override
public String getUsername() {
return Details.this.getUsername();
return username;
}

@Override
public boolean isAccountNonExpired() {
return Details.this.isAccountNonExpired();
return accountNonExpired;
}

@Override
public boolean isAccountNonLocked() {
return Details.this.isAccountNonLocked();
return accountNonLocked;
}

@Override
public boolean isCredentialsNonExpired() {
return Details.this.isCredentialsNonExpired();
return credentialsNonExpired;
}

@Override
public boolean isEnabled() {
return Details.this.isEnabled();
return enabled;
}

@Override
Expand Down

0 comments on commit d1b8473

Please sign in to comment.