[Users | Trunk]: finish register service form
This commit is contained in:
parent
5d2cc9c427
commit
0fbe93619f
|
@ -75,7 +75,7 @@ public class RegisterServiceServlet extends HttpServlet {
|
||||||
String[] schemes = {"https"};
|
String[] schemes = {"https"};
|
||||||
UrlValidator urlValidator = new UrlValidator(schemes);
|
UrlValidator urlValidator = new UrlValidator(schemes);
|
||||||
if (!urlValidator.isValid(jwksUri)){
|
if (!urlValidator.isValid(jwksUri)){
|
||||||
request.getSession().setAttribute("msg_key_uri_error_display", "display:block");
|
request.getSession().setAttribute("uri_error", true);
|
||||||
canProceed = false;
|
canProceed = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,11 +86,11 @@ public class RegisterServiceServlet extends HttpServlet {
|
||||||
jwks = gson.fromJson(jwksSet, Jwks.class);
|
jwks = gson.fromJson(jwksSet, Jwks.class);
|
||||||
if (jwks.getKeys() == null || jwks.getKeys().length == 0) {
|
if (jwks.getKeys() == null || jwks.getKeys().length == 0) {
|
||||||
System.out.println("Something wrong with the keys.");
|
System.out.println("Something wrong with the keys.");
|
||||||
request.getSession().setAttribute("msg_key_value_error_display", "display:block");
|
request.getSession().setAttribute("value_error", true);
|
||||||
canProceed = false;
|
canProceed = false;
|
||||||
}
|
}
|
||||||
} catch (JsonParseException jpe) {
|
} catch (JsonParseException jpe) {
|
||||||
request.getSession().setAttribute("msg_key_value_error_display", "display:block");
|
request.getSession().setAttribute("value_error", true);
|
||||||
canProceed = false;
|
canProceed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,23 +56,22 @@
|
||||||
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
|
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
|
||||||
<div class="alert alert-success" aria-hidden="true" style="display: none;"></div>
|
<div class="alert alert-success" aria-hidden="true" style="display: none;"></div>
|
||||||
<div class="alert alert-danger" aria-hidden="true" style="display: none;"></div>
|
<div class="alert alert-danger" aria-hidden="true" style="display: none;"></div>
|
||||||
<span id="server_error" class="uk-text-danger uk-text-small uk-float-left">${message}</span>
|
|
||||||
<c:remove var="message" scope="session"/>
|
|
||||||
<h4 class="uk-text-bold uk-text-center">General</h4>
|
<h4 class="uk-text-bold uk-text-center">General</h4>
|
||||||
<div class="uk-margin-medium-top">
|
<div class="uk-margin-medium-top">
|
||||||
<label class="uk-form-label uk-text-bold" for="first_name">Name*</label>
|
<label class="uk-form-label uk-text-bold" for="first_name">Name*</label>
|
||||||
<input id="first_name" name="first_name" type="text" placeholder="Name (*)"
|
<input id="first_name" name="first_name" type="text" placeholder="Name (*)"
|
||||||
class="form-control" value=${first_name}>
|
class="uk-input" onkeyup="validate()" onfocusout="nameTouched = true;validate()" value=${first_name}>
|
||||||
<span class="uk-text-danger uk-text-small">
|
<c:remove var="first_name" scope="session"/>
|
||||||
Please enter a name for your service.</span>
|
<div id="first_name_error" style="display:none;" class="uk-text-danger uk-text-small">Please enter a name for your
|
||||||
<c:remove var="msg_first_name_error_display" scope="session"/>
|
service.
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-margin-medium-top">
|
<div class="uk-margin-medium-top">
|
||||||
<label class="uk-form-label uk-text-bold" for="description">Description</label>
|
<label class="uk-form-label uk-text-bold" for="description">Description</label>
|
||||||
<textarea id="description" name="description" type="textarea" placeholder="Description:"
|
<textarea id="description" name="description" type="textarea" placeholder="Description:"
|
||||||
class="form-control uk-textarea" rows="3" value=${description}></textarea>
|
class="uk-textarea" rows="3" value=${description}></textarea>
|
||||||
|
<c:remove var="description" scope="session"/>
|
||||||
</div>
|
</div>
|
||||||
<hr class="uk-margin-medium uk-divider">
|
|
||||||
<h4 class="uk-text-bold uk-text-center">Access</h4>
|
<h4 class="uk-text-bold uk-text-center">Access</h4>
|
||||||
<div class="uk-margin-medium-top">
|
<div class="uk-margin-medium-top">
|
||||||
<label class="uk-form-label uk-text-bold">Scope</label>
|
<label class="uk-form-label uk-text-bold">Scope</label>
|
||||||
|
@ -82,7 +81,6 @@
|
||||||
<label class="uk-form-label uk-text-bold">Grant Types</label>
|
<label class="uk-form-label uk-text-bold">Grant Types</label>
|
||||||
<input disabled value="client credentials" class="uk-input">
|
<input disabled value="client credentials" class="uk-input">
|
||||||
</div>
|
</div>
|
||||||
<hr class="uk-margin-medium uk-divider">
|
|
||||||
<h4 class="uk-text-bold uk-text-center">Credentials</h4>
|
<h4 class="uk-text-bold uk-text-center">Credentials</h4>
|
||||||
<div class="uk-margin-medium-top">
|
<div class="uk-margin-medium-top">
|
||||||
<label class="uk-form-label uk-text-bold">Authentication Method</label>
|
<label class="uk-form-label uk-text-bold">Authentication Method</label>
|
||||||
|
@ -97,28 +95,59 @@
|
||||||
<label class="uk-form-label uk-text-bold">Public Key Set</label>
|
<label class="uk-form-label uk-text-bold">Public Key Set</label>
|
||||||
<span class="uk-float-right">
|
<span class="uk-float-right">
|
||||||
<span class="uk-margin-small-right">
|
<span class="uk-margin-small-right">
|
||||||
<input id="by_value" class="uk-radio uk-margin-small-right" type="radio" name="key_radio" value="value" ${(key_radio == 'value' || key_radio == '' || key_radio == null) ? 'checked' : ''}>
|
<input id="by_value" class="uk-radio uk-margin-small-right" type="radio"
|
||||||
|
name="key_radio"
|
||||||
|
value="value" ${(key_radio == 'value' || key_radio == '' || key_radio == null) ? 'checked' : ''}>
|
||||||
<label class="clickable" for="by_value">By Value</label>
|
<label class="clickable" for="by_value">By Value</label>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
<input id="by_uri" class="uk-radio uk-margin-small-right" type="radio" name="key_radio" value="uri" ${key_radio == 'uri' ? 'checked' : ''}>
|
<input id="by_uri" class="uk-radio uk-margin-small-right" type="radio"
|
||||||
|
name="key_radio" value="uri" ${key_radio == 'uri' ? 'checked' : ''}>
|
||||||
<label class="clickable" for="by_uri">By URI</label>
|
<label class="clickable" for="by_uri">By URI</label>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
<c:remove var="key_radio" scope="session"/>
|
||||||
<div id="value_input">
|
<div id="value_input">
|
||||||
<textarea id="value" name="value" type="textarea" placeholder='{"kty": ..., "e": ... , "use": ... , "kid": ..., "alg": ... , "n": ...}'
|
<textarea id="value" name="value" type="textarea"
|
||||||
class="form-control uk-textarea" rows="10">${value}</textarea>
|
placeholder='{"kty": ..., "e": ... , "use": ... , "kid": ..., "alg": ... , "n": ...}'
|
||||||
<span class="uk-text-danger uk-text-small">Please provide a valid JSON.</span>
|
onfocusout="valueTouched = true;validate()"
|
||||||
|
onkeyup="validate()"
|
||||||
|
class="uk-textarea ${value_error == true?'uk-form-danger':''}" rows="10">${value}</textarea>
|
||||||
|
<c:choose>
|
||||||
|
<c:when test="${value_error == true}">
|
||||||
|
<div id="value_error" class="uk-text-danger uk-text-small">Please provide a valid JSON.</div>
|
||||||
|
<c:remove var="value_error" scope="session"/>
|
||||||
|
</c:when>
|
||||||
|
<c:otherwise>
|
||||||
|
<div id="value_error" style="display:none;" class="uk-text-danger uk-text-small">Please provide a valid JSON.</div>
|
||||||
|
</c:otherwise>
|
||||||
|
</c:choose>
|
||||||
|
<c:remove var="value" scope="session"/>
|
||||||
</div>
|
</div>
|
||||||
<div id="uri_input" style="display:none;">
|
<div id="uri_input" style="display:none;">
|
||||||
<input id="uri" name="uri" type="text" placeholder="https://" class="form-control" value="${jwksUri}">
|
<input id="uri" name="uri" type="text" placeholder="https://" onfocusout="uriTouched = true;validate()"
|
||||||
<span class="uk-text-danger uk-text-small">Please provide a valid URI (do not forget the protocol! https://...)</span>
|
onkeyup="validate()"
|
||||||
|
class="uk-input ${uri_error == true?'uk-form-danger':''}" value="${jwksUri}">
|
||||||
|
<c:choose>
|
||||||
|
<c:when test="${uri_error == true}">
|
||||||
|
<div id="uri_error" class="uk-text-danger uk-text-small">
|
||||||
|
Please provide a valid URI (do not forget the protocol! https://...)
|
||||||
|
</div>
|
||||||
|
<c:remove var="uri_error" scope="session"/>
|
||||||
|
</c:when>
|
||||||
|
<c:otherwise>
|
||||||
|
<div id="uri_error" style="display:none;" class="uk-text-danger uk-text-small">
|
||||||
|
Please provide a valid URI (do not forget the protocol! https://...)
|
||||||
|
</div>
|
||||||
|
</c:otherwise>
|
||||||
|
</c:choose>
|
||||||
|
<c:remove var="jwksUri" scope="session"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-flex uk-flex-right uk-margin-medium-top">
|
<div class="uk-flex uk-flex-right uk-margin-medium-top">
|
||||||
<a type="submit" class="uk-button uk-button-default uk-margin-small-right"
|
<a type="submit" class="uk-button uk-button-default uk-margin-small-right"
|
||||||
href="./registeredServices">Cancel</a>
|
href="./registeredServices">Cancel</a>
|
||||||
<button type="submit" class="uk-button uk-button-primary" onclick="return validate();">
|
<button id="create" type="submit" class="uk-button uk-button-primary">
|
||||||
Add new service
|
Add new service
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -164,81 +193,100 @@
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<script>
|
<script>
|
||||||
$('input[type=radio][name=key_radio]').change(function () {
|
var nameTouched = false;
|
||||||
if (this.value == 'uri') {
|
var valueTouched = false;
|
||||||
|
var uriTouched = false;
|
||||||
|
$(document).ready(function () {
|
||||||
|
checkRadio();
|
||||||
|
if($('#value_error').is(':visible')) {
|
||||||
|
$("#value_input").get(0).scrollIntoView();
|
||||||
|
} else if($('#uri_error').is(':visible')) {
|
||||||
|
$("#uri_input").get(0).scrollIntoView();
|
||||||
|
}
|
||||||
|
$('input[type=radio][name=key_radio]').change(function () {
|
||||||
|
checkRadio();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function checkRadio() {
|
||||||
|
var radio = $('input[type=radio][name=key_radio]:checked').val();
|
||||||
|
if (radio === 'uri') {
|
||||||
$("#uri_input").show();
|
$("#uri_input").show();
|
||||||
$("#value_input").hide();
|
$("#value_input").hide();
|
||||||
|
} else if (radio === 'value') {
|
||||||
} else if (this.value == 'value') {
|
|
||||||
$("#uri_input").hide();
|
$("#uri_input").hide();
|
||||||
$("#value_input").show();
|
$("#value_input").show();
|
||||||
}
|
}
|
||||||
});
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
function validate() {
|
function validate() {
|
||||||
var isValid = false;
|
var isValid = true;
|
||||||
if ($("#first_name").val() != undefined) {
|
var create = $('#create');
|
||||||
if ($.trim($("#first_name").val()).length <= 0) {
|
create.prop('disabled', true);
|
||||||
$("#first_name").addClass('uk-input aai-form-danger');
|
var name = $("#first_name");
|
||||||
$(".msg_first_name_error").show();
|
if (name.val() !== undefined) {
|
||||||
return false;
|
if ($.trim(name.val()).length <= 0) {
|
||||||
|
if (nameTouched) {
|
||||||
|
name.addClass('uk-form-danger');
|
||||||
|
$("#first_name_error").show();
|
||||||
|
}
|
||||||
|
isValid = false;
|
||||||
} else {
|
} else {
|
||||||
$(".msg_first_name_error").hide();
|
if (nameTouched) {
|
||||||
$("#first_name").removeClass('aai-form-danger');
|
name.removeClass('uk-form-danger');
|
||||||
|
$("#first_name_error").hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var radio = $('input[type=radio][name=key_radio]:checked');
|
||||||
if ($('input[type=radio][name=key_radio]:checked').val() === 'value') {
|
if (radio.val() === 'value') {
|
||||||
isValid = validateJSON();
|
if (!validateJSON()) {
|
||||||
if (!isValid) {
|
if (valueTouched) {
|
||||||
$("#value_input").addClass('uk-input aai-form-danger');
|
$("#value").addClass('uk-form-danger');
|
||||||
$(".msg_key_value_error_display").show();
|
$("#value_error").show();
|
||||||
return false;
|
}
|
||||||
|
isValid = false;
|
||||||
|
} else {
|
||||||
|
if (valueTouched) {
|
||||||
|
$("#value").removeClass('uk-form-danger');
|
||||||
|
$("#value_error").hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (radio.val() === 'uri') {
|
||||||
if ($('input[type=radio][name=key_radio]:checked').val() === 'uri') {
|
if (!validateURI()) {
|
||||||
isValid = validateURI();
|
if (uriTouched) {
|
||||||
if (!isValid) {
|
$("#uri").addClass('uk-form-danger');
|
||||||
$("#uri_input").addClass('uk-input aai-form-danger');
|
$("#uri_error").show();
|
||||||
$(".msg_key_uri_error_display").show();
|
}
|
||||||
return false;
|
isValid = false;
|
||||||
|
} else {
|
||||||
|
if (uriTouched) {
|
||||||
|
$("#uri").removeClass('uk-form-danger');
|
||||||
|
$("#uri_error").hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isValid) {
|
||||||
|
create.prop('disabled', false);
|
||||||
|
}
|
||||||
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateJSON() {
|
function validateJSON() {
|
||||||
if ($("#value").val() != undefined && $("#value").val() !== "") {
|
var value = $("#value").val();
|
||||||
if (/^[\],:{}\s]*$/.test($("#value").val().replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
if (value !== undefined && value !== "") {
|
||||||
return true;
|
return /^[\],:{}\s]*$/.test(value.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''));
|
||||||
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateURI() {
|
function validateURI() {
|
||||||
if ($("#uri").val() != undefined && $("#uri").val() !== "") {
|
var value = $("#uri").val();
|
||||||
return /^(?:(?:(?:https):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test($("#uri").val());
|
if (value !== undefined && value !== "") {
|
||||||
|
return /^(?:(?:(?:https):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#first_name").focusin(function () {
|
|
||||||
$(this).removeClass('aai-form-danger');
|
|
||||||
$(".msg_first_name_error").fadeOut();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#value_input").focusin(function () {
|
|
||||||
$(this).removeClass('aai-form-danger');
|
|
||||||
$(".msg_key_value_error").fadeOut();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#uri_input").focusin(function () {
|
|
||||||
$(this).removeClass('aai-form-danger');
|
|
||||||
$(".msg_key_uri_error").fadeOut();
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue