Example usage for javax.servlet.http HttpServletResponse SC_FOUND

List of usage examples for javax.servlet.http HttpServletResponse SC_FOUND

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_FOUND.

Prototype

int SC_FOUND

To view the source code for javax.servlet.http HttpServletResponse SC_FOUND.

Click Source Link

Document

Status code (302) indicating that the resource reside temporarily under a different URI.

Usage

From source file:cn.vlabs.umt.ui.servlet.AuthorizationCodeServlet.java

/**
 * /*from   www.  java2 s. c  o  m*/
 * ?Authorization?????
 * @param request
 * @param response
 * @throws IOException
 * @throws ServletException
 */
private void authorization(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String redirectURI = null;
    try {
        OAuthAuthzRequest oauthRequest = new OAuthAuthzRequest(request);
        String clientId = oauthRequest.getClientId();
        Set<String> scope = oauthRequest.getScopes();
        redirectURI = oauthRequest.getRedirectURI();
        if (!validateClient(clientId, redirectURI, request, response)) {
            return;
        }
        OauthClientBean bean = getClientServer().findByClientId(clientId);
        request.setAttribute("client_name", bean.getClientName());
        request.setAttribute("client_website", bean.getClientWebsite());
        if (!validateScope(clientId, scope)) {
            dealAppError("invalid_scope", "scope[" + scope + "]", redirectURI, response);
            return;
        }
        request.setAttribute(USER_OAUTH_REQUEST, new OAuthAuthzRequestWrap(oauthRequest, request));
        if (userHaveLogin(request, response)) {
            return;
        }
        dealCoremailUserName(request);
        request.setAttribute("thirdPartyList", bean.getThirdPartyMap());
        Map<String, String> siteInfo = new HashMap<String, String>();
        siteInfo.put(Attributes.RETURN_URL, URLEncoder.encode(RequestUtil.getFullRequestUrl(request), "UTF-8"));
        siteInfo.put(Attributes.APP_NAME, "umtOauth2");
        SessionUtils.setSessionVar(request, Attributes.SITE_INFO, siteInfo);
        forwordUserInfoPage(request, response);
    } catch (OAuthProblemException ex) {
        if (StringUtils.isEmpty(redirectURI)) {
            redirectURI = request.getParameter("redirect_url");
            if (StringUtils.isEmpty(redirectURI)) {
                request.setAttribute("client_id", request.getParameter("client_id"));
                request.setAttribute("errorCode", ex.getError());
                request.setAttribute("errorDescription", ex.getDescription());
                dealClientRedirectError(request, response);
                return;
            }
        }
        OAuthResponse resp = null;
        try {
            resp = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND).error(ex).location(redirectURI)
                    .buildQueryMessage();
        } catch (OAuthSystemException e) {
            LOG.error("", e);
        }
        response.sendRedirect(resp.getLocationUri());
        LOG.info("redirect=" + redirectURI, ex);
    } catch (OAuthSystemException e) {
        LOG.error("", e);
        dealOAuthSystemError(redirectURI, e, request, response);
    }
}

From source file:org.wso2.carbon.identity.oauth.endpoint.expmapper.InvalidRequestExceptionMapper.java

private Response buildErrorResponseConsentHandlingFailure(InvalidRequestParentException exception)
        throws URISyntaxException {

    if (log.isDebugEnabled()) {
        log.debug("System Error while handling consent: ", exception);
    }/*from   w  ww  .  j  a va 2s  . c  o  m*/
    return Response.status(HttpServletResponse.SC_FOUND).location(new URI(EndpointUtil.getErrorPageURL(request,
            OAuth2ErrorCodes.SERVER_ERROR, "Error while handling consent.", null))).build();
}

From source file:com.mercer.cpsg.swarm.oidc.deployment.OIDCAuthenticationMechanism.java

