Skip to content

Commit d2dac7b

Browse files
authored
Fix auth-behaviour (#91)
* Fix default behavior of authorization in add subscription - Also fixes the Issue with add key/value pair for authorization bug. THe add key/value button is removed, the information is instead send in the body with the keys "userName" and "password". - It's no longer possible to get password information back from the server, therefore the frontend won't display the empty password fields. User will need to click a "change password" button in order to change a password.
1 parent 210ff7e commit d2dac7b

File tree

9 files changed

+68
-57
lines changed

9 files changed

+68
-57
lines changed

src/functionaltest/java/com/ericsson/ei/frontend/TestSubscriptionHandling.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
194194
String authValue = "BASIC_AUTH";
195195
String userName = "ABCD";
196196
String userNameID = "userNameInput";
197-
String token = "EFGH";
198-
String tokenID = "tokenInput";
197+
String password = "password";
198+
String passwordID = "passwordInput";
199199
String subName = "Selenium_test_subscription";
200200
String subNameID = "subscriptionNameInput";
201201
String selectRepeatID = "selectRepeat";
@@ -205,10 +205,10 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
205205

206206
subscriptionPage.selectDropdown(selectAuthID, authValue);
207207
subscriptionPage.addFieldValue(userNameID, userName);
208-
subscriptionPage.addFieldValue(tokenID, token);
209-
String kvID = "kvID";
210-
subscriptionPage.clickKVbtn(kvID);
211-
assert (new WebDriverWait(driver, 10).until((webdriver) -> driver.getPageSource().contains("Authorization")));
208+
subscriptionPage.addFieldValue(passwordID, password);
209+
210+
assert (new WebDriverWait(driver, 10).until((webdriver) -> driver.getPageSource().contains("ABCD")));
211+
assert (new WebDriverWait(driver, 10).until((webdriver) -> driver.getPageSource().contains("password")));
212212

213213
// Test "Repeat" dropdown: Select repeat value as "true" and then verify the selected value
214214
subscriptionPage.selectDropdown(selectRepeatID, repeatValue);

src/functionaltest/resources/responses/SubscriptionForUploadLDAP.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"aggregationtype":"eiffel-intelligence",
44
"created":1524037895385,
5-
"userName" : "ABCD",
5+
"ldapUserName" : "ABCD",
66
"notificationMeta":"http://eiffel-jenkins1:8080/job/ei-artifact-triggered-job/build",
77
"notificationType":"REST_POST",
88
"restPostBodyMediaType":"application/x-www-form-urlencoded",
@@ -31,7 +31,7 @@
3131
{
3232
"aggregationtype":"eiffel-intelligence",
3333
"created":1524037895415,
34-
"userName" : "EFGH",
34+
"ldapUserName" : "EFGH",
3535
"notificationMeta":"http://eiffel-jenkins1:8080/job/ei-artifact-triggered-job/build",
3636
"notificationType":"REST_POST",
3737
"restPostBodyMediaType":"application/x-www-form-urlencoded",
@@ -59,7 +59,7 @@
5959
{
6060
"aggregationtype":"eiffel-intelligence",
6161
"created":1524223397628,
62-
"userName" : "ABCD",
62+
"ldapUserName" : "ABCD",
6363
"notificationMeta":"http://<MyHost:port>/api/doit",
6464
"notificationType":"REST_POST",
6565
"restPostBodyMediaType":"application/json",

src/main/resources/static/css/style.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
height: 45px;
6565
animation: spin 1s cubic-bezier(.86,0,.07,1) infinite;
6666
}
67+
6768
.cursor-pointer {
6869
cursor: pointer;
6970
}
@@ -74,6 +75,11 @@
7475
white-space: nowrap;
7576
border-radius: .25rem;
7677
}
78+
79+
.showPasswordButton{
80+
margin-top: 10px;
81+
}
82+
7783
/* Safari */
7884
@-webkit-keyframes spin {
7985
0% { -webkit-transform: rotate(0deg); }
@@ -96,4 +102,4 @@ body {
96102
body {
97103
padding-top: 80px;
98104
}
99-
}
105+
}

src/main/resources/static/js/login.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ var frontendServiceUrl = $('#frontendServiceUrl').text();
44
// /Start ## Knockout ####################################################
55
function loginModel() {
66
this.userState = {
7-
username: ko.observable(""),
7+
ldapUserName: ko.observable(""),
88
password: ko.observable("")
99
};
1010
this.remember = ko.observable(false);
1111

1212
this.login = function(userState, remember) {
1313
var dataJSON = ko.toJSON(userState);
14-
if(JSON.parse(dataJSON).username == "" || JSON.parse(dataJSON).password == "") {
14+
if(JSON.parse(dataJSON).ldapUserName == "" || JSON.parse(dataJSON).password == "") {
1515
window.logMessages("Username and password fields cannot be empty");
1616
} else {
17-
var token = window.btoa(JSON.parse(dataJSON).username + ":" + JSON.parse(dataJSON).password);
17+
var token = window.btoa(JSON.parse(dataJSON).ldapUserName + ":" + JSON.parse(dataJSON).password);
1818
sendLoginRequest(frontendServiceUrl + "/auth/login", "GET", token);
1919
}
2020
}
@@ -45,7 +45,7 @@ var frontendServiceUrl = $('#frontendServiceUrl').text();
4545
function doIfUserLoggedIn(name) {
4646
localStorage.removeItem("currentUser");
4747
localStorage.setItem("currentUser", name);
48-
$("#userName").text(name);
48+
$("#ldapUserName").text(name);
4949
$("#loginBlock").hide();
5050
$("#logoutBlock").show();
5151
}
@@ -73,4 +73,4 @@ var frontendServiceUrl = $('#frontendServiceUrl').text();
7373
}
7474
// /Stop ## Cookies functions ############################################
7575

76-
});
76+
});

