Skip to content

Commit

Permalink
api fixes after the upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoayyed committed Feb 2, 2021
1 parent 972bea4 commit f024ac9
Show file tree
Hide file tree
Showing 146 changed files with 706 additions and 615 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ targetCompatibility=11
###############################
# Compiler/Utils versions
###############################
lombokVersion=1.18.18
lombokVersion=1.18.16
aspectjVersion=1.9.6
errorProneVersion=2.5.1
errorproneJavacVersion=9+181-r4173-1
Expand Down Expand Up @@ -304,8 +304,8 @@ commonsCollectionsVersion=4.4
###############################
# Pac4j versions
###############################
pac4jSpringWebmvcVersion=4.0.1
pac4jVersion=4.3.1
pac4jSpringWebmvcVersion=5.0.0-RC1
pac4jVersion=5.0.0-RC1

###############################
# ACME versions
Expand Down
2 changes: 1 addition & 1 deletion lombok.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lombok.log.fieldName=LOGGER
lombok.log.fieldName = LOGGER
lombok.log.fieldIsStatic=true

lombok.toString.doNotUseGetters=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.jose4j.keys.RsaKeyUtil;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.session.SessionStore;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.ObjectProvider;
Expand Down Expand Up @@ -183,7 +182,7 @@ public CasWebflowExecutionPlanConfigurer mfaAccepttoCasWebflowExecutionPlanConfi