@Override
public ChallengeResult sendChallenge(HttpServerExchange exchange, SecurityContext securityContext) {
    OIDCContext oidcContext = exchange.getAttachment(OIDCContext.ATTACHMENT_KEY);
    // NOT_AUTHENTICATED and NOT_ATTEMPTED always send challenges
    if (oidcContext.isError()) {
        return new ChallengeResult(false, HttpServletResponse.SC_UNAUTHORIZED);
    }//  ww  w.  j  a v a2 s.  c o m

    String redirectURL = buildAuthorizationURL(exchange);
    LOG.fine("Challenge redirect:" + redirectURL);
    exchange.getResponseHeaders().put(Headers.LOCATION, redirectURL);
    return new ChallengeResult(true, HttpServletResponse.SC_FOUND);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.OAuthAction.java

private ActionForward redirectWithCode(HttpServletRequest request, HttpServletResponse response,
        ExternalApplication clientApplication) {
    try {//from ww w  . j  a  v a2  s  .co m
        final String code = createAppUserSession(clientApplication, getLoggedPerson(request).getUser(), request,
                response);
        OAuthResponse resp = OAuthASResponse.authorizationResponse(request, HttpServletResponse.SC_FOUND)
                .location(clientApplication.getRedirectUrl()).setCode(code).buildQueryMessage();
        response.sendRedirect(resp.getLocationUri());
    } catch (OAuthSystemException e) {
        logger.error(e.getMessage(), e);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}

From source file:org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.java

@GET
@Path("/")
@Consumes("application/x-www-form-urlencoded")
@Produces("text/html")
public Response authorize(@Context HttpServletRequest request, @Context HttpServletResponse response)
        throws URISyntaxException {

    // Setting super-tenant carbon context
    PrivilegedCarbonContext.startTenantFlow();
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

    // Validate repeated parameters
    if (!(request instanceof OAuthRequestWrapper)) {
        if (!EndpointUtil.validateParams(request, response, null)) {
            return Response.status(HttpServletResponse.SC_BAD_REQUEST)
                    .location(new URI(EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST,
                            "Invalid authorization request with repeated parameters", null)))
                    .build();/*from  www . j a  va 2s .  c o m*/
        }
    }

    String clientId = request.getParameter("client_id");

    String sessionDataKeyFromLogin = getSessionDataKey(request);
    String sessionDataKeyFromConsent = request.getParameter(OAuthConstants.SESSION_DATA_KEY_CONSENT);
    SessionDataCacheKey cacheKey = null;
    SessionDataCacheEntry resultFromLogin = null;
    SessionDataCacheEntry resultFromConsent = null;

    Object flowStatus = request.getAttribute(FrameworkConstants.RequestParams.FLOW_STATUS);
    String isToCommonOauth = request.getParameter(FrameworkConstants.RequestParams.TO_COMMONAUTH);

    if ("true".equals(isToCommonOauth) && flowStatus == null) {
        try {
            return sendRequestToFramework(request, response);
        } catch (ServletException | IOException e) {
            log.error("Error occurred while sending request to authentication framework.");
            return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).build();
        }
    }

    if (StringUtils.isNotEmpty(sessionDataKeyFromLogin)) {
        cacheKey = new SessionDataCacheKey(sessionDataKeyFromLogin);
        resultFromLogin = SessionDataCache.getInstance().getValueFromCache(cacheKey);
    }
    if (StringUtils.isNotEmpty(sessionDataKeyFromConsent)) {
        cacheKey = new SessionDataCacheKey(sessionDataKeyFromConsent);
        resultFromConsent = SessionDataCache.getInstance().getValueFromCache(cacheKey);
        SessionDataCache.getInstance().clearCacheEntry(cacheKey);
    }
    if (resultFromLogin != null && resultFromConsent != null) {

        if (log.isDebugEnabled()) {
            log.debug("Invalid authorization request.\'SessionDataKey\' found in request as parameter and "
                    + "attribute, and both have non NULL objects in cache");
        }
        return Response.status(HttpServletResponse.SC_FOUND).location(new URI(EndpointUtil
                .getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST, "Invalid authorization request", null)))
                .build();

    } else if (clientId == null && resultFromLogin == null && resultFromConsent == null) {

        if (log.isDebugEnabled()) {
            log.debug("Invalid authorization request.\'SessionDataKey\' not found in request as parameter or "
                    + "attribute, and client_id parameter cannot be found in request");
        }
        return Response.status(HttpServletResponse.SC_FOUND).location(new URI(EndpointUtil
                .getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST, "Invalid authorization request", null)))
                .build();

    } else if (sessionDataKeyFromLogin != null && resultFromLogin == null) {
        if (log.isDebugEnabled()) {
            log.debug("Session data not found in SessionDataCache for " + sessionDataKeyFromLogin);
        }
        return Response.status(HttpServletResponse.SC_FOUND).location(new URI(
                EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.ACCESS_DENIED, "Session Timed Out", null)))
                .build();

    } else if (sessionDataKeyFromConsent != null && resultFromConsent == null) {

        if (resultFromLogin == null) {
            if (log.isDebugEnabled()) {
                log.debug("Session data not found in SessionDataCache for " + sessionDataKeyFromConsent);
            }
            return Response
                    .status(HttpServletResponse.SC_FOUND).location(new URI(EndpointUtil
                            .getErrorPageURL(OAuth2ErrorCodes.ACCESS_DENIED, "Session Timed Out", null)))
                    .build();
        } else {
            sessionDataKeyFromConsent = null;
        }

    }
    SessionDataCacheEntry sessionDataCacheEntry = null;

    try {
        if (StringUtils.isNotEmpty(clientId)) {
            OAuthAppDAO oAuthAppDAO = new OAuthAppDAO();
            try {
                String appState = oAuthAppDAO.getConsumerAppState(clientId);
                if (StringUtils.isEmpty(appState)) {
                    if (log.isDebugEnabled()) {
                        log.debug("A valid OAuth client could not be found for client_id: " + clientId);
                    }
                    OAuthResponse oAuthResponse = OAuthASResponse
                            .errorResponse(HttpServletResponse.SC_UNAUTHORIZED)
                            .setError(OAuth2ErrorCodes.INVALID_CLIENT)
                            .setErrorDescription(
                                    "A valid OAuth client could not be found for client_id: " + clientId)
                            .buildJSONMessage();
                    return Response.status(oAuthResponse.getResponseStatus()).entity(oAuthResponse.getBody())
                            .build();
                }

                if (!OAuthConstants.OauthAppStates.APP_STATE_ACTIVE.equalsIgnoreCase(appState)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Oauth App is not in active state.");
                    }
                    OAuthResponse oAuthResponse = OAuthASResponse
                            .errorResponse(HttpServletResponse.SC_UNAUTHORIZED)
                            .setError(OAuth2ErrorCodes.INVALID_CLIENT)
                            .setErrorDescription("Oauth application is not in active state.")
                            .buildJSONMessage();
                    return Response.status(oAuthResponse.getResponseStatus()).entity(oAuthResponse.getBody())
                            .build();
                }
            } catch (IdentityOAuthAdminException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Error in getting oauth app state.", e);
                }
                OAuthResponse oAuthResponse = OAuthASResponse.errorResponse(HttpServletResponse.SC_NOT_FOUND)
                        .setError(OAuth2ErrorCodes.SERVER_ERROR)
                        .setErrorDescription("Error in getting oauth app state.").buildJSONMessage();
                return Response.status(oAuthResponse.getResponseStatus()).entity(oAuthResponse.getBody())
                        .build();
            }
        }

        if (clientId != null && sessionDataKeyFromLogin == null && sessionDataKeyFromConsent == null) {
            // Authz request from client
            String redirectURL = null;

            redirectURL = handleOAuthAuthorizationRequest(clientId, request);

            String type = OAuthConstants.Scope.OAUTH2;
            String scopes = request.getParameter(OAuthConstants.OAuth10AParams.SCOPE);
            if (scopes != null && scopes.contains(OAuthConstants.Scope.OPENID)) {
                type = OAuthConstants.Scope.OIDC;
            }
            Object attribute = request.getAttribute(FrameworkConstants.RequestParams.FLOW_STATUS);
            if (attribute != null && attribute == AuthenticatorFlowStatus.SUCCESS_COMPLETED) {
                try {
                    return sendRequestToFramework(request, response,
                            (String) request.getAttribute(FrameworkConstants.SESSION_DATA_KEY), type);
                } catch (ServletException | IOException e) {
                    log.error("Error occurred while sending request to authentication framework.");
                }
                return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).build();
            } else {
                return Response.status(HttpServletResponse.SC_FOUND).location(new URI(redirectURL)).build();
            }

        } else if (resultFromLogin != null) { // Authentication response
            Cookie cookie = FrameworkUtils.getAuthCookie(request);
            long authTime = getAuthenticatedTimeFromCommonAuthCookie(cookie);
            sessionDataCacheEntry = resultFromLogin;
            if (authTime > 0) {
                sessionDataCacheEntry.setAuthTime(authTime);
            }
            OAuth2Parameters oauth2Params = sessionDataCacheEntry.getoAuth2Parameters();
            AuthenticationResult authnResult = getAuthenticationResult(request, sessionDataKeyFromLogin);
            if (authnResult != null) {
                removeAuthenticationResult(request, sessionDataKeyFromLogin);

                String redirectURL = null;
                boolean isOIDCRequest = OAuth2Util.isOIDCAuthzRequest(oauth2Params.getScopes());
                if (authnResult.isAuthenticated()) {
                    AuthenticatedUser authenticatedUser = authnResult.getSubject();
                    if (authenticatedUser.getUserAttributes() != null) {
                        authenticatedUser.setUserAttributes(new ConcurrentHashMap<ClaimMapping, String>(
                                authenticatedUser.getUserAttributes()));
                    }
                    sessionDataCacheEntry.setLoggedInUser(authenticatedUser);
                    sessionDataCacheEntry.setAuthenticatedIdPs(authnResult.getAuthenticatedIdPs());
                    SessionDataCache.getInstance().addToCache(cacheKey, sessionDataCacheEntry);

                    OIDCSessionState sessionState = new OIDCSessionState();
                    redirectURL = doUserAuthz(request, sessionDataKeyFromLogin, sessionDataCacheEntry,
                            sessionState);

                    if (RESPONSE_MODE_FORM_POST.equals(oauth2Params.getResponseMode()) && isJSON(redirectURL)) {

                        String sessionStateValue = null;
                        if (isOIDCRequest) {
                            sessionState.setAddSessionState(true);
                            sessionStateValue = manageOIDCSessionState(request, response, sessionState,
                                    oauth2Params,
                                    sessionDataCacheEntry.getLoggedInUser().getAuthenticatedSubjectIdentifier(),
                                    redirectURL);
                        }

                        return Response.ok(createFormPage(redirectURL, oauth2Params.getRedirectURI(),
                                StringUtils.EMPTY, sessionStateValue)).build();
                    }

                    if (isOIDCRequest) {
                        redirectURL = manageOIDCSessionState(request, response, sessionState, oauth2Params,
                                authenticatedUser.getAuthenticatedSubjectIdentifier(), redirectURL);
                    }

                    return Response.status(HttpServletResponse.SC_FOUND).location(new URI(redirectURL)).build();

                } else {

                    OAuthProblemException oauthException = buildOAuthProblemException(authnResult);
                    redirectURL = EndpointUtil.getErrorRedirectURL(oauthException, oauth2Params);
                    if (isOIDCRequest) {
                        Cookie opBrowserStateCookie = OIDCSessionManagementUtil
                                .getOPBrowserStateCookie(request);
                        redirectURL = OIDCSessionManagementUtil.addSessionStateToURL(redirectURL,
                                oauth2Params.getClientId(), oauth2Params.getRedirectURI(), opBrowserStateCookie,
                                oauth2Params.getResponseType());
                    }
                }
                return Response.status(HttpServletResponse.SC_FOUND).location(new URI(redirectURL)).build();

            } else {

                String appName = sessionDataCacheEntry.getoAuth2Parameters().getApplicationName();

                if (log.isDebugEnabled()) {
                    log.debug("Invalid authorization request. \'sessionDataKey\' attribute found but "
                            + "corresponding AuthenticationResult does not exist in the cache.");
                }
                return Response.status(HttpServletResponse.SC_FOUND)
                        .location(new URI(EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST,
                                "Invalid authorization request", appName)))
                        .build();

            }

        } else if (resultFromConsent != null) { // Consent submission
            Cookie cookie = FrameworkUtils.getAuthCookie(request);
            long authTime = getAuthenticatedTimeFromCommonAuthCookie(cookie);
            sessionDataCacheEntry = resultFromConsent;
            OAuth2Parameters oauth2Params = sessionDataCacheEntry.getoAuth2Parameters();
            if (authTime > 0) {
                oauth2Params.setAuthTime(authTime);
            }
            boolean isOIDCRequest = OAuth2Util.isOIDCAuthzRequest(oauth2Params.getScopes());

            String consent = request.getParameter("consent");
            if (consent != null) {

                if (OAuthConstants.Consent.DENY.equals(consent)) {
                    OpenIDConnectUserRPStore.getInstance().putUserRPToStore(resultFromConsent.getLoggedInUser(),
                            resultFromConsent.getoAuth2Parameters().getApplicationName(), false,
                            oauth2Params.getClientId());
                    // return an error if user denied
                    OAuthProblemException ex = OAuthProblemException.error(OAuth2ErrorCodes.ACCESS_DENIED);
                    String denyResponse = EndpointUtil.getErrorRedirectURL(ex, oauth2Params);

                    if (isOIDCRequest) {
                        Cookie opBrowserStateCookie = OIDCSessionManagementUtil
                                .getOPBrowserStateCookie(request);
                        denyResponse = OIDCSessionManagementUtil.addSessionStateToURL(denyResponse,
                                oauth2Params.getClientId(), oauth2Params.getRedirectURI(), opBrowserStateCookie,
                                oauth2Params.getResponseType());
                    }
                    return Response.status(HttpServletResponse.SC_FOUND).location(new URI(denyResponse))
                            .build();
                }

                OIDCSessionState sessionState = new OIDCSessionState();
                String redirectURL = handleUserConsent(request, consent, oauth2Params, sessionDataCacheEntry,
                        sessionState);

                String authenticatedIdPs = sessionDataCacheEntry.getAuthenticatedIdPs();

                if (RESPONSE_MODE_FORM_POST.equals(oauth2Params.getResponseMode()) && isJSON(redirectURL)) {

                    String sessionStateValue = null;
                    if (isOIDCRequest) {
                        sessionState.setAddSessionState(true);
                        sessionStateValue = manageOIDCSessionState(request, response, sessionState,
                                oauth2Params,
                                sessionDataCacheEntry.getLoggedInUser().getAuthenticatedSubjectIdentifier(),
                                redirectURL);
                    }

                    return Response.ok(createFormPage(redirectURL, oauth2Params.getRedirectURI(),
                            authenticatedIdPs, sessionStateValue)).build();
                }

                if (isOIDCRequest) {
                    sessionState.setAddSessionState(true);
                    redirectURL = manageOIDCSessionState(request, response, sessionState, oauth2Params,
                            sessionDataCacheEntry.getLoggedInUser().getAuthenticatedSubjectIdentifier(),
                            redirectURL);
                }

                return Response.status(HttpServletResponse.SC_FOUND).location(new URI(redirectURL)).build();
            } else {
                String appName = sessionDataCacheEntry.getoAuth2Parameters().getApplicationName();

                if (log.isDebugEnabled()) {
                    log.debug(
                            "Invalid authorization request. \'sessionDataKey\' parameter found but \'consent\' "
                                    + "parameter could not be found in request");
                }
                return Response.status(HttpServletResponse.SC_FOUND)
                        .location(new URI(EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST,
                                "Invalid authorization " + "request", appName)))
                        .build();
            }

        } else { // Invalid request
            if (log.isDebugEnabled()) {
                log.debug("Invalid authorization request");
            }

            return Response.status(HttpServletResponse.SC_FOUND).location(new URI(EndpointUtil
                    .getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST, "Invalid authorization request", null)))
                    .build();
        }

    } catch (OAuthProblemException e) {

        if (log.isDebugEnabled()) {
            log.debug(e.getError(), e);
        }
        String errorPageURL = EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST, e.getMessage(),
                null);
        String redirectURI = request.getParameter(REDIRECT_URI);

        if (redirectURI != null) {
            try {
                errorPageURL = errorPageURL + "&" + REDIRECT_URI + "="
                        + URLEncoder.encode(redirectURI, StandardCharsets.UTF_8.name());
            } catch (UnsupportedEncodingException e1) {
                if (log.isDebugEnabled()) {
                    log.debug("Error while encoding the error page url", e);
                }
            }
        }
        return Response.status(HttpServletResponse.SC_FOUND).location(new URI(errorPageURL))
                .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_TYPE).build();

    } catch (OAuthSystemException e) {

        OAuth2Parameters params = null;
        if (sessionDataCacheEntry != null) {
            params = sessionDataCacheEntry.getoAuth2Parameters();
        }
        if (log.isDebugEnabled()) {
            log.debug("Server error occurred while performing authorization", e);
        }
        OAuthProblemException ex = OAuthProblemException.error(OAuth2ErrorCodes.SERVER_ERROR,
                "Server error occurred while performing authorization");
        return Response.status(HttpServletResponse.SC_FOUND)
                .location(new URI(EndpointUtil.getErrorRedirectURL(ex, params))).build();

    } finally {
        if (sessionDataKeyFromConsent != null) {
            /*
             * TODO Cache retaining is a temporary fix. Remove after Google fixes
             * http://code.google.com/p/gdata-issues/issues/detail?id=6628
             */
            String retainCache = System.getProperty("retainCache");

            if (retainCache == null) {
                clearCacheEntry(sessionDataKeyFromConsent);
            }
        }

        PrivilegedCarbonContext.endTenantFlow();
    }
}

