-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jans-auth-server): forced clientWhiteList when session is valid f…
- Loading branch information
Showing
4 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
jans-auth-server/server/src/main/java/io/jans/as/server/session/ws/rs/EndSessionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.jans.as.server.session.ws.rs; | ||
|
||
import io.jans.as.model.configuration.AppConfiguration; | ||
import io.jans.as.model.util.URLPatternList; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
@Named | ||
public class EndSessionService { | ||
|
||
@Inject | ||
private Logger log; | ||
|
||
@Inject | ||
private AppConfiguration appConfiguration; | ||
|
||
public boolean isUrlWhiteListed(String url) { | ||
final boolean result = new URLPatternList(appConfiguration.getClientWhiteList()).isUrlListed(url); | ||
log.trace("White listed result: {}, url: {}", result, url); | ||
return result; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...th-server/server/src/test/java/io/jans/as/server/session/ws/rs/EndSessionServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.jans.as.server.session.ws.rs; | ||
|
||
import com.google.common.collect.Lists; | ||
import io.jans.as.model.configuration.AppConfiguration; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.testng.MockitoTestNGListener; | ||
import org.slf4j.Logger; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
@Listeners(MockitoTestNGListener.class) | ||
public class EndSessionServiceTest { | ||
|
||
@InjectMocks | ||
private EndSessionService endSessionService; | ||
|
||
@Mock | ||
private Logger log; | ||
|
||
@Mock | ||
private AppConfiguration appConfiguration; | ||
|
||
@Test | ||
public void isUrlWhiteListed_whenClientWhiteListAllows_shouldReturnTrue() { | ||
when(appConfiguration.getClientWhiteList()).thenReturn(Lists.newArrayList("white.com")); | ||
|
||
assertTrue(endSessionService.isUrlWhiteListed("https://white.com/path")); | ||
assertTrue(endSessionService.isUrlWhiteListed("https://white.com/path?param=value")); | ||
assertTrue(endSessionService.isUrlWhiteListed("http://white.com/path?param=value")); | ||
} | ||
|
||
@Test | ||
public void isUrlWhiteListed_whenClientWhiteListDoesNotAllow_shouldReturnFalse() { | ||
when(appConfiguration.getClientWhiteList()).thenReturn(Lists.newArrayList("some.com")); | ||
|
||
assertFalse(endSessionService.isUrlWhiteListed("https://white.com/path")); | ||
assertFalse(endSessionService.isUrlWhiteListed("https://white.com/path?param=value")); | ||
assertFalse(endSessionService.isUrlWhiteListed("http://white.com/path?param=value")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters