Skip to content

Commit cf70a20

Browse files
committed
advanced claim addition function
1 parent cebf0fb commit cf70a20

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

uma-server-webapp/src/main/webapp/resources/js/locale/en/uma.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838
"share-email": "Share with email address",
3939
"new": "New Policy",
4040
"edit": "Edit Policy"
41+
4142
},
4243
"webfinger-error": "Error",
43-
"webfinger-error-description": "The server was unable to find an identity provider for <code>__email__</code>."
44+
"webfinger-error-description": "The server was unable to find an identity provider for <code>__email__</code>.",
45+
"advanced-error": "Error",
46+
"advanced-error-description": "There was an error saving your advanced claim. Did you fill in all required fields?"
4447
},
4548
"sidebar": {
4649
"personal": {

uma-server-webapp/src/main/webapp/resources/js/policy.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,84 @@ var PolicyFormView = Backbone.View.extend({
486486
});
487487
});
488488

489+
},
490+
491+
addAdvancedClaim:function(e) {
492+
e.preventDefault();
493+
494+
var name = $('#name', this.el).val();
495+
var friendly = $('#friendly-name', this.el).val();
496+
var rawValue = $('#value', this.el).val();
497+
var valueType = $('#value-type', this.el).val();
498+
var value = null;
499+
if (valueType == 'number') {
500+
value = Number(rawValue);
501+
} else if (valueType == 'boolean') {
502+
value = (rawValue.toLowerCase() == 'true');
503+
} else if (valueType == 'json') {
504+
value = JSON.parse(rawValue);
505+
} else {
506+
// treat it as a string, the default
507+
value = rawValue;
508+
}
509+
510+
var issuers = this.issuerCollection.pluck('item');
511+
512+
console.log(name, friendly, rawValue, valueType, value, issuers);
513+
514+
if (!_.isEmpty(issuers)
515+
&& name
516+
&& value) {
517+
// we've got a valid claim, add it to our set
518+
// grab the current state of the scopes checkboxes just in case
519+
var scopes = $('#scopes input[type="checkbox"]:checked').map(function(idx, elem) { return $(elem).val(); }).get();
520+
521+
var claimsRequired = this.model.get('claimsRequired');
522+
if (!claimsRequired) {
523+
claimsRequired = [];
524+
}
525+
console.log(claimsRequired);
526+
claimsRequired.push({
527+
name: name,
528+
friendlyName: friendly,
529+
value: value,
530+
issuer: issuers
531+
});
532+
console.log(claimsRequired);
533+
534+
this.model.set({
535+
scopes: scopes,
536+
claimsRequired: claimsRequired
537+
}, {trigger: false});
538+
539+
$('#name', this.el).val('');
540+
$('#friendly-name', this.el).val('');
541+
$('#value', this.el).val('');
542+
$('#value-type', this.el).val('text');
543+
544+
this.render();
545+
546+
// re-select the advanced tab
547+
$('a[data-target="#policy-advanced-tab"]', this.el).tab('show')
548+
549+
} else {
550+
// something is missing
551+
$('#loadingbox').sheet('hide');
552+
553+
//Display an alert with an error message
554+
$('#modalAlert div.modal-header').html($.t('policy.advanced-error'));
555+
$('#modalAlert div.modal-body').html($.t('policy.advanced-error-description'));
556+
557+
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
558+
"backdrop" : "static",
559+
"keyboard" : true,
560+
"show" : true // ensure the modal is shown immediately
561+
});
562+
}
563+
564+
565+
566+
489567
},
490568

491569
savePolicy:function(e) {

uma-server-webapp/src/main/webapp/resources/template/policy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ <h1 data-i18n="policy.policy-form.edit">Edit Policy</h1>
186186
<div class="controls">
187187
<input type="text" id="value" placeholder="claim value" data-i18n="[placeholder]policy.policy-form.claim-value" />
188188
<select id="value-type">
189-
<option value="text" data-i18n="policy.policy-form.value-type-text">Text</option>
189+
<option value="text" selected="selected" data-i18n="policy.policy-form.value-type-text">Text</option>
190190
<option value="number" data-i18n="policy.policy-form.value-type-number">Number</option>
191191
<option value="boolean" data-i18n="policy.policy-form.value-type-boolean">Boolean</option>
192192
<option value="json" data-i18n="policy.policy-form.value-type-json">JSON</option>

0 commit comments

Comments
 (0)