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

[SHIRO-551] Implement toString() for DelegatingSubject.java. #220

Merged
merged 1 commit into from
Jul 5, 2020
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
[SHIRO-551] Implement toString() for DelegatingSubject.java.
  • Loading branch information
bmarwell committed Jul 5, 2020
commit 062c8e383b8f657c0b6ff735018d85a2e74d4322
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import java.util.Collection;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;

Expand Down Expand Up @@ -515,4 +516,16 @@ private PrincipalCollection popIdentity() {

return popped;
}

@Override
public String toString() {
return new StringJoiner(", ", "DelegatingSubject{", "}")
.add("principals=" + principals)
.add("authenticated=" + authenticated)
.add("host='******")
.add("session='******'")
.add("sessionCreationEnabled=" + sessionCreationEnabled)
.add("securityManager=" + securityManager)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,25 @@ public void testRunAs() {

LifecycleUtils.destroy(sm);
}

@Test
public void testToString() {
// given
String username = "jsmith";

DefaultSecurityManager securityManager = new DefaultSecurityManager();
PrincipalCollection identity = new SimplePrincipalCollection(username, "testRealm");
final String hostname = "localhost";
final DelegatingSubject sourceSubject = new DelegatingSubject(identity, true, hostname, null, securityManager);

// when
final String subjectToString = sourceSubject.toString();

// then
final Session session = sourceSubject.getSession(true);
String sesionId = (String) session.getId();
assertFalse("toString must not leak sessionId", subjectToString.contains(sesionId));
assertFalse("toString must not leak host", subjectToString.contains(hostname));
}

}