From source file:cn.vlabs.umt.ui.servlet.AuthorizationCodeServlet.java

/**
 * ?//  ww  w. j  av a  2  s. co  m
 * @param errorCode 
 * @param redirectURI
 * @param response
 * @throws IOException
 */
private void dealAppError(String errorCode, String desc, String redirectURI, HttpServletResponse response)
        throws IOException {
    OAuthResponse resp = null;
    try {
        resp = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND).setError(errorCode)
                .setErrorDescription(desc).location(redirectURI).buildQueryMessage();
    } catch (OAuthSystemException e) {
        LOG.error("", e);
    }
    LOG.info("redirectURI=" + redirectURI + "?errorCode=" + errorCode + ";description=" + desc
            + ";");
    response.sendRedirect(resp.getLocationUri());
}

From source file:org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpointTest.java

@DataProvider(name = "providePostParams")
public Object[][] providePostParams() {
    MultivaluedMap<String, String> paramMap1 = new MultivaluedHashMap<String, String>();
    List<String> list1 = new ArrayList<>();
    list1.add("value1");
    list1.add("value2");
    paramMap1.put("paramName1", list1);

    Map<String, String[]> requestParams1 = new HashMap<>();
    requestParams1.put("reqParam1", new String[] { "val1", "val2" });

    MultivaluedMap<String, String> paramMap2 = new MultivaluedHashMap<String, String>();
    List<String> list2 = new ArrayList<>();
    list2.add("value1");
    paramMap2.put("paramName1", list2);

    Map<String, String[]> requestParams2 = new HashMap<>();
    requestParams2.put("reqParam1", new String[] { "val1" });

    return new Object[][] { { paramMap2, requestParams2, HttpServletResponse.SC_FOUND },
            { paramMap1, requestParams2, HttpServletResponse.SC_BAD_REQUEST }, };
}