@ConditionalOnMissingBean(name = "mfaAccepttoDistributedSessionStore")
@Bean
public SessionStore<JEEContext> mfaAccepttoDistributedSessionStore() {
public SessionStore mfaAccepttoDistributedSessionStore() {
val cookie = casProperties.getSessionReplication().getCookie();
val cookieGenerator = CookieUtils.buildCookieRetrievingGenerator(cookie);
return new DistributedJEESessionStore(centralAuthenticationService.getObject(), ticketFactory.getObject(), cookieGenerator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
@RequiredArgsConstructor
public class AccepttoMultifactorFetchChannelAction extends AbstractAction {
private final CasConfigurationProperties casProperties;
private final SessionStore<JEEContext> sessionStore;
private final SessionStore sessionStore;
private final PublicKey apiPublicKey;

@Override
public Event doExecute(final RequestContext requestContext) throws Exception {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val webContext = new JEEContext(request, response, this.sessionStore);
val webContext = new JEEContext(request, response);

val channel = authenticateAndFetchChannel(requestContext);
LOGGER.debug("Storing channel [{}] in session", channel);
AccepttoWebflowUtils.storeChannelInSessionStore(channel, webContext);
AccepttoWebflowUtils.storeChannelInSessionStore(channel, webContext, sessionStore);

val authentication = WebUtils.getInProgressAuthentication();
AccepttoWebflowUtils.storeAuthenticationInSessionStore(authentication, webContext);
AccepttoWebflowUtils.storeAuthenticationInSessionStore(authentication, webContext, sessionStore);

val accepttoRedirectUrl = buildAccepttoAuthenticationSelectionUrl(request, channel);
LOGGER.debug("Redirecting to [{}]", accepttoRedirectUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@Slf4j
@RequiredArgsConstructor
public class AccepttoMultifactorValidateChannelAction extends AbstractAction {
private final SessionStore<JEEContext> sessionStore;
private final SessionStore sessionStore;
private final AuthenticationSystemSupport authenticationSystemSupport;

@Override
Expand All @@ -36,14 +36,14 @@ protected Event doExecute(final RequestContext requestContext) {
try {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val webContext = new JEEContext(request, response, this.sessionStore);
val webContext = new JEEContext(request, response);

val channel = AccepttoWebflowUtils.getChannel(webContext);
val channel = AccepttoWebflowUtils.getChannel(webContext, sessionStore);
if (channel == null) {
LOGGER.debug("Unable to determine channel from session store; not a validation attempt");
return null;
}
val authentication = AccepttoWebflowUtils.getAuthentication(webContext);
val authentication = AccepttoWebflowUtils.getAuthentication(webContext, sessionStore);
if (authentication == null) {
LOGGER.debug("Unable to determine the original authentication attempt the session store");
throw new AuthenticationException("Unable to determine authentication from session store");
Expand All @@ -54,7 +54,7 @@ protected Event doExecute(final RequestContext requestContext) {
val service = WebUtils.getService(requestContext);

LOGGER.debug("Cleaning up session store to remove [{}]", credential);
AccepttoWebflowUtils.resetChannelAndAuthentication(webContext);
AccepttoWebflowUtils.resetChannelAndAuthentication(webContext, sessionStore);
AccepttoWebflowUtils.setChannel(requestContext, null);

LOGGER.debug("Attempting to authenticate channel [{}] with authentication [{}] and service [{}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.session.SessionStore;
import org.springframework.webflow.execution.RequestContext;

import java.util.Optional;
Expand All @@ -31,22 +32,23 @@ public class AccepttoWebflowUtils {
/**
* Reset acceptto session store.
*
* @param webContext the web context
* @param webContext the web context
* @param sessionStore the session store
*/
public void resetChannelAndAuthentication(final JEEContext webContext) {
val sessionStore = webContext.getSessionStore();
public void resetChannelAndAuthentication(final JEEContext webContext, final SessionStore sessionStore) {
sessionStore.set(webContext, SESSION_ATTRIBUTE_CHANNEL, null);
sessionStore.set(webContext, SESSION_ATTRIBUTE_ORIGINAL_AUTHENTICATION, null);
}

/**
* Gets channel.
*
* @param webContext the web context
* @param webContext the web context
* @param sessionStore the session store
* @return the channel
*/
public static Object getChannel(final JEEContext webContext) {
return webContext.getSessionStore().get(webContext, SESSION_ATTRIBUTE_CHANNEL);
public static Object getChannel(final JEEContext webContext, final SessionStore sessionStore) {
return sessionStore.get(webContext, SESSION_ATTRIBUTE_CHANNEL);
}

/**
Expand All @@ -62,32 +64,37 @@ public static Optional<String> getChannel(final RequestContext requestContext) {
/**
* Gets authentication from session store.
*
* @param webContext the web context
* @param webContext the web context
* @param sessionStore the session store
* @return the authentication from session store
*/
public static Authentication getAuthentication(final JEEContext webContext) {
val result = webContext.getSessionStore().get(webContext, SESSION_ATTRIBUTE_ORIGINAL_AUTHENTICATION);
return (Authentication) result.map(Authentication.class::cast).orElse(null);
public static Authentication getAuthentication(final JEEContext webContext, final SessionStore sessionStore) {
val result = sessionStore.get(webContext, SESSION_ATTRIBUTE_ORIGINAL_AUTHENTICATION);
return result.map(Authentication.class::cast).orElse(null);
}

/**
* Store channel.
*
* @param channel the channel
* @param webContext the web context
* @param channel the channel
* @param webContext the web context
* @param sessionStore the session store
*/
public static void storeChannelInSessionStore(final String channel, final JEEContext webContext) {
webContext.getSessionStore().set(webContext, SESSION_ATTRIBUTE_CHANNEL, channel);
public static void storeChannelInSessionStore(final String channel,
final JEEContext webContext, final SessionStore sessionStore) {
sessionStore.set(webContext, SESSION_ATTRIBUTE_CHANNEL, channel);
}

/**
* Store authentication.
*
* @param authentication the authentication
* @param webContext the web context
* @param sessionStore the session store
*/
public static void storeAuthenticationInSessionStore(final Authentication authentication, final JEEContext webContext) {
webContext.getSessionStore().set(webContext, SESSION_ATTRIBUTE_ORIGINAL_AUTHENTICATION, authentication);
public static void storeAuthenticationInSessionStore(final Authentication authentication,
final JEEContext webContext, final SessionStore sessionStore) {
sessionStore.set(webContext, SESSION_ATTRIBUTE_ORIGINAL_AUTHENTICATION, authentication);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public class AccepttoQRCodeValidateWebSocketChannelAction extends AbstractAction

private final CasConfigurationProperties casProperties;

private final SessionStore<JEEContext> sessionStore;
private final SessionStore sessionStore;

@Override
protected Event doExecute(final RequestContext requestContext) {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val webContext = new JEEContext(request, response, this.sessionStore);
val webContext = new JEEContext(request, response);

val channel = request.getParameter("channel");
if (channel == null) {
Expand Down Expand Up @@ -93,7 +93,7 @@ protected Event doExecute(final RequestContext requestContext) {
if (success) {
val email = results.get("user_email").toString();
LOGGER.trace("Storing channel [{}] in http session", channel);
AccepttoWebflowUtils.storeChannelInSessionStore(channel, webContext);
AccepttoWebflowUtils.storeChannelInSessionStore(channel, webContext, sessionStore);
WebUtils.putCredential(requestContext, new AccepttoEmailCredential(email));
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_FINALIZE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.apereo.inspektr.common.web.ClientInfoHolder;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.session.SessionStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -65,7 +64,7 @@ public class AccepttoMultifactorFetchChannelActionTests {

@Autowired
@Qualifier("mfaAccepttoDistributedSessionStore")
private SessionStore<JEEContext> mfaAccepttoDistributedSessionStore;
private SessionStore mfaAccepttoDistributedSessionStore;

@Autowired
@Qualifier("mfaAccepttoApiPublicKey")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class AccepttoMultifactorValidateChannelActionTests {

@Autowired
@Qualifier("mfaAccepttoDistributedSessionStore")
private SessionStore<JEEContext> mfaAccepttoDistributedSessionStore;
private SessionStore mfaAccepttoDistributedSessionStore;

@Test
public void verifyOperation() throws Exception {
Expand All @@ -77,12 +77,12 @@ public void verifyOperation() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val webContext = new JEEContext(request, response, mfaAccepttoDistributedSessionStore);
val webContext = new JEEContext(request, response);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val authn = CoreAuthenticationTestUtils.getAuthentication("casuser");
WebUtils.putAuthentication(authn, context);
AccepttoWebflowUtils.storeChannelInSessionStore("test-channel", webContext);
AccepttoWebflowUtils.storeAuthenticationInSessionStore(authn, webContext);
AccepttoWebflowUtils.storeChannelInSessionStore("test-channel", webContext, mfaAccepttoDistributedSessionStore);
AccepttoWebflowUtils.storeAuthenticationInSessionStore(authn, webContext, mfaAccepttoDistributedSessionStore);
RequestContextHolder.setRequestContext(context);
val result = action.doExecute(context);
assertEquals(CasWebflowConstants.TRANSITION_ID_FINALIZE, result.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.apereo.inspektr.common.web.ClientInfoHolder;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.session.SessionStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -61,7 +60,7 @@ public class AccepttoQRCodeValidateWebSocketChannelActionTests {

@Autowired
@Qualifier("mfaAccepttoDistributedSessionStore")
private SessionStore<JEEContext> mfaAccepttoDistributedSessionStore;
private SessionStore mfaAccepttoDistributedSessionStore;

@Test
public void verifyOperation() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
@RequiredArgsConstructor
public class SessionStoreTicketGrantingTicketAction extends AbstractAction {
private final SessionStore<JEEContext> sessionStore;
private final SessionStore sessionStore;

@Override
protected Event doExecute(final RequestContext requestContext) {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val ticketGrantingTicketId = WebUtils.getTicketGrantingTicketId(requestContext);
val webContext = new JEEContext(request, response, sessionStore);
val webContext = new JEEContext(request, response);
sessionStore.set(webContext, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, ticketGrantingTicketId);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ protected static boolean isLogoutRequestConfirmed(final RequestContext requestCo
@SuppressWarnings("java:S2441")
protected static void destroyApplicationSession(final HttpServletRequest request, final HttpServletResponse response) {
LOGGER.trace("Destroying application session");
val context = new JEEContext(request, response, new JEESessionStore());
val manager = new ProfileManager<>(context);
manager.logout();
val context = new JEEContext(request, response);
val manager = new ProfileManager(context, JEESessionStore.INSTANCE);
manager.removeProfiles();

val session = request.getSession(false);
if (session != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ public void verifyOperation() throws Exception {
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
WebUtils.putTicketGrantingTicketInScopes(context, new MockTicketGrantingTicket("casuser"));
val sessionStore = new JEESessionStore();
val action = new SessionStoreTicketGrantingTicketAction(sessionStore);
val action = new SessionStoreTicketGrantingTicketAction(JEESessionStore.INSTANCE);
val result = action.execute(context);
assertNull(result);
val webContext = new JEEContext(request, response, sessionStore);
assertTrue(sessionStore.get(webContext, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID).isPresent());
val webContext = new JEEContext(request, response);
assertTrue(JEESessionStore.INSTANCE.get(webContext, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID).isPresent());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import lombok.val;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.session.JEESessionStore;
import org.pac4j.core.credentials.UsernamePasswordCredentials;
import org.pac4j.core.credentials.extractor.BasicAuthExtractor;
import org.springframework.webflow.execution.RequestContext;

Expand All @@ -37,10 +38,10 @@ protected Credential constructCredentialsFromRequest(final RequestContext reques
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val extractor = new BasicAuthExtractor();
val webContext = new JEEContext(request, response, new JEESessionStore());
val credentialsResult = extractor.extract(webContext);
val webContext = new JEEContext(request, response);
val credentialsResult = extractor.extract(webContext, JEESessionStore.INSTANCE);
if (credentialsResult.isPresent()) {
val credentials = credentialsResult.get();
val credentials = (UsernamePasswordCredentials) credentialsResult.get();
LOGGER.debug("Received basic authentication request from credentials [{}]", credentials);
return new UsernamePasswordCredential(credentials.getUsername(), credentials.getPassword());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import org.apereo.cas.integration.pac4j.authentication.handler.support.UsernamePasswordWrapperAuthenticationHandler;
import org.apereo.cas.services.ServicesManager;

import org.pac4j.core.context.session.JEESessionStore;

/**
* This is {@link CouchDbAuthenticationHandler}.
*
* @author Timur Duehr
* @since 6.0.0
*/
public class CouchDbAuthenticationHandler extends UsernamePasswordWrapperAuthenticationHandler {
public CouchDbAuthenticationHandler(final String name, final ServicesManager servicesManager, final PrincipalFactory principalFactory, final int order) {
super(name, servicesManager, principalFactory, order);
public CouchDbAuthenticationHandler(final String name, final ServicesManager servicesManager,
final PrincipalFactory principalFactory, final int order) {
super(name, servicesManager, principalFactory, order, JEESessionStore.INSTANCE);
}
}
Loading

0 comments on commit f024ac9

Please sign in to comment.