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

feat(jans-auth-server): implemented auth server config property to disable prompt=login #3006 #3522

Merged
merged 1 commit into from
Jan 5, 2023
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
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