Search in sources :

Example 21 with URLBuilderException

use of org.wso2.carbon.identity.core.URLBuilderException in project identity-inbound-auth-oauth by wso2-extensions.

the class UserAuthenticationEndpoint method setCallbackURI.

/**
 * This method is used to set the callback uri. If there is no value it will set a default value.
 *
 * @param clientId Consumer key of the application.
 * @throws IdentityOAuth2Exception
 */
private void setCallbackURI(String clientId) throws IdentityOAuth2Exception {
    try {
        OAuthAppDO oAuthAppDO;
        oAuthAppDO = OAuth2Util.getAppInformationByClientId(clientId);
        String redirectURI = oAuthAppDO.getCallbackUrl();
        if (StringUtils.isBlank(redirectURI)) {
            String appName = oAuthAppDO.getApplicationName();
            redirectURI = getRedirectionURI(appName);
            deviceAuthService.setCallbackUri(clientId, redirectURI);
            AppInfoCache.getInstance().clearCacheEntry(clientId);
        }
        deviceFlowDO.setCallbackUri(redirectURI);
    } catch (InvalidOAuthClientException | URISyntaxException | URLBuilderException | IdentityOAuth2Exception e) {
        String errorMsg = String.format("Error when getting app details for client id : %s", clientId);
        throw new IdentityOAuth2Exception(errorMsg, e);
    }
}
Also used : OAuthAppDO(org.wso2.carbon.identity.oauth.dao.OAuthAppDO) URLBuilderException(org.wso2.carbon.identity.core.URLBuilderException) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) URISyntaxException(java.net.URISyntaxException) InvalidOAuthClientException(org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException)

Example 22 with URLBuilderException

use of org.wso2.carbon.identity.core.URLBuilderException in project identity-inbound-auth-oauth by wso2-extensions.

the class EndpointUtilTest method mockServiceURLBuilder.

private void mockServiceURLBuilder(String url) throws URLBuilderException {
    mockStatic(ServiceURLBuilder.class);
    ServiceURLBuilder serviceURLBuilder = mock(ServiceURLBuilder.class);
    when(ServiceURLBuilder.create()).thenReturn(serviceURLBuilder);
    when(serviceURLBuilder.addPath(any())).thenReturn(serviceURLBuilder);
    ServiceURL serviceURL = mock(ServiceURL.class);
    when(serviceURL.getAbsolutePublicURL()).thenReturn(url);
    when(serviceURLBuilder.build()).thenReturn(serviceURL);
}
Also used : ServiceURL(org.wso2.carbon.identity.core.ServiceURL) ServiceURLBuilder(org.wso2.carbon.identity.core.ServiceURLBuilder)

Aggregations

URLBuilderException (org.wso2.carbon.identity.core.URLBuilderException)18 IOException (java.io.IOException)5 ServiceURLBuilder (org.wso2.carbon.identity.core.ServiceURLBuilder)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Test (org.testng.annotations.Test)4 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)4 URISyntaxException (java.net.URISyntaxException)3 HashMap (java.util.HashMap)3 CommonAuthRequestWrapper (org.wso2.carbon.identity.application.authentication.framework.model.CommonAuthRequestWrapper)3 ServiceURL (org.wso2.carbon.identity.core.ServiceURL)3 URI (java.net.URI)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ServletException (javax.servlet.ServletException)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AuthenticationRequestCacheEntry (org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheEntry)2