Search in sources :

Example 6 with InternalServerErrorException

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;
}
Also used : ApplicationTokenDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationTokenDTO) JSONObject(org.json.simple.JSONObject) ApplicationKeyDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO) HashMap(java.util.HashMap) InternalServerErrorException(org.wso2.carbon.apimgt.rest.api.util.exception.InternalServerErrorException) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with InternalServerErrorException

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);
}
Also used : Error(org.wso2.carbon.identity.api.otp.service.smsotp.dto.Error) InternalServerErrorException(org.wso2.carbon.identity.api.otp.service.smsotp.exception.InternalServerErrorException)

Example 8 with InternalServerErrorException

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);
}
Also used : Error(org.wso2.carbon.identity.api.otp.service.emailotp.dto.Error) InternalServerErrorException(org.wso2.carbon.identity.api.otp.service.emailotp.exception.InternalServerErrorException)

Example 9 with InternalServerErrorException

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);
}
Also used : ErrorDTO(org.wso2.carbon.identity.configuration.mgt.endpoint.dto.ErrorDTO) InternalServerErrorException(org.wso2.carbon.identity.configuration.mgt.endpoint.exception.InternalServerErrorException)

Example 10 with InternalServerErrorException

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;
}
Also used : UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) UserRecoveryDataStore(org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore) InternalServerErrorException(org.wso2.carbon.identity.user.endpoint.exceptions.InternalServerErrorException) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException)

Aggregations

InternalServerErrorException (org.wso2.carbon.apimgt.rest.api.util.exception.InternalServerErrorException)3 InternalServerErrorException (org.wso2.carbon.identity.user.endpoint.exceptions.InternalServerErrorException)3 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)2 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)2 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 UnrecognizedPropertyException (com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException)1 EOFException (java.io.EOFException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 AuthenticationException (org.apache.cxf.interceptor.security.AuthenticationException)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1 ParseException (org.json.simple.parser.ParseException)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1