Search in sources :

Example 1 with ScopeSettingsDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeSettingsDTO in project carbon-apimgt by wso2.

the class SystemScopesApiServiceImpl method systemScopesScopeNameGet.

public Response systemScopesScopeNameGet(String scope, String username, MessageContext messageContext) throws APIManagementException {
    ScopeSettingsDTO scopeSettingsDTO = new ScopeSettingsDTO();
    APIAdmin apiAdmin = new APIAdminImpl();
    String decodedScope = new String(Base64.getDecoder().decode(scope));
    boolean existence;
    if (username == null) {
        existence = apiAdmin.isScopeExists(RestApiCommonUtil.getLoggedInUsername(), decodedScope);
        if (existence) {
            scopeSettingsDTO.setName(decodedScope);
        } else {
            throw new APIManagementException("Scope Not Found. Scope : " + decodedScope, ExceptionCodes.SCOPE_NOT_FOUND);
        }
    } else {
        existence = apiAdmin.isScopeExistsForUser(username, decodedScope);
        if (existence) {
            scopeSettingsDTO.setName(decodedScope);
        } else {
            throw new APIManagementException("User does not have scope. Username : " + username + " Scope : " + decodedScope, ExceptionCodes.SCOPE_NOT_FOUND_FOR_USER);
        }
    }
    return Response.ok().entity(scopeSettingsDTO).build();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) ScopeSettingsDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeSettingsDTO)

Aggregations

APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)1 ScopeSettingsDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeSettingsDTO)1