Skip to content

Commit

Permalink
feat(jans-auth-server): implemented auth server config property to di…
Browse files Browse the repository at this point in the history
…sable prompt=login #3006 (#3522)
  • Loading branch information
yuriyz authored Jan 5, 2023
1 parent 069dceb commit 0233cd1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ public class AppConfiguration implements Configuration {
@DocProperty(description = "Boolean value specifying whether to include sessionId in response", defaultValue = "false")
private Boolean includeSidInResponse = false;

@DocProperty(description = "Boolean value specifying whether to disable prompt=login", defaultValue = "false")
private Boolean disablePromptLogin = false;


/**
* SessionId will be expired after sessionIdLifetime seconds
Expand Down Expand Up @@ -1109,6 +1112,15 @@ public void setForceOfflineAccessScopeToEnableRefreshToken(Boolean forceOfflineA
this.forceOfflineAccessScopeToEnableRefreshToken = forceOfflineAccessScopeToEnableRefreshToken;
}

public Boolean getDisablePromptLogin() {
if (disablePromptLogin == null) disablePromptLogin = false;
return disablePromptLogin;
}

public void setDisablePromptLogin(Boolean disablePromptLogin) {
this.disablePromptLogin = disablePromptLogin;
}

public Boolean getIncludeSidInResponse() {
if (includeSidInResponse == null) includeSidInResponse = false;
return includeSidInResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,12 @@ private void checkPromptConsent(AuthzRequest authzRequest, List<Prompt> prompts,
}
}

private void checkPromptLogin(AuthzRequest authzRequest, List<Prompt> prompts) {
public void checkPromptLogin(AuthzRequest authzRequest, List<Prompt> prompts) {
if (isTrue(appConfiguration.getDisablePromptLogin())) {
log.trace("Disabled prompt=login (because disablePromptLogin=true).");
prompts.remove(Prompt.LOGIN);
return;
}
if (prompts.contains(Prompt.LOGIN)) {
boolean sessionUnauthenticated = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.jans.as.common.model.registration.Client;
import io.jans.as.common.model.session.SessionId;
import io.jans.as.model.common.Prompt;
import io.jans.as.model.common.ResponseType;
import io.jans.as.model.common.ScopeConstants;
import io.jans.as.model.configuration.AppConfiguration;
Expand All @@ -25,10 +27,12 @@
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.mockito.Mockito.when;
import static org.testng.Assert.*;

/**
* @author Yuriy Z
Expand Down Expand Up @@ -111,6 +115,35 @@ public class AuthorizeRestWebServiceImplTest {
@Mock
private AuthzRequestService authzRequestService;

@Test
public void checkPromptLogin_whenDisablePromptLoginIsTrue_shouldNotClearSession() {
AuthzRequest authzRequest = new AuthzRequest();
authzRequest.setSessionId("some_id");

List<Prompt> promptList = new ArrayList<>();
promptList.add(Prompt.LOGIN);

when(appConfiguration.getDisablePromptLogin()).thenReturn(true);

authorizeRestWebService.checkPromptLogin(authzRequest, promptList);
assertEquals(authzRequest.getSessionId(), "some_id");
}

@Test
public void checkPromptLogin_whenDisablePromptLoginIsFalse_shouldClearSession() {
AuthzRequest authzRequest = new AuthzRequest();
authzRequest.setSessionId("some_id");

List<Prompt> promptList = new ArrayList<>();
promptList.add(Prompt.LOGIN);

when(identity.getSessionId()).thenReturn(new SessionId());
when(appConfiguration.getDisablePromptLogin()).thenReturn(false);

authorizeRestWebService.checkPromptLogin(authzRequest, promptList);
assertNull(authzRequest.getSessionId());
}

@Test
public void checkOfflineAccessScopes_whenOfflineAccessIsPresentAndConsentNot_shouldRemoveOfflineAccess() {
final Set<String> scopes = Sets.newHashSet(ScopeConstants.OFFLINE_ACCESS);
Expand Down

0 comments on commit 0233cd1

Please sign in to comment.