From source file:edu.harvard.i2b2.fhirserver.ws.OAuth2AuthzEndpoint.java

String successfulResponse(HttpServletRequest request)
        throws OAuthSystemException, URISyntaxException, OAuthProblemException {
    OAuthAuthzRequest oauthRequest = new OAuthAuthzRequest(request);
    OAuthIssuerImpl oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());

    String responseType = oauthRequest.getParam(OAuth.OAUTH_RESPONSE_TYPE);

    OAuthASResponse.OAuthAuthorizationResponseBuilder builder = OAuthASResponse.authorizationResponse(request,
            HttpServletResponse.SC_FOUND);

    String redirectURI = oauthRequest.getRedirectURI();

    if (responseType.equals(ResponseType.CODE.toString())) {
        String authorizationCode = oauthIssuerImpl.authorizationCode();

        logger.info("generated authorizationCode:" + authorizationCode);
        builder.setCode(authorizationCode);
        builder.setParam("state", oauthRequest.getState());

        HttpSession session = request.getSession();
        session.setAttribute("authorizationCode", authorizationCode);
        logger.info("put generated authcode " + session.getAttribute("authorizationCode") + " in session "
                + session.getId());/*from  w  w  w .j a  v  a2  s . c  o m*/

    }
    final OAuthResponse Oresponse = builder.location(redirectURI).buildQueryMessage();
    URI url = new URI(Oresponse.getLocationUri());

    return url.toString();
}

