use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenIssuerTest method testCrossTenantTokenRequestError.
/**
* Tests whether cross tenant token requests fail in tenant qualified URL mode.
*
* @throws Exception
*/
@Test(dataProvider = "tenantDataProvider", expectedExceptions = InvalidOAuthClientException.class)
public void testCrossTenantTokenRequestError(String tenantInContext) throws Exception {
OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO();
reqDTO.setGrantType("password");
OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext();
oAuthClientAuthnContext.setAuthenticated(true);
reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext);
mockStatic(IdentityTenantUtil.class);
when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(true);
when(IdentityTenantUtil.getTenantDomainFromContext()).thenReturn(tenantInContext);
when(OAuth2Util.class, "validateRequestTenantDomain", anyString()).thenCallRealMethod();
mockPasswordGrantHandler(true, true, true, true);
AccessTokenIssuer.getInstance().issue(reqDTO);
}
use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenIssuerTest method testIssueNoAuthorizationGrantHandler.
/**
* No authorization grant handler found for the given grant type.
*
* @throws Exception
*/
@Test
public void testIssueNoAuthorizationGrantHandler() throws Exception {
when(oAuthServerConfiguration.getSupportedGrantTypes()).thenReturn(new HashMap<String, AuthorizationGrantHandler>());
OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO();
reqDTO.setGrantType(DUMMY_GRANT_TYPE);
OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext();
oAuthClientAuthnContext.setAuthenticated(true);
reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext);
OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO);
assertNotNull(tokenRespDTO);
assertTrue(tokenRespDTO.isError());
assertEquals(tokenRespDTO.getErrorCode(), OAuthError.TokenResponse.UNSUPPORTED_GRANT_TYPE);
}
use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class BasicAuthClientAuthenticatorTest method testAuthenticateClientExeption.
@Test(dataProvider = "testClientAuthnDataErrorScenario", expectedExceptions = OAuthClientAuthnException.class)
public void testAuthenticateClientExeption(String headerName, String headerValue, HashMap<String, List> bodyContent, Object oAuthClientAuthnContextObj, Object exception) throws Exception {
OAuthClientAuthnContext oAuthClientAuthnContext = (OAuthClientAuthnContext) oAuthClientAuthnContextObj;
HttpServletRequest httpServletRequest = PowerMockito.mock(HttpServletRequest.class);
PowerMockito.mockStatic(OAuth2Util.class);
if (exception instanceof IdentityOAuthAdminException) {
PowerMockito.when(OAuth2Util.authenticateClient(Matchers.anyString(), Matchers.anyString())).thenThrow((IdentityOAuthAdminException) exception);
} else if (exception instanceof IdentityOAuth2Exception) {
PowerMockito.when(OAuth2Util.authenticateClient(Matchers.anyString(), Matchers.anyString())).thenThrow((IdentityOAuth2Exception) exception);
}
PowerMockito.when(httpServletRequest.getHeader(headerName)).thenReturn(headerValue);
basicAuthClientAuthenticator.authenticateClient(httpServletRequest, bodyContent, oAuthClientAuthnContext);
}
use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class BasicAuthClientAuthenticatorTest method buildOAuthClientAuthnContext.
private OAuthClientAuthnContext buildOAuthClientAuthnContext(String clientId, String clientSecret) {
OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext();
oAuthClientAuthnContext.setClientId(clientId);
if (StringUtils.isNotEmpty(clientSecret)) {
oAuthClientAuthnContext.addParameter(OAuth.OAUTH_CLIENT_SECRET, clientSecret);
}
return oAuthClientAuthnContext;
}
use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class BasicAuthClientAuthenticatorTest method testGetClientIdErrorScenario.
@Test(dataProvider = "testGetClientIdDataErrorScenario", expectedExceptions = OAuthClientAuthnException.class)
public void testGetClientIdErrorScenario(String headerName, String headerValue, HashMap<String, List> bodyContent) throws Exception {
HttpServletRequest httpServletRequest = PowerMockito.mock(HttpServletRequest.class);
PowerMockito.when(httpServletRequest.getHeader(headerName)).thenReturn(headerValue);
basicAuthClientAuthenticator.getClientId(httpServletRequest, bodyContent, new OAuthClientAuthnContext());
}
Aggregations