Search in sources :

Example 1 with RequestContext

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);
}
Also used : HttpSession(javax.servlet.http.HttpSession) SessionContext(io.asgardeo.java.oidc.sdk.bean.SessionContext) RequestContext(io.asgardeo.java.oidc.sdk.bean.RequestContext) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with RequestContext

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);
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) State(com.nimbusds.oauth2.sdk.id.State) HttpSession(javax.servlet.http.HttpSession) RequestContext(io.asgardeo.java.oidc.sdk.bean.RequestContext) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with 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);
}
Also used : HttpSession(javax.servlet.http.HttpSession) SessionContext(io.asgardeo.java.oidc.sdk.bean.SessionContext) RequestContext(io.asgardeo.java.oidc.sdk.bean.RequestContext) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with 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);
}
Also used : HttpSession(javax.servlet.http.HttpSession) RequestContext(io.asgardeo.java.oidc.sdk.bean.RequestContext)

Example 5 with 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);
}
Also used : HttpSession(javax.servlet.http.HttpSession) SessionContext(io.asgardeo.java.oidc.sdk.bean.SessionContext) RequestContext(io.asgardeo.java.oidc.sdk.bean.RequestContext)

Aggregations

RequestContext (io.asgardeo.java.oidc.sdk.bean.RequestContext)11 HttpSession (javax.servlet.http.HttpSession)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Test (org.testng.annotations.Test)6 SessionContext (io.asgardeo.java.oidc.sdk.bean.SessionContext)5 State (com.nimbusds.oauth2.sdk.id.State)4 Nonce (com.nimbusds.openid.connect.sdk.Nonce)3 JWT (com.nimbusds.jwt.JWT)2 SSOAgentServerException (io.asgardeo.java.oidc.sdk.exception.SSOAgentServerException)2 URI (java.net.URI)2 AccessTokenResponse (com.nimbusds.oauth2.sdk.AccessTokenResponse)1 AuthorizationCode (com.nimbusds.oauth2.sdk.AuthorizationCode)1 AuthorizationResponse (com.nimbusds.oauth2.sdk.AuthorizationResponse)1 AuthorizationSuccessResponse (com.nimbusds.oauth2.sdk.AuthorizationSuccessResponse)1 ResponseType (com.nimbusds.oauth2.sdk.ResponseType)1 Scope (com.nimbusds.oauth2.sdk.Scope)1 TokenResponse (com.nimbusds.oauth2.sdk.TokenResponse)1 HTTPRequest (com.nimbusds.oauth2.sdk.http.HTTPRequest)1 ServletUtils (com.nimbusds.oauth2.sdk.http.ServletUtils)1 ClientID (com.nimbusds.oauth2.sdk.id.ClientID)1