Skip to content

Commit b936604

Browse files
author
Anders Breid
authored
Enable use of custom AuthenticationType (#21)
* Enable use of custom AuthenticationType
1 parent 0fec171 commit b936604

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

src/main/java/com/ericsson/eiffelcommons/subscriptionobject/RestPostSubscriptionObject.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
public class RestPostSubscriptionObject extends SubscriptionObject {
66

7+
private final String NOTIFICATION_TYPE_KEY = "notificationType";
8+
private final String NOTIFICATION_TYPE = "REST_POST";
9+
10+
private final String AUTHENTICATION_TYPE_KEY = "authenticationType";
11+
private final String USERNAME_KEY = "userName";
12+
private final String PASSWORD_KEY = "password";
13+
14+
private final String BASIC_AUTH = "BASIC_AUTH";
15+
716
/**
817
* Creates a subscriptionObject with REST/POST capabilities.
918
* @param subscriptionName
@@ -12,17 +21,48 @@ public class RestPostSubscriptionObject extends SubscriptionObject {
1221
public RestPostSubscriptionObject(String subscriptionName) throws IOException {
1322
super(subscriptionName);
1423

15-
subscriptionJson.put("notificationType", "REST_POST");
24+
subscriptionJson.put(NOTIFICATION_TYPE_KEY, NOTIFICATION_TYPE);
1625
}
1726

1827
/**
1928
* Sets the field authenticationType to BASIC_AUTH together with the username and password.
2029
* @param username
2130
* @param password
2231
*/
32+
@Deprecated
2333
public void setBasicAuth(String username, String password) {
24-
subscriptionJson.put("userName", username);
25-
subscriptionJson.put("password", password);
26-
subscriptionJson.put("authenticationType", "BASIC_AUTH");
34+
setAuthenticationType(BASIC_AUTH);
35+
setUsername(username);
36+
setPassword(password);
37+
}
38+
39+
/**
40+
* Sets the field authenticationType to given value
41+
* @param authenticationType
42+
* @return RestPostSubscriptionObject
43+
*/
44+
public RestPostSubscriptionObject setAuthenticationType(String authenticationType) {
45+
subscriptionJson.put(AUTHENTICATION_TYPE_KEY, authenticationType);
46+
return this;
47+
}
48+
49+
/**
50+
* Sets the field username in a subscription.
51+
* @param username
52+
* @return RestPostSubscriptionObject
53+
*/
54+
public RestPostSubscriptionObject setUsername(String username) {
55+
subscriptionJson.put(USERNAME_KEY, username);
56+
return this;
57+
}
58+
59+
/**
60+
* Sets the field password in a subscription.
61+
* @param password
62+
* @return RestPostSubscriptionObject
63+
*/
64+
public RestPostSubscriptionObject setPassword(String password) {
65+
subscriptionJson.put(PASSWORD_KEY, password);
66+
return this;
2767
}
2868
}

0 commit comments

Comments
 (0)