Skip to content
Merged
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 @@ -60,20 +60,18 @@ public void setup() {
section.put("guest", "guest, guest");
section.put("lonestarr", "vespa, goodguy");
sm.setRealm(new IniRealm(ini));
SecurityUtils.setSecurityManager(sm);
}

@AfterEach
@Override
public void tearDown() {
SecurityUtils.setSecurityManager(null);
sm.destroy();
super.tearDown();
}

@Test
void testDefaultConfig() {
Subject subject = SecurityUtils.getSubject();
Subject subject = new Subject.Builder(sm).buildSubject();

AuthenticationToken token = new UsernamePasswordToken("guest", "guest");
subject.login(token);
Expand All @@ -99,7 +97,7 @@ void testDefaultConfig() {
@SuppressWarnings("checkstyle:MagicNumber")
@Test
void testAutoCreateSessionAfterInvalidation() {
Subject subject = SecurityUtils.getSubject();
Subject subject = new Subject.Builder(sm).buildSubject();
Session session = subject.getSession();

String key = "foo";
Expand Down Expand Up @@ -128,7 +126,7 @@ void testAutoCreateSessionAfterInvalidation() {
@Test
void testSubjectReuseAfterLogout() {

Subject subject = SecurityUtils.getSubject();
Subject subject = new Subject.Builder(sm).buildSubject();

AuthenticationToken token = new UsernamePasswordToken("guest", "guest");
subject.login(token);
Expand Down Expand Up @@ -195,19 +193,18 @@ void testNewSubjectWithoutThreadSecurityManager() {
void testNewSubjectWithoutSessionCreationEnabled() {
PrincipalCollection principals = ImmutablePrincipalCollection.ofSinglePrincipal("guest", "asd");
// this tests that calling `buildSubject` doesn't throw an exception due to session-creation being disabled
Subject subject = new Subject.Builder().principals(principals).sessionCreationEnabled(false).buildSubject();
Subject subject = new Subject.Builder(sm).principals(principals).sessionCreationEnabled(false).buildSubject();

assertThat(subject.getPrincipal()).isEqualTo("guest");
}

@Test
void testNewSubjectWithSubjectFactoryThatDisablesSessionCreation() {
((DefaultSecurityManager) SecurityUtils.getSecurityManager())
.setSubjectFactory(new SessionCreationDisabledSubjectFactory());
sm.setSubjectFactory(new SessionCreationDisabledSubjectFactory());

PrincipalCollection principals = ImmutablePrincipalCollection.ofSinglePrincipal("guest", "asd");
// this tests that calling `buildSubject` doesn't throw an exception due to session-creation being disabled
Subject subject = new Subject.Builder().principals(principals).buildSubject();
Subject subject = new Subject.Builder(sm).principals(principals).buildSubject();

assertThat(subject.getPrincipal()).isEqualTo("guest");
}
Expand Down
Loading