use of org.wso2.carbon.identity.oauth.dto.OAuthRevocationResponseDTO in project identity-api-user by wso2.
the class AuthorizedAppsService method deleteUserAuthorizedApps.
public void deleteUserAuthorizedApps(User user, String applicationId) {
OAuthRevocationRequestDTO oAuthRevocationRequestDTO = new OAuthRevocationRequestDTO();
oAuthRevocationRequestDTO.setApps(new String[] { applicationId });
try {
startTenantFlowWithUser(getUsernameWithUserStoreDomain(user), user.getTenantDomain());
OAuthConsumerAppDTO[] appsAuthorizedByUser = oAuthAdminService.getAppsAuthorizedByUser();
Optional<OAuthConsumerAppDTO> first = Arrays.stream(appsAuthorizedByUser).filter(oAuthConsumerAppDTO -> oAuthConsumerAppDTO.getApplicationName().equals(applicationId)).findFirst();
if (!first.isPresent()) {
throw handleError(NOT_FOUND, Constants.ErrorMessages.ERROR_CODE_INVALID_APPLICATION_ID, applicationId, user.toFullQualifiedUsername());
}
OAuthRevocationResponseDTO oAuthRevocationResponseDTO = oAuthAdminService.revokeAuthzForAppsByResourceOwner(oAuthRevocationRequestDTO);
if (!oAuthRevocationResponseDTO.isError()) {
// TODO: Handle
log.warn("Given application: " + applicationId + " has been deleted by a PreRevokeListener.");
}
} catch (IdentityOAuthAdminException e) {
throw handleError(Status.INTERNAL_SERVER_ERROR, Constants.ErrorMessages.ERROR_CODE_REVOKE_APP_BY_ID_BY_USER, applicationId, user.toFullQualifiedUsername());
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.identity.oauth.dto.OAuthRevocationResponseDTO in project identity-api-user by wso2.
the class AuthorizedAppsService method deleteUserAuthorizedApps.
public void deleteUserAuthorizedApps(User user) {
OAuthRevocationRequestDTO oAuthRevocationRequestDTO = new OAuthRevocationRequestDTO();
try {
startTenantFlowWithUser(getUsernameWithUserStoreDomain(user), user.getTenantDomain());
List<AuthorizedAppDTO> authorizedAppDTOS = listUserAuthorizedApps(user);
List<String> allAuthorizedApps = authorizedAppDTOS.stream().map(AuthorizedAppDTO::getAppId).collect(Collectors.toList());
oAuthRevocationRequestDTO.setApps(allAuthorizedApps.toArray(new String[0]));
OAuthRevocationResponseDTO oAuthRevocationResponseDTO = oAuthAdminService.revokeAuthzForAppsByResourceOwner(oAuthRevocationRequestDTO);
if (!oAuthRevocationResponseDTO.isError()) {
// TODO: Handle
log.warn("No applications can be found for the user: " + user.getUserName());
}
} catch (IdentityOAuthAdminException e) {
throw handleError(Status.INTERNAL_SERVER_ERROR, Constants.ErrorMessages.ERROR_CODE_REVOKE_APP_BY_USER, user.toFullQualifiedUsername());
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.identity.oauth.dto.OAuthRevocationResponseDTO in project identity-api-user by wso2.
the class AuthorizedAppsService method deleteUserAuthorizedApps.
/**
* Delete all the authorized application for the user.
*
* @param user User.
*/
public void deleteUserAuthorizedApps(User user) {
OAuthRevocationRequestDTO oAuthRevocationRequestDTO = new OAuthRevocationRequestDTO();
try {
startTenantFlowWithUser(getUsernameWithUserStoreDomain(user), user.getTenantDomain());
List<AuthorizedAppDTO> authorizedAppDTOS = listUserAuthorizedApps(user);
List<String> allAuthorizedApps = authorizedAppDTOS.stream().map(AuthorizedAppDTO::getName).collect(Collectors.toList());
oAuthRevocationRequestDTO.setApps(allAuthorizedApps.toArray(new String[0]));
OAuthRevocationResponseDTO oAuthRevocationResponseDTO = oAuthAdminService.revokeAuthzForAppsByResourceOwner(oAuthRevocationRequestDTO);
String userId = getUserIdFromUser(user);
oAuth2ScopeService.revokeUserConsents(userId, IdentityTenantUtil.getTenantId(user.getTenantDomain()));
if (!oAuthRevocationResponseDTO.isError()) {
// TODO: Handle
log.warn("No applications can be found for the user: " + user.getUserName());
}
} catch (IdentityOAuthAdminException | IdentityOAuth2ScopeException e) {
throw handleError(INTERNAL_SERVER_ERROR, Constants.ErrorMessages.ERROR_CODE_REVOKE_APP_BY_USER, user.toFullQualifiedUsername());
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.identity.oauth.dto.OAuthRevocationResponseDTO in project identity-api-user by wso2.
the class AuthorizedAppsService method deleteUserAuthorizedApps.
/**
* Delete the authorized application for the user by the given application id.
*
* @param user User.
* @param applicationId Application Id.
*/
public void deleteUserAuthorizedApps(User user, String applicationId) {
String applicationName = getApplicationName(user, applicationId);
OAuthRevocationRequestDTO oAuthRevocationRequestDTO = new OAuthRevocationRequestDTO();
oAuthRevocationRequestDTO.setApps(new String[] { applicationName });
try {
startTenantFlowWithUser(getUsernameWithUserStoreDomain(user), user.getTenantDomain());
OAuthConsumerAppDTO[] appsAuthorizedByUser = oAuthAdminService.getAppsAuthorizedByUser();
Optional<OAuthConsumerAppDTO> first = Arrays.stream(appsAuthorizedByUser).filter(oAuthConsumerAppDTO -> oAuthConsumerAppDTO.getApplicationName().equals(applicationName)).findFirst();
String userId = getUserIdFromUser(user);
oAuth2ScopeService.revokeUserConsentForApplication(userId, applicationId, IdentityTenantUtil.getTenantId(user.getTenantDomain()));
if (!first.isPresent()) {
throw handleError(NOT_FOUND, Constants.ErrorMessages.ERROR_CODE_INVALID_APPLICATION_ID, applicationId, user.toFullQualifiedUsername());
}
OAuthRevocationResponseDTO oAuthRevocationResponseDTO = oAuthAdminService.revokeAuthzForAppsByResourceOwner(oAuthRevocationRequestDTO);
if (!oAuthRevocationResponseDTO.isError()) {
// TODO: Handle
log.warn("Given application: " + applicationId + " has been deleted by a PreRevokeListener.");
}
} catch (IdentityOAuthAdminException | IdentityOAuth2ScopeException e) {
throw handleError(INTERNAL_SERVER_ERROR, Constants.ErrorMessages.ERROR_CODE_REVOKE_APP_BY_ID_BY_USER, applicationId, user.toFullQualifiedUsername());
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.identity.oauth.dto.OAuthRevocationResponseDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ServiceTest method testIdentityExceptionForRevokeTokenByOAuthClient.
@Test
public void testIdentityExceptionForRevokeTokenByOAuthClient() throws Exception {
setUpRevokeToken();
mockStatic(IdentityTenantUtil.class);
when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(-1234);
AccessTokenDO accessTokenDO = getAccessToken();
TokenBinding tokenBinding = new TokenBinding();
tokenBinding.setBindingReference("dummyReference");
accessTokenDO.setTokenBinding(tokenBinding);
when(OAuth2Util.findAccessToken(anyString(), anyBoolean())).thenThrow(IdentityException.class);
OAuthRevocationRequestDTO revokeRequestDTO = getOAuthRevocationRequestDTO();
OAuthRevocationResponseDTO oAuthRevocationResponseDTO = oAuth2Service.revokeTokenByOAuthClient(revokeRequestDTO);
assertEquals(oAuthRevocationResponseDTO.getErrorMsg(), "Error occurred while revoking authorization grant for applications");
}
Aggregations