Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
feat(security): Add multiple security implementations and manage secu…
Browse files Browse the repository at this point in the history
…rity by plan

Closes gravitee-io/issues#379
  • Loading branch information
brasseld committed Jan 9, 2017
1 parent ccfc368 commit 79304cb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/app/api/admin/plans/apiPlans.controller.js
Expand Up @@ -27,6 +27,14 @@ class ApiPlansController {
this.dndEnabled = true;
this.statusFilters = ['staging', 'published', 'closed'];
this.selectedStatus = ['published'];
this.securityTypes = [
{
'id': 'api_key',
'name': 'API Key'
}, {
'id': 'key_less',
'name': 'Keyless (public)'
}];

$scope.planEdit = true;

Expand Down
17 changes: 14 additions & 3 deletions src/app/api/admin/plans/apiPlans.html
Expand Up @@ -87,7 +87,7 @@ <h4 ng-class="{italic: plan.status === 'staging', strike: plan.status === 'close
</md-card-header>
<md-divider></md-divider>
<md-card-content layout="column">
<h4 class="gravitee-plan-content">{{plan.description}}</h4>
<h4 class="gravitee-plan-content">{{plan.description}} ({{plan.security}})</h4>
<md-divider></md-divider>
<div ng-repeat="characteristic in plan.characteristics">
<h5 class="gravitee-plan-content">{{characteristic}}</h5>
Expand All @@ -97,10 +97,14 @@ <h5 class="gravitee-plan-content">{{characteristic}}</h5>
<md-divider ng-if="graviteeUser || plan.isPublic"></md-divider>
<md-card-footer ng-if="graviteeUser || plan.isPublic">
<div layout="row" layout-align="end">
<md-button class="md-primary md-raised" aria-label="Execute"
<md-button ng-if="plan.security === 'api_key' || plan.security === undefined" class="md-primary md-raised" aria-label="Execute"
ng-click="subscribe(plan)" ng-disabled="plan.status || planEdit">
{{plan.alreadySubscribed ? 'Subscribed' : (plan.validation === 'auto'?'Subscribe': 'Request for subscription')}}
</md-button>
<md-button ng-if="plan.security === 'key_less'" class="md-primary md-raised" aria-label="Execute"
ng-click="subscribe(plan)" ng-disabled="plan.status || planEdit">
No subscription required
</md-button>
</div>
</md-card-footer>
</md-card>
Expand Down Expand Up @@ -150,6 +154,13 @@ <h2>
<label>Description</label>
<input type="text" ng-model="plan.description" required>
</md-input-container>
<md-input-container class="md-block">
<label>Security Type</label>
<md-select ng-model="plan.security" placeholder="Security type" required ng-required="true"
ng-disabled="plan.id">
<md-option ng-repeat="type in apiPlansCtrl.securityTypes" ng-value="type.id">{{type.name}}</md-option>
</md-select>
</md-input-container>
<md-input-container class="md-block">
<label>Characteristics</label>
<md-chips ng-model="plan.characteristics" placeholder="Enter a characteristic"
Expand All @@ -160,7 +171,7 @@ <h2>
<md-input-container class="md-block" flex="33">
<label>Auto validation</label>
<md-switch aria-label="Auto validation"
ng-model="plan.validation" ng-true-value="'auto'" ng-false-value="'manual'"></md-switch>
ng-model="plan.validation" ng-true-value="'auto'" ng-disabled="plan.security == 'key_less'" ng-false-value="'manual'"></md-switch>
</md-input-container>
</div>

Expand Down
7 changes: 5 additions & 2 deletions src/app/api/admin/plans/closePlan.dialog.html
Expand Up @@ -26,22 +26,25 @@ <h2>Close plan</h2>
</div>
</md-toolbar>
<md-dialog-content>
<div class="md-dialog-content">
<div ng-if="plan.security == 'api_key'" class="md-dialog-content">
<h5 ng-if="subscriptions == 0">No subscription is associated to this plan. You can delete it safely.</h5>
<h5 ng-if="subscriptions > 0">There are <code>{{subscriptions}}</code> active subscriptions associated to this plan.</h5>
<p ng-if="subscriptions > 0">
By closing this plan, all relative subscriptions will also be closed and associated api-keys will be no longer
available.
</p>
</div>
<div ng-if="plan.security == 'key_less'" class="md-dialog-content">
<h5>Are you sure to close the plan {{plan.name}}?</h5>
</div>
</md-dialog-content>

<md-dialog-actions layout="row">
<md-button type="button" ng-click="hide()" class="md-primary" md-autofocus>
Cancel
</md-button>
<md-button type="submit" class="md-primary" ng-click="close()">
{{subscriptions == 0 ? 'Delete' : 'Close'}}
{{subscriptions == 0 && plan.security == 'api_key' ? 'Delete' : 'Close'}}
</md-button>
</md-dialog-actions>
</md-dialog>
2 changes: 1 addition & 1 deletion src/app/api/admin/plans/closePlanDialog.controller.js
Expand Up @@ -25,7 +25,7 @@ function DialogClosePlanController($scope, $mdDialog, ApiService, NotificationSe
};

$scope.close = function () {
if ($scope.subscriptions === 0) {
if ($scope.plan.security === 'api_key' && $scope.subscriptions === 0) {
ApiService.deletePlan($scope.apiId, $scope.plan.id).then(function() {
NotificationService.show('Plan ' + plan.name + ' has been deleted');
}).catch(function (error) {
Expand Down
1 change: 0 additions & 1 deletion src/app/api/admin/plans/publishPlanDialog.controller.js
Expand Up @@ -27,7 +27,6 @@ function DialogPublishPlanController($scope, $mdDialog, ApiService, Notification
ApiService.publishPlan($scope.apiId, $scope.plan.id).then(function() {
NotificationService.show('Plan ' + plan.name + ' has been published');
}).catch(function (error) {
NotificationService.show('Error while publishing plan ' + plan.name);
$scope.error = error;
});

Expand Down
8 changes: 6 additions & 2 deletions src/app/api/portal/plan/apiPlan.html
Expand Up @@ -21,7 +21,7 @@ <h3 layout-padding>{{plan.name}}</h3>
</md-card-header>
<md-divider></md-divider>
<md-card-content layout="column">
<h4 class="gravitee-plan-content">{{plan.description}}</h4>
<h4 class="gravitee-plan-content">{{plan.description}} ({{plan.security}})</h4>
<md-divider></md-divider>
<div ng-repeat="characteristic in plan.characteristics">
<h5 class="gravitee-plan-content">{{characteristic}}</h5>
Expand All @@ -31,10 +31,14 @@ <h5 class="gravitee-plan-content">{{characteristic}}</h5>
<md-divider ng-if="graviteeUser || plan.isPublic"></md-divider>
<md-card-footer ng-if="graviteeUser || plan.isPublic">
<div layout="row" layout-align="end">
<md-button class="md-primary md-raised" aria-label="Execute"
<md-button ng-if="plan.security === 'api_key' || plan.security === undefined" class="md-primary md-raised" aria-label="Execute"
ng-click="subscribe(plan)" ng-disabled="planEdit">
{{plan.alreadySubscribed ? 'Subscribed' : (plan.validation === 'auto'?'Subscribe': 'Request for subscription')}}
</md-button>
<md-button ng-if="plan.security === 'key_less'" class="md-primary md-raised" aria-label="Execute"
ng-click="subscribe(plan)" ng-disabled="true">
No subscription required
</md-button>
</div>
</md-card-footer>
</md-card>
3 changes: 2 additions & 1 deletion src/app/services/api.service.js
Expand Up @@ -192,7 +192,8 @@ class ApiService {
{
name: plan.name, description: plan.description, api: plan.api,
validation: plan.validation, policies: plan.policies,
characteristics: plan.characteristics, type: plan.type, paths: plan.paths
characteristics: plan.characteristics, type: plan.type, paths: plan.paths,
security: plan.security
});
}
}
Expand Down

0 comments on commit 79304cb

Please sign in to comment.