Search in sources :

Example 1 with OIDCSessionManagerException

use of org.wso2.carbon.identity.oidc.session.OIDCSessionManagerException in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCSessionIFrameServlet method getCallbackURL.

private String getCallbackURL(HttpServletRequest request, String clientId) throws InvalidOAuthClientException, IdentityOAuth2Exception, OIDCSessionManagerException {
    OAuthAppDO oAuthAppDO = OAuth2Util.getAppInformationByClientId(clientId);
    String configuredCallbackURL = oAuthAppDO.getCallbackUrl();
    if (log.isDebugEnabled()) {
        log.debug("Requested client_id : " + clientId + " Configured callbackUrl : " + configuredCallbackURL);
    }
    if (StringUtils.isBlank(configuredCallbackURL)) {
        throw new OIDCSessionManagerException("CallbackURL is empty in service provider configuration, clientId : " + clientId);
    }
    if (configuredCallbackURL.startsWith(OAuthConstants.CALLBACK_URL_REGEXP_PREFIX)) {
        if (log.isDebugEnabled()) {
            log.debug("Regex value found for callback url in service provider.");
        }
        String rpIFrameReqCallbackURL = request.getParameter(OIDCSessionConstants.OIDC_REDIRECT_URI_PARAM);
        if (StringUtils.isBlank(rpIFrameReqCallbackURL)) {
            throw new OIDCSessionManagerException("Invalid request. redirect_uri not found in request as parameter. It is " + "mandatory because of there is regex pattern for " + "callback url in service provider configuration. client_id : " + clientId);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Requested redirect_uri from rp IFrame : " + rpIFrameReqCallbackURL);
            }
            String regexp = configuredCallbackURL.substring(OAuthConstants.CALLBACK_URL_REGEXP_PREFIX.length());
            if (rpIFrameReqCallbackURL.matches(regexp)) {
                if (log.isDebugEnabled()) {
                    log.debug("Requested redirect_uri is matched with the regex in service provider.");
                }
                configuredCallbackURL = rpIFrameReqCallbackURL;
            } else {
                throw new OIDCSessionManagerException("Invalid request. redirect_uri is not matched with the regex that is " + "configured in the service provider, client_id : " + clientId);
            }
        }
    }
    return configuredCallbackURL;
}
Also used : OAuthAppDO(org.wso2.carbon.identity.oauth.dao.OAuthAppDO) OIDCSessionManagerException(org.wso2.carbon.identity.oidc.session.OIDCSessionManagerException)

Aggregations

OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)1 OIDCSessionManagerException (org.wso2.carbon.identity.oidc.session.OIDCSessionManagerException)1