use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthContextTokenDOTest method initTest.
@BeforeClass
public void initTest() throws SocketException {
authzCodeDO = new AuthzCodeDO();
authContextTokenDO = new AuthContextTokenDO(AUTHZ_CODE, CONSUMER_KEY, CALLBACK_URL, authzCodeDO);
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeGrantHandlerTest method testValidateGrantException.
@Test(dataProvider = "buildErrorTokenRequestMessageContext")
public void testValidateGrantException(Object tokenRequestMessageContext, Object authzCode, String clientId, boolean pkceValid, long timestamp, String expectedError) throws Exception {
AuthzCodeDO authzCodeDO = (AuthzCodeDO) authzCode;
WhiteboxImpl.setInternalState(authorizationCodeGrantHandler, "cacheEnabled", true);
OAuthCache oAuthCache = mock(OAuthCache.class);
when(OAuthCache.getInstance()).thenReturn(oAuthCache);
WhiteboxImpl.setInternalState(authorizationCodeGrantHandler, "oauthCache", oAuthCache);
OAuthTokenReqMessageContext tokReqMsgCtx = (OAuthTokenReqMessageContext) tokenRequestMessageContext;
oAuthServerConfiguration = mock(OAuthServerConfiguration.class);
TokenPersistenceProcessor tokenPersistenceProcessor = mock(TokenPersistenceProcessor.class);
when(OAuthServerConfiguration.getInstance()).thenReturn(oAuthServerConfiguration);
when(oAuthServerConfiguration.getPersistenceProcessor()).thenReturn(tokenPersistenceProcessor);
OAuthAppDAO oAuthAppDAO = mock(OAuthAppDAO.class);
OAuthAppDO oAuthAppDO = new OAuthAppDO();
whenNew(OAuthAppDAO.class).withNoArguments().thenReturn(oAuthAppDAO);
when(oAuthAppDAO.getAppInformation(CLIENT_ID_VALUE)).thenReturn(oAuthAppDO);
when(oAuthAppDAO.getAppInformation(INVALID_CLIENT)).thenThrow(new InvalidOAuthClientException("Error"));
AppInfoCache appInfoCache = mock(AppInfoCache.class);
when(AppInfoCache.getInstance()).thenReturn(appInfoCache);
doNothing().when(appInfoCache).addToCache(anyString(), any(OAuthAppDO.class));
spy(OAuth2Util.class);
doReturn(pkceValid).when(OAuth2Util.class, "validatePKCE", anyString(), anyString(), anyString(), any(OAuthAppDO.class));
try {
authorizationCodeGrantHandler.validateGrant(tokReqMsgCtx);
fail("Expected exception not thrown");
} catch (IdentityOAuth2Exception e) {
assertTrue(e.getMessage().contains(expectedError), "Expected error message with '" + expectedError + "'");
}
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeGrantHandlerTest method buildTokenRequestMessageContext.
@DataProvider(name = "BuildTokenRequestMessageContext")
public Object[][] buildTokenRequestMessageContext() {
OAuthTokenReqMessageContext messageContext1 = new OAuthTokenReqMessageContext(new OAuth2AccessTokenReqDTO());
messageContext1.getOauth2AccessTokenReqDTO().setAuthorizationCode("123456");
OAuthTokenReqMessageContext messageContext2 = new OAuthTokenReqMessageContext(new OAuth2AccessTokenReqDTO());
messageContext2.getOauth2AccessTokenReqDTO().setAuthorizationCode("123456");
messageContext2.getOauth2AccessTokenReqDTO().setCallbackURI("callBackUrl");
AuthenticatedUser authenticatedUser = new AuthenticatedUser();
AuthzCodeDO authzCodeDO1 = new AuthzCodeDO();
WhiteboxImpl.setInternalState(authzCodeDO1, "authorizedUser", authenticatedUser);
WhiteboxImpl.setInternalState(authzCodeDO1, "callbackUrl", "callBackUrl");
AuthzCodeDO authzCodeDO2 = new AuthzCodeDO();
return new Object[][] { { messageContext1, authzCodeDO2, false, true, System.currentTimeMillis() + 250000L, true }, { messageContext2, authzCodeDO1, true, false, System.currentTimeMillis() + 250000L, true } };
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class RequestObjectHandlerTest method revokeAccessToken.
@DataProvider(name = "requestObjectRevoke")
public Object[][] revokeAccessToken() {
List<String> codeList = new ArrayList<>();
codeList.add("code1");
codeList.add("code2");
AuthzCodeDO authzCodeDO = new AuthzCodeDO();
authzCodeDO.setAuthorizationCode("code1");
authzCodeDO.setAuthzCodeId("coded1");
AuthzCodeDO authzCodeDO1 = new AuthzCodeDO();
authzCodeDO1.setAuthzCodeId("codeId2");
authzCodeDO1.setAuthorizationCode("code2");
List<AuthzCodeDO> lstAuthzCode = new ArrayList<>();
lstAuthzCode.add(authzCodeDO);
lstAuthzCode.add(authzCodeDO1);
return new Object[][] { { OIDCConstants.Event.POST_REVOKE_ACESS_TOKEN, codeList, null, OIDCConstants.Event.ACEESS_TOKENS, null }, { OIDCConstants.Event.POST_REVOKE_CODE, null, lstAuthzCode, OIDCConstants.Event.CODES, null }, { OIDCConstants.Event.POST_ISSUE_ACCESS_TOKEN, null, null, OIDCConstants.Event.TOKEN_ID, "token1" }, { OIDCConstants.Event.POST_ISSUE_CODE, null, null, OIDCConstants.Event.CODE_ID, "token1" } };
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class RequestObjectHandler method handlePostRevokeCode.
private void handlePostRevokeCode(Map<String, Object> eventProperties, String codeState) throws IdentityOAuth2Exception, IdentityOAuthAdminException {
boolean isCodeRemove = isCodeRemoved(codeState);
List<AuthzCodeDO> authzcodes = (List<AuthzCodeDO>) eventProperties.get(OIDCConstants.Event.CODES);
for (AuthzCodeDO authzCodeDO : authzcodes) {
String codeId = authzCodeDO.getAuthzCodeId();
String tokenId = authzCodeDO.getOauthTokenId();
if (isCodeRemove) {
OAuthTokenPersistenceFactory.getInstance().getRequestObjectDAO().deleteRequestObjectReferenceByCode(codeId);
} else if (StringUtils.isNotEmpty(tokenId) && OAuthConstants.AuthorizationCodeState.INACTIVE.equals(codeState)) {
// update the token id of request object reference identified by code id
OAuthTokenPersistenceFactory.getInstance().getRequestObjectDAO().updateRequestObjectReferenceCodeToToken(codeId, tokenId);
}
}
}
Aggregations