Search in sources :

Example 1 with OAuthAdminService

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);
}
Also used : OAuthAdminService(org.wso2.carbon.identity.oauth.OAuthAdminService)

Example 2 with OAuthAdminService

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;
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) HashMap(java.util.HashMap) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) OAuthAdminService(org.wso2.carbon.identity.oauth.OAuthAdminService) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)

Example 3 with OAuthAdminService

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;
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) OAuthAdminService(org.wso2.carbon.identity.oauth.OAuthAdminService) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)

Aggregations

OAuthAdminService (org.wso2.carbon.identity.oauth.OAuthAdminService)3 IdentityOAuthAdminException (org.wso2.carbon.identity.oauth.IdentityOAuthAdminException)2 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)2 HashMap (java.util.HashMap)1 OAuthApplicationInfo (org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo)1