use of org.wso2.carbon.identity.oauth.OAuthAdminService in project carbon-apimgt by wso2.
the class APIUtil method getGrantTypes.
public static List<String> getGrantTypes() throws APIManagementException {
OAuthAdminService oAuthAdminService = new OAuthAdminService();
String[] allowedGrantTypes = oAuthAdminService.getAllowedGrantTypes();
return Arrays.asList(allowedGrantTypes);
}
use of org.wso2.carbon.identity.oauth.OAuthAdminService in project carbon-apimgt by wso2.
the class RegistrationServiceImpl method getExistingApp.
/**
* Retrieve the existing application of given name
*
* @param applicationName application name
* @param saasApp value of IsSaasApp attribute of application.
* @return existing Application
*/
private OAuthApplicationInfo getExistingApp(String applicationName, boolean saasApp) {
OAuthApplicationInfo appToReturn = null;
OAuthAdminService oAuthAdminService = new OAuthAdminService();
try {
OAuthConsumerAppDTO consumerAppDTO = oAuthAdminService.getOAuthApplicationDataByAppName(applicationName);
Map<String, String> valueMap = new HashMap<String, String>();
valueMap.put(OAUTH_CLIENT_GRANT, consumerAppDTO.getGrantTypes());
appToReturn = this.fromAppDTOToApplicationInfo(consumerAppDTO.getOauthConsumerKey(), consumerAppDTO.getApplicationName(), consumerAppDTO.getCallbackUrl(), consumerAppDTO.getOauthConsumerSecret(), saasApp, null, valueMap);
} catch (IdentityOAuthAdminException e) {
log.error("error occurred while trying to get OAuth Application data", e);
}
return appToReturn;
}
use of org.wso2.carbon.identity.oauth.OAuthAdminService in project carbon-apimgt by wso2.
the class RegistrationServiceImpl method createOAuthApp.
/**
* Method to create a OAuth App with client credentials
*
* @param appName application name
* @param grantTypes grant types
* @param userName username of the application
* @return created Oauth App
*/
private OAuthConsumerAppDTO createOAuthApp(String appName, OAuthApplicationInfo applicationInfo, String grantTypes, String userName) {
OAuthConsumerAppDTO createdApp = null;
OAuthAdminService oauthAdminService = new OAuthAdminService();
OAuthConsumerAppDTO oauthConsumerAppDTO = new OAuthConsumerAppDTO();
oauthConsumerAppDTO.setApplicationName(appName);
if (StringUtils.isNotBlank(applicationInfo.getCallBackURL())) {
oauthConsumerAppDTO.setCallbackUrl(applicationInfo.getCallBackURL());
}
oauthConsumerAppDTO.setUsername(userName);
oauthConsumerAppDTO.setOAuthVersion(OAuthConstants.OAuthVersions.VERSION_2);
oauthConsumerAppDTO.setGrantTypes(grantTypes.trim());
try {
boolean isHashDisabled = OAuth2Util.isHashDisabled();
if (isHashDisabled) {
// Creating the Oauth app
oauthAdminService.registerOAuthApplicationData(oauthConsumerAppDTO);
// Retrieving the created OAuth application
createdApp = oauthAdminService.getOAuthApplicationDataByAppName(oauthConsumerAppDTO.getApplicationName());
} else {
createdApp = oauthAdminService.registerAndRetrieveOAuthApplicationData(oauthConsumerAppDTO);
}
} catch (IdentityOAuthAdminException e) {
log.error("Error occurred while creating the OAuth app", e);
}
if (log.isDebugEnabled()) {
log.debug("Created OAuth App " + appName);
}
return createdApp;
}
Aggregations