use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdMapKeysPost.
/**
* Generate keys using existing consumer key and consumer secret
*
* @param applicationId Application id
* @param body Contains consumer key, secret and key type information
* @return A response object containing application keys
*/
@Override
public Response applicationsApplicationIdMapKeysPost(String applicationId, ApplicationKeyMappingRequestDTO body, String xWSO2Tenant, MessageContext messageContext) throws APIManagementException {
String username = RestApiCommonUtil.getLoggedInUsername();
JSONObject jsonParamObj = new JSONObject();
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
Application application = apiConsumer.getApplicationByUUID(applicationId);
String keyManagerName = APIConstants.KeyManager.DEFAULT_KEY_MANAGER;
if (StringUtils.isNotEmpty(body.getKeyManager())) {
keyManagerName = body.getKeyManager();
}
if (application != null) {
if (RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
String clientId = body.getConsumerKey();
String keyType = body.getKeyType().toString();
String tokenType = APIConstants.DEFAULT_TOKEN_TYPE;
jsonParamObj.put(APIConstants.SUBSCRIPTION_KEY_TYPE, body.getKeyType().toString());
jsonParamObj.put(APIConstants.JSON_CLIENT_SECRET, body.getConsumerSecret());
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Map<String, Object> keyDetails = apiConsumer.mapExistingOAuthClient(jsonParamObj.toJSONString(), username, clientId, application.getName(), keyType, tokenType, keyManagerName, organization);
ApplicationKeyDTO applicationKeyDTO = ApplicationKeyMappingUtil.fromApplicationKeyToDTO(keyDetails, body.getKeyType().toString());
applicationKeyDTO.setKeyManager(keyManagerName);
return Response.ok().entity(applicationKeyDTO).build();
} else {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
}
} else {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdOauthKeysGet.
@Override
public Response applicationsApplicationIdOauthKeysGet(String applicationId, String xWso2Tenant, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Set<APIKey> applicationKeys = getApplicationKeys(applicationId, organization);
List<ApplicationKeyDTO> keyDTOList = new ArrayList<>();
ApplicationKeyListDTO applicationKeyListDTO = new ApplicationKeyListDTO();
applicationKeyListDTO.setCount(0);
if (applicationKeys != null) {
for (APIKey apiKey : applicationKeys) {
ApplicationKeyDTO appKeyDTO = ApplicationKeyMappingUtil.fromApplicationKeyToDTO(apiKey);
keyDTOList.add(appKeyDTO);
}
applicationKeyListDTO.setList(keyDTOList);
applicationKeyListDTO.setCount(keyDTOList.size());
}
return Response.ok().entity(applicationKeyListDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationtoDTO.
public static ApplicationDTO fromApplicationtoDTO(Application application) throws APIManagementException {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(application.getUUID());
applicationDTO.setThrottlingPolicy(application.getTier());
applicationDTO.setDescription(application.getDescription());
Map<String, String> applicationAttributes = application.getApplicationAttributes();
applicationDTO.setAttributes(applicationAttributes);
applicationDTO.setName(application.getName());
applicationDTO.setStatus(application.getStatus());
applicationDTO.setOwner(application.getOwner());
if (StringUtils.isNotEmpty(application.getGroupId())) {
applicationDTO.setGroups(Arrays.asList(application.getGroupId().split(",")));
}
applicationDTO.setTokenType(ApplicationDTO.TokenTypeEnum.OAUTH);
applicationDTO.setSubscriptionCount(application.getSubscriptionCount());
if (StringUtils.isNotEmpty(application.getTokenType()) && !APIConstants.DEFAULT_TOKEN_TYPE.equals(application.getTokenType())) {
applicationDTO.setTokenType(ApplicationDTO.TokenTypeEnum.valueOf(application.getTokenType()));
}
/*List<ApplicationKeyDTO> applicationKeyDTOs = new ArrayList<>();
for(APIKey apiKey : application.getKeys()) {
ApplicationKeyDTO applicationKeyDTO = ApplicationKeyMappingUtil.fromApplicationKeyToDTO(apiKey);
applicationKeyDTOs.add(applicationKeyDTO);
}
applicationDTO.setKeys(applicationKeyDTOs);*/
return applicationDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO in project carbon-apimgt by wso2.
the class ImportUtils method getAPIKeyFromApplicationKeyDTO.
/**
* This extracts information for creating an APIKey from an OAuthApplication
*
* @param applicationKeyDto Application Key DTO
* @return An APIKey containing keys from OAuthApplication
*/
public static APIKey getAPIKeyFromApplicationKeyDTO(ApplicationKeyDTO applicationKeyDto) {
APIKey apiKey = new APIKey();
apiKey.setType(String.valueOf(applicationKeyDto.getKeyType()));
apiKey.setConsumerKey(applicationKeyDto.getConsumerKey());
apiKey.setConsumerSecret(new String(Base64.decodeBase64(applicationKeyDto.getConsumerSecret())));
apiKey.setKeyManager(applicationKeyDto.getKeyManager());
apiKey.setGrantTypes(StringUtils.join(applicationKeyDto.getSupportedGrantTypes(), ", "));
if (apiKey.getGrantTypes() != null && (apiKey.getGrantTypes().contains(GRANT_TYPE_IMPLICIT) || apiKey.getGrantTypes().contains(GRANT_TYPE_CODE))) {
apiKey.setCallbackUrl(applicationKeyDto.getCallbackUrl());
}
apiKey.setValidityPeriod(applicationKeyDto.getToken().getValidityTime());
apiKey.setTokenScope(DEFAULT_TOKEN_SCOPE);
return apiKey;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO in project carbon-apimgt by wso2.
the class ApplicationKeyMappingUtil method fromApplicationKeyToDTO.
/**
* Insert the application related details to a DTO Object using api key
*
* @param apiKey Object that contains details needed during token request
* @return DTO object with application related details
*/
public static ApplicationKeyDTO fromApplicationKeyToDTO(APIKey apiKey) {
ApplicationKeyDTO applicationKeyDTO = new ApplicationKeyDTO();
applicationKeyDTO.setKeyType(ApplicationKeyDTO.KeyTypeEnum.valueOf(apiKey.getType()));
applicationKeyDTO.setConsumerKey(apiKey.getConsumerKey());
applicationKeyDTO.setConsumerSecret(apiKey.getConsumerSecret());
applicationKeyDTO.setKeyState(apiKey.getState());
applicationKeyDTO.setMode(ApplicationKeyDTO.ModeEnum.valueOf(apiKey.getCreateMode()));
applicationKeyDTO.setKeyManager(apiKey.getKeyManager());
applicationKeyDTO.setKeyMappingId(apiKey.getMappingId());
if (apiKey.getGrantTypes() != null) {
applicationKeyDTO.setSupportedGrantTypes(Arrays.asList(apiKey.getGrantTypes().split(" ")));
} else {
applicationKeyDTO.setSupportedGrantTypes(null);
}
applicationKeyDTO.setCallbackUrl(apiKey.getCallbackUrl());
ApplicationTokenDTO tokenDTO = new ApplicationTokenDTO();
if (apiKey.getTokenScope() != null) {
tokenDTO.setTokenScopes(Arrays.asList(apiKey.getTokenScope().split(" ")));
}
tokenDTO.setAccessToken(apiKey.getAccessToken());
tokenDTO.setValidityTime(apiKey.getValidityPeriod());
applicationKeyDTO.setToken(tokenDTO);
applicationKeyDTO.setAdditionalProperties(apiKey.getAdditionalProperties());
return applicationKeyDTO;
}
Aggregations