use of io.asgardeo.java.oidc.sdk.bean.RequestContext in project asgardeo-java-oidc-sdk by asgardeo.
the class HTTPSessionBasedOIDCProcessorTest method testHandleOIDCCallback.
@Test
public void testHandleOIDCCallback() throws SSOAgentException {
SessionContext sessionContext = new SessionContext();
RequestContext requestContext = new RequestContext();
HttpSession session = mock(HttpSession.class);
mockedOIDCManagerFactory = mockStatic(DefaultOIDCManagerFactory.class);
when(DefaultOIDCManagerFactory.createOIDCManager(oidcAgentConfig)).thenReturn(defaultOIDCManager);
when(request.getSession()).thenReturn(session);
when(request.getSession(false)).thenReturn(session);
when(session.getAttribute(SSOAgentConstants.REQUEST_CONTEXT)).thenReturn(requestContext);
when(defaultOIDCManager.handleOIDCCallback(request, response, requestContext)).thenReturn(sessionContext);
HTTPSessionBasedOIDCProcessor provider = new HTTPSessionBasedOIDCProcessor(oidcAgentConfig);
provider.handleOIDCCallback(request, response);
verify(session).setAttribute(SSOAgentConstants.SESSION_CONTEXT, sessionContext);
}
use of io.asgardeo.java.oidc.sdk.bean.RequestContext in project asgardeo-java-oidc-sdk by asgardeo.
the class HTTPSessionBasedOIDCProcessorTest method testSendForLogin.
@Test
public void testSendForLogin() throws Exception {
Nonce nonce = new Nonce();
State state = new State("SampleState");
RequestContext requestContext = new RequestContext(state, nonce);
HttpSession session = mock(HttpSession.class);
mockedOIDCManagerFactory = mockStatic(DefaultOIDCManagerFactory.class);
when(DefaultOIDCManagerFactory.createOIDCManager(oidcAgentConfig)).thenReturn(defaultOIDCManager);
when(request.getSession()).thenReturn(session);
when(defaultOIDCManager.sendForLogin(request, response)).thenReturn(requestContext);
HTTPSessionBasedOIDCProcessor provider = new HTTPSessionBasedOIDCProcessor(oidcAgentConfig);
provider.sendForLogin(request, response);
verify(session).setAttribute(SSOAgentConstants.REQUEST_CONTEXT, requestContext);
}
use of io.asgardeo.java.oidc.sdk.bean.RequestContext in project asgardeo-java-oidc-sdk by asgardeo.
the class HTTPSessionBasedOIDCProcessorTest method testLogout.
@Test
public void testLogout() throws SSOAgentException {
RequestContext requestContext = new RequestContext();
SessionContext sessionContext = new SessionContext();
HttpSession session = mock(HttpSession.class);
mockedOIDCManagerFactory = mockStatic(DefaultOIDCManagerFactory.class);
when(DefaultOIDCManagerFactory.createOIDCManager(oidcAgentConfig)).thenReturn(defaultOIDCManager);
when(request.getSession()).thenReturn(session);
when(request.getSession(false)).thenReturn(session);
when(session.getAttribute(SSOAgentConstants.SESSION_CONTEXT)).thenReturn(sessionContext);
when(defaultOIDCManager.logout(sessionContext, response)).thenReturn(requestContext);
HTTPSessionBasedOIDCProcessor provider = new HTTPSessionBasedOIDCProcessor(oidcAgentConfig);
provider.logout(request, response);
verify(session).setAttribute(SSOAgentConstants.REQUEST_CONTEXT, requestContext);
}
use of io.asgardeo.java.oidc.sdk.bean.RequestContext in project asgardeo-java-oidc-sdk by asgardeo.
the class HTTPSessionBasedOIDCProcessor method sendForLogin.
/**
* Builds an authentication request and redirects. Information
* regarding the authentication session would be retrieved via
* {@link RequestContext} object and then, would be written to
* the http session.
*
* @param request Incoming {@link HttpServletRequest}.
* @param response Outgoing {@link HttpServletResponse}.
* @throws SSOAgentException
*/
public void sendForLogin(HttpServletRequest request, HttpServletResponse response) throws SSOAgentException {
HttpSession session = request.getSession();
RequestContext requestContext = defaultOIDCManager.sendForLogin(request, response);
if (request.getRequestURI() != null) {
String redirectPageURI = request.getRequestURI().substring(request.getContextPath().length() + 1);
requestContext.setParameter(SSOAgentConstants.REDIRECT_URI_KEY, redirectPageURI);
}
session.setAttribute(SSOAgentConstants.REQUEST_CONTEXT, requestContext);
}
use of io.asgardeo.java.oidc.sdk.bean.RequestContext in project asgardeo-java-oidc-sdk by asgardeo.
the class HTTPSessionBasedOIDCProcessor method logout.
/**
* Builds a logout request and redirects.
*
* @param request Incoming {@link HttpServletRequest}.
* @param response Outgoing {@link HttpServletResponse}
* @throws SSOAgentException
*/
public void logout(HttpServletRequest request, HttpServletResponse response) throws SSOAgentException {
SessionContext sessionContext = getSessionContext(request);
clearSession(request);
HttpSession session = request.getSession();
RequestContext requestContext = defaultOIDCManager.logout(sessionContext, response);
session.setAttribute(SSOAgentConstants.REQUEST_CONTEXT, requestContext);
}
Aggregations