use of org.wso2.carbon.identity.user.endpoint.exceptions.InternalServerErrorException in project carbon-apimgt by wso2.
the class ApplicationKeyMappingUtil method fromApplicationKeyToDTO.
/**
* Insert the application related details to a DTO Object
*
* @param keyDetails Application related details map
* @param applicationKeyType Key type of the application
* @return DTO object with application related details
*/
@SuppressWarnings("unchecked")
public static ApplicationKeyDTO fromApplicationKeyToDTO(Map<String, Object> keyDetails, String applicationKeyType) {
ApplicationKeyDTO applicationKeyDTO = new ApplicationKeyDTO();
applicationKeyDTO.setConsumerKey((String) keyDetails.get(APIConstants.FrontEndParameterNames.CONSUMER_KEY));
applicationKeyDTO.setKeyMappingId((String) keyDetails.get(APIConstants.FrontEndParameterNames.KEY_MAPPING_ID));
applicationKeyDTO.setConsumerSecret((String) keyDetails.get(APIConstants.FrontEndParameterNames.CONSUMER_SECRET));
applicationKeyDTO.setKeyState((String) keyDetails.get(APIConstants.FrontEndParameterNames.KEY_STATE));
applicationKeyDTO.setKeyType(ApplicationKeyDTO.KeyTypeEnum.valueOf(applicationKeyType));
Object mode = keyDetails.get(APIConstants.FrontEndParameterNames.MODE);
if (mode != null) {
applicationKeyDTO.setMode(ApplicationKeyDTO.ModeEnum.valueOf((String) mode));
}
try {
String appDetailsString = (String) keyDetails.get(ApplicationConstants.OAUTH_APP_DETAILS);
if (appDetailsString != null) {
JSONObject appDetailsJsonObj = (JSONObject) new JSONParser().parse(appDetailsString);
if (appDetailsJsonObj != null) {
String supportedGrantTypes = (String) appDetailsJsonObj.get(ApplicationConstants.OAUTH_CLIENT_GRANT);
if (supportedGrantTypes != null) {
applicationKeyDTO.setSupportedGrantTypes(Arrays.asList(supportedGrantTypes.split(" ")));
}
String callbackUrl = (String) appDetailsJsonObj.get(ApplicationConstants.OAUTH_REDIRECT_URIS);
applicationKeyDTO.setCallbackUrl(callbackUrl);
Object additionalPropertiesObj = appDetailsJsonObj.get(APIConstants.JSON_ADDITIONAL_PROPERTIES);
if (additionalPropertiesObj != null) {
if (additionalPropertiesObj instanceof JSONObject) {
Map additionalPropertiesMap = new HashMap();
additionalPropertiesMap.putAll((Map) additionalPropertiesObj);
applicationKeyDTO.setAdditionalProperties(additionalPropertiesMap);
} else if (additionalPropertiesObj instanceof String) {
applicationKeyDTO.setAdditionalProperties(additionalPropertiesObj);
}
}
}
}
ApplicationTokenDTO tokenDTO = new ApplicationTokenDTO();
tokenDTO.setValidityTime((Long) keyDetails.get(APIConstants.AccessTokenConstants.VALIDITY_TIME));
tokenDTO.setAccessToken((String) keyDetails.get(APIConstants.AccessTokenConstants.ACCESS_TOKEN));
String[] tokenScopes = (String[]) keyDetails.get(APIConstants.AccessTokenConstants.TOKEN_SCOPES);
if (tokenScopes != null) {
tokenDTO.setTokenScopes(Arrays.asList(tokenScopes));
}
applicationKeyDTO.setToken(tokenDTO);
} catch (ParseException e) {
String errorMsg = "Error while parsing application details string";
log.error(errorMsg, e);
throw new InternalServerErrorException(errorMsg, e);
}
return applicationKeyDTO;
}
use of org.wso2.carbon.identity.user.endpoint.exceptions.InternalServerErrorException in project identity-otp-integration-endpoints by wso2-extensions.
the class EndpointUtils method buildInternalServerErrorException.
public static InternalServerErrorException buildInternalServerErrorException(String code, Log log, Throwable e) {
Error errorDTO = getError(Response.Status.INTERNAL_SERVER_ERROR.toString(), Response.Status.INTERNAL_SERVER_ERROR.toString(), code);
logError(log, e);
return new InternalServerErrorException(errorDTO);
}
use of org.wso2.carbon.identity.user.endpoint.exceptions.InternalServerErrorException in project identity-otp-integration-endpoints by wso2-extensions.
the class EndpointUtils method buildInternalServerErrorException.
public static InternalServerErrorException buildInternalServerErrorException(String code, Log log, Throwable e) {
Error errorDTO = getError(Response.Status.INTERNAL_SERVER_ERROR.toString(), Response.Status.INTERNAL_SERVER_ERROR.toString(), code);
logError(log, e);
return new InternalServerErrorException(errorDTO);
}
use of org.wso2.carbon.identity.user.endpoint.exceptions.InternalServerErrorException in project carbon-identity-framework by wso2.
the class ConfigurationEndpointUtils method buildInternalServerErrorException.
/**
* This method is used to create an InternalServerErrorException with the known errorCode.
*
* @param code Error Code.
* @return a new InternalServerErrorException with default details.
*/
public static InternalServerErrorException buildInternalServerErrorException(String code, Log log, Throwable e) {
ErrorDTO errorDTO = getErrorDTO(ConfigurationConstants.STATUS_INTERNAL_SERVER_ERROR_MESSAGE_DEFAULT, ConfigurationConstants.STATUS_INTERNAL_SERVER_ERROR_MESSAGE_DEFAULT, code);
logError(log, e);
return new InternalServerErrorException(errorDTO);
}
use of org.wso2.carbon.identity.user.endpoint.exceptions.InternalServerErrorException in project identity-governance by wso2-extensions.
the class Utils method getUserRecoveryData.
/**
* Gets user recovery data for a specific user by recovery scenario.
*
* @param resendCodeRequestDTO ResendCodeRequestDTO.
* @param recoveryScenario Recovery Scenario.
* @return User Recovery Data.
*/
public static UserRecoveryData getUserRecoveryData(ResendCodeRequestDTO resendCodeRequestDTO, String recoveryScenario) {
UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
UserRecoveryData userRecoveryData = null;
try {
userRecoveryData = userRecoveryDataStore.loadWithoutCodeExpiryValidation(Utils.getUser(resendCodeRequestDTO.getUser()), RecoveryScenarios.getRecoveryScenario(recoveryScenario));
} catch (IdentityRecoveryException e) {
throw new InternalServerErrorException("Error in loading user recovery data for " + Utils.getUser(resendCodeRequestDTO.getUser()) + " for scenario " + recoveryScenario, e);
}
return userRecoveryData;
}
Aggregations