From source file:org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpointTest.java

@DataProvider(name = "provideParams")
public Object[][] provideParams() {
    initMocks(this);

    return new Object[][] {
            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { "val1", "val2" },
                    SESSION_DATA_KEY_CONSENT_VALUE, "true", "scope1", SESSION_DATA_KEY_VALUE, null,
                    HttpServletResponse.SC_BAD_REQUEST, OAuth2ErrorCodes.INVALID_REQUEST },

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { CLIENT_ID_VALUE },
                    SESSION_DATA_KEY_CONSENT_VALUE, "true", "scope1", SESSION_DATA_KEY_VALUE, null,
                    HttpServletResponse.SC_FOUND, OAuth2ErrorCodes.INVALID_REQUEST },

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, null, null, "true", "scope1", null, null,
                    HttpServletResponse.SC_FOUND, OAuth2ErrorCodes.INVALID_REQUEST },

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { CLIENT_ID_VALUE },
                    SESSION_DATA_KEY_CONSENT_VALUE, "true", "scope1", "invalidSession", null,
                    HttpServletResponse.SC_FOUND, OAuth2ErrorCodes.ACCESS_DENIED },

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { CLIENT_ID_VALUE },
                    "invalidConsentCacheKey", "true", "scope1", null, null, HttpServletResponse.SC_FOUND,
                    OAuth2ErrorCodes.ACCESS_DENIED },

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { "invalidId" }, "invalidConsentCacheKey",
                    "true", "scope1", SESSION_DATA_KEY_VALUE, null, HttpServletResponse.SC_UNAUTHORIZED,
                    OAuth2ErrorCodes.INVALID_CLIENT },

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { INACTIVE_CLIENT_ID_VALUE },
                    "invalidConsentCacheKey", "true", "scope1", SESSION_DATA_KEY_VALUE, null,
                    HttpServletResponse.SC_UNAUTHORIZED, OAuth2ErrorCodes.INVALID_CLIENT },

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { CLIENT_ID_VALUE },
                    "invalidConsentCacheKey", "true", "scope1", SESSION_DATA_KEY_VALUE, null,
                    HttpServletResponse.SC_FOUND, OAuth2ErrorCodes.INVALID_REQUEST },

            { null, new String[] { CLIENT_ID_VALUE }, SESSION_DATA_KEY_CONSENT_VALUE, "true", "scope1",
                    SESSION_DATA_KEY_VALUE, null, HttpServletResponse.SC_FOUND,
                    OAuth2ErrorCodes.INVALID_REQUEST },

            { null, new String[] { CLIENT_ID_VALUE }, SESSION_DATA_KEY_CONSENT_VALUE, "true", "scope1",
                    SESSION_DATA_KEY_VALUE, new IOException(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    null },//from   w ww . j ava2s.  c  o  m

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { CLIENT_ID_VALUE }, null, "true",
                    "scope1", null, null, HttpServletResponse.SC_FOUND, OAuth2ErrorCodes.INVALID_REQUEST },

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { CLIENT_ID_VALUE }, null, "true",
                    "scope1", null, OAuthProblemException.error("error"), HttpServletResponse.SC_FOUND,
                    OAuth2ErrorCodes.INVALID_REQUEST },

            { AuthenticatorFlowStatus.SUCCESS_COMPLETED, new String[] { CLIENT_ID_VALUE }, null, "true",
                    "scope1", null, new IOException(), HttpServletResponse.SC_FOUND,
                    OAuth2ErrorCodes.INVALID_REQUEST },

            { null, new String[] { CLIENT_ID_VALUE }, null, "false", null, null, null,
                    HttpServletResponse.SC_FOUND, OAuth2ErrorCodes.INVALID_REQUEST },

            { AuthenticatorFlowStatus.INCOMPLETE, new String[] { CLIENT_ID_VALUE }, null, "false",
                    OAuthConstants.Scope.OPENID, null, null, HttpServletResponse.SC_FOUND,
                    OAuth2ErrorCodes.INVALID_REQUEST },

            { AuthenticatorFlowStatus.INCOMPLETE, null, null, "false", OAuthConstants.Scope.OPENID, null, null,
                    HttpServletResponse.SC_FOUND, OAuth2ErrorCodes.INVALID_REQUEST }, };
}