src/main/resources/static/js/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jQuery(document).ready(function() {
8383

8484
function doIfUserLoggedOut() {
8585
localStorage.removeItem("currentUser");
86-
$("#userName").text("Guest");
86+
$("#ldapUserName").text("Guest");
8787
$("#loginBlock").show();
8888
$("#logoutBlock").hide();
8989
localStorage.setItem('errorsStore', []);
@@ -185,4 +185,4 @@ jQuery(document).ready(function() {
185185
$('.tooltip').tooltip('hide');
186186
}
187187
});
188-
});
188+
});

src/main/resources/static/js/subscription.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ jQuery(document).ready(function () {
7575
function doIfUserLoggedIn() {
7676
var currentUser = localStorage.getItem("currentUser");
7777
if (currentUser != "") {
78-
$("#userName").text(currentUser);
78+
$("#ldapUserName").text(currentUser);
7979
$("#logoutBlock").show();
8080
$(".show_if_authorized").show();
8181
}
8282
}
8383
function doIfUserLoggedOut() {
8484
localStorage.removeItem("currentUser");
85-
$("#userName").text("Guest");
85+
$("#ldapUserName").text("Guest");
8686
$("#loginBlock").show();
8787
$("#logoutBlock").hide();
8888
$(".show_if_authorized").hide();
@@ -115,7 +115,7 @@ jQuery(document).ready(function () {
115115
this.aggregationtype = ko.observable(data.aggregationtype);
116116
this.authenticationType = ko.observable(data.authenticationType);
117117
this.userName = ko.observable(data.userName);
118-
this.token = ko.observable(data.token);
118+
this.password = ko.observable(data.password);
119119

120120
this.notificationType.subscribe(function (new_value) {
121121
vm.subscription()[0].restPostBodyMediaType(null);
@@ -158,6 +158,11 @@ jQuery(document).ready(function () {
158158
self.choosen_subscription_template = ko.observable();
159159
self.authenticationType = ko.observable();
160160
self.formpostkeyvaluepairs = ko.observable(false);
161+
self.mode = ko.observable("");
162+
self.showPassword = ko.observable(false);
163+
self.setShowPassword = function (boolean){
164+
self.showPassword(boolean);
165+
}
161166
self.formpostkeyvaluepairsAuth = ko.observable(false);
162167
self.notificationType_in = ko.observableArray(
163168
[
@@ -190,15 +195,6 @@ jQuery(document).ready(function () {
190195
self.subscription()[0].notificationMessageKeyValues.push(new formdata_model(defaultFormKeyValuePair));
191196
};
192197

193-
self.addNotificationMsgKeyValuePairAuth = function (data, event) {
194-
data.notificationMessageKeyValues.push({
195-
"formkey": "Authorization", "formvalue": ko.computed(function () {
196-
return "Basic " + btoa(data.userName() + ":" + data.token());
197-
198-
})
199-
});
200-
};
201-
202198
self.getUTCDate = function (epochtime) {
203199
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
204200
d.setUTCMilliseconds(epochtime);
@@ -321,7 +317,7 @@ jQuery(document).ready(function () {
321317
"targets": [2],
322318
"orderable": true,
323319
"title": "UserName",
324-
"data": "userName",
320+
"data": "ldapUserName",
325321
"defaultContent": ""
326322
},
327323
{
@@ -370,7 +366,8 @@ jQuery(document).ready(function () {
370366
"title": "Action",
371367
"data": null,
372368
"render": function (data, type, row, meta) {
373-
if (isSecured == false || (row.userName == currentUser && row.userName != null)) {
369+
370+
if (isSecured == false || (row.ldapUserName == currentUser && row.ldapUserName != null)) {
374371
return '<button id="view-' + data.subscriptionName + '" class="btn btn-sm btn-success view_record">View</button> '
375372
+ '<button id="edit-' + data.subscriptionName + '" class="btn btn-sm btn-primary edit_record">Edit</button> '
376373
+ '<button id="delete-' + data.subscriptionName + '" class="btn btn-sm btn-danger delete_record">Delete</button>';
@@ -635,6 +632,13 @@ jQuery(document).ready(function () {
635632

636633
// /Start ## populate JSON ###########################################
637634
function populate_json(data, save_method_in) {
635+
vm.mode(save_method_in);
636+
637+
if (save_method_in == "edit" || save_method_in == "view"){
638+
vm.showPassword(false);
639+
} else {
640+
vm.showPassword(true);
641+
}
638642
var returnData = [data];
639643
if (returnData.length > 0) {
640644
vm.subscription([]);
@@ -667,6 +671,7 @@ jQuery(document).ready(function () {
667671
title_ = 'Edit Subscription';
668672
addEditMode();
669673
} else if (save_method_in === "add") {
674+
670675
title_ = 'Add Subscription';
671676
addEditMode();
672677
} else {
@@ -915,4 +920,4 @@ jQuery(document).ready(function () {
915920
function closeTooltip() {
916921
$('.tooltip').tooltip('hide');
917922
}
918-
});
923+
});

src/main/resources/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
</div>
108108
</li>
109109
<li class="nav-item">
110-
<a class="nav-link" id="userName"></a>
110+
<a class="nav-link" id="ldapUserName"></a>
111111
</li>
112112
<li class="nav-item" id="loginBlock" style="display: none">
113113
<a class="nav-link" id="loginBtn" href="#">

src/main/resources/templates/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="form-group">
2020
<label for="inputUsername">Username</label>
2121
<input class="form-control" id="inputUsername" type="text" placeholder="Enter username"
22-
data-bind="textInput: $root.userState.username"/>
22+
data-bind="textInput: $root.userState.ldapUserName"/>
2323
</div>
2424
<div class="form-group">
2525
<label for="inputPassword">Password</label>

src/main/resources/templates/subscription.html

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ <h3 class="modal-title text-center" id="formHeader">Subscription Form</h3>
130130
</div>
131131
<div class="form-group">
132132
<label class="pl-1 control-label font-weight-bold">NotificationType</label>
133-
<img class="cursor-pointer" id="notificationTypeInfo" alt="NotificationType Info" src="assets/images/information.png" data-toggle="tooltip" data-placement="top"
133+
<img class="cursor-pointer" id="notificationTypeInfo" alt="NotificationType Info" src="assets/images/information.png"
134134
title="This is the notification method used once the subscription triggers."/>
135135
<div>
136136
<select id="notificationType" data-bind="options: $root.notificationType_in,
@@ -144,7 +144,7 @@ <h3 class="modal-title text-center" id="formHeader">Subscription Form</h3>
144144

145145
<div class="form-group" data-bind="visible: notificationType() == 'REST_POST'">
146146
<label class="pl-1 control-label font-weight-bold">RestPostMediaType</label>
147-
<img class="cursor-pointer" id="restPostMediaTypeInfo" alt="RestPostMediaType Info" src="assets/images/information.png" data-toggle="tooltip" data-placement="top"
147+
<img class="cursor-pointer" id="restPostMediaTypeInfo" alt="RestPostMediaType Info" src="assets/images/information.png"
148148
title="This decides the Content-Type of the POST body."/>
149149
<div>
150150
<select style="width: 100%" data-bind="options: $root.restPostBodyType_in,
@@ -204,43 +204,43 @@ <h3 class="modal-title text-center" id="formHeader">Subscription Form</h3>
204204
</button>
205205
</div>
206206
</div>
207-
207+
208208
<div class="pt-3 form-group">
209209
<label class="pl-1 control-label font-weight-bold">Authorization</label>
210210
<div>
211-
<select id="selectAuth" data-bind="options: $root.authenticationType_in,
212-
optionsText: 'text',
213-
optionsValue: 'value',
214-
value: authenticationType,
215-
optionsCaption: 'Choose...'"></select>
211+
<select id="selectAuth" title="Choose an authentication type" data-bind="options: $root.authenticationType_in,
212+
optionsText: 'text', optionsValue: 'value', value: authenticationType">
213+
</select>
216214
</div>
217215
</div>
218216

219217
<div class="p-1 border border-primary form-group" data-bind="visible: authenticationType() == 'BASIC_AUTH'">
220218
<label class="pt-1 control-label font-weight-bold">Username</label>
221219
<div>
222-
<input id="userNameInput" data-bind="textInput:$data.userName" name="userName"
223-
placeholder="Username" class="form-control" type="text" />
220+
<input id="userNameInput" title="Enter user name" data-bind="textInput:userName" name="userName"
221+
placeholder="userName" class="form-control" type="text" />
224222
<span class="help-block"></span>
225223
</div>
226-
227-
<label class="pt-1 control-label font-weight-bold">Password</label>
224+
225+
<label data-bind="visible: $root.showPassword()" class="pl-1 control-label font-weight-bold">Password*</label>
226+
228227
<div>
229-
<input id="tokenInput" data-bind="textInput:$data.token" name="token" placeholder="Password"
228+
<input id="passwordInput" title="Enter password" data-bind="visible: $root.showPassword() && ($root.mode() == 'edit' || $root.mode() == 'add'),textInput:$data.password" name="password" placeholder="password"
230229
class="form-control" type="password" />
230+
231+
<div data-bind="visible: !$root.showPassword() && $root.mode() == 'edit'" class="showPasswordButton" >
232+
<button data-bind="click: function(){$root.showPassword(true);}" class="btn btn-warning">
233+
<i class="glyphicon glyphicon-trash"></i>
234+
Change password
235+
</button>
236+
</div>
231237
<span class="help-block"></span>
232-
</div>
233-
234-
<div class="pt-1 d-flex justify-content-end">
235-
<button data-bind="click: $root.addNotificationMsgKeyValuePairAuth" class="btn btn-success">
236-
<i class="glyphicon glyphicon-plus float-right"></i> Generate Key/Value Pair</button>
237-
</div>
238+
</div>
238239
</div>
239240

240-
241241
<div class="pt-3 form-group">
242242
<label class="pl-1 control-label font-weight-bold">Repeat</label>
243-
<img class="cursor-pointer" id="repeatInfo" alt="Repeat Info" src="assets/images/information.png" data-toggle="tooltip" data-placement="top"
243+
<img class="cursor-pointer" id="repeatInfo" alt="Repeat Info" src="assets/images/information.png"
244244
title="Instructs whether the subscription should be re-triggered for new additions to the aggregated object. If false only first time the conditions are fulfilled
245245
a notification will be triggered. No matter how many times the aggregated object is updated."/>
246246
<div>
@@ -254,7 +254,7 @@ <h3 class="modal-title text-center" id="formHeader">Subscription Form</h3>
254254
</div>
255255
<div class="form-group">
256256
<label class="pl-1 control-label font-weight-bold">NotificationMeta</label>
257-
<img class="cursor-pointer" id="notificationMetaInfo" alt="NotificationMeta Info" src="assets/images/information.png" data-toggle="tooltip" data-placement="top"
257+
<img class="cursor-pointer" id="notificationMetaInfo" alt="NotificationMeta Info" src="assets/images/information.png"
258258
title="The specific point to notify. Example: my@mail.com or host.com/endpoint"/>
259259
<div>
260260
<font class="addSubscriptionErrors" id="noNotificationMetaGiven" color="red" size="2" />
@@ -270,7 +270,7 @@ <h3 class="modal-title text-center" id="formHeader">Subscription Form</h3>
270270
<!-- ko if: $index() !== 0 -->
271271
<h5>OR</h5>
272272
<!-- /ko -->
273-
<img class="cursor-pointer" data-toggle="tooltip" data-placement="top" alt="Requirement Information" src="assets/images/information.png"
273+
<img class="cursor-pointer" alt="Requirement Information" src="assets/images/information.png"
274274
title="Info: 'AND' is used between Conditions in Requirement groups, and 'OR' is used between Requirement groups."/>
275275
</div>
276276
<div class="p-1 border border-primary form-group">

0 commit comments

Comments
 (0)