Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit c56ce0a

Browse files
committed
Merge pull request #92 from tomasbjerre/feature/ignore-ssl
Allowing SSL certificates to be ignored #90
2 parents 982d5db + cd23217 commit c56ce0a

24 files changed

+1198
-319
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Changelog of Pull Request Notifier for Bitbucket.
44

5+
## 2.13
6+
* Allowing SSL certificates to be ignored.
7+
* Adding settings to configure custom keystore.
8+
59
## 2.12
610
* Fixing PULL_REQUEST_URL-bug correctly with getSlug.
711

@@ -46,9 +50,10 @@ These can be used to, for example, show a trigger button only if there are non-z
4650
* Bugfix: Adding Basic Auth headers to injection url request.
4751

4852
## 2.0
49-
* Migrated from Stash 3 to Bitbucket 4.
50-
* The release of Bitbucket 4.0 (2015-09-22) broke all backwards compatibility and made it more ore less impossible to maintain a version that is compatible with both Stash 3.x and Bitbucket 4.x. That is why this plugin changed name and started over with a 1.0 release.
51-
* Changed name from Pull Request Notifier for Stash to Pull Request Notifier for Bitbucket
53+
* Migrated from Stash 3 to Bitbucket Server 4.
54+
* The release of Bitbucket Server 4.0 (2015-09-22) broke all backwards compatibility and made it more or less impossible to maintain a version that is compatible with both Stash 3.x and Bitbucket Server 4.x. That is why this plugin changed name in 2.0 release.
55+
* Changed name from Pull Request Notifier for Stash to Pull Request Notifier for Bitbucket.
56+
* 1.x is compatible with Stash 3 and 2.x is compatible with Bitbucket Server 4.
5257

5358
## 1.28
5459
* Can enable trigger

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ The Pull Request Notifier for Bitbucket can:
2828
* Be configured to only trigger if the pull request mathches a filter. A filter text is constructed with any combination of the variables and then a regexp is constructed to match that text.
2929
* Add buttons to pull request view in Bitbucket. And map those buttons to URL invocations. This can be done by setting the filter string to ${BUTTON_TRIGGER_TITLE} and the filter regexp to title of button.
3030
* Authenticate with HTTP basic authentication.
31+
* Optionally allow any SSL certificate.
32+
* Use custom SSL key store, type and password.
3133
* Send custom HTTP headers
3234
* Can optionally use proxy to connect
3335
* Can let users and/or admins do configuration. Or restrict configuration to just system admins. A user will have to browse to the configuration page at `http://domain/bitbucket/plugins/servlet/prnfb/admin`.

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
<artifactId>gson</artifactId>
8989
<scope>provided</scope>
9090
</dependency>
91+
<dependency>
92+
<groupId>org.apache.httpcomponents</groupId>
93+
<artifactId>httpclient</artifactId>
94+
<scope>provided</scope>
95+
</dependency>
9196

9297
<!-- TEST //-->
9398
<dependency>
@@ -108,6 +113,18 @@
108113
<version>1.19</version>
109114
<scope>test</scope>
110115
</dependency>
116+
<dependency>
117+
<groupId>org.assertj</groupId>
118+
<artifactId>assertj-core</artifactId>
119+
<version>3.3.0</version>
120+
<scope>test</scope>
121+
</dependency>
122+
<dependency>
123+
<groupId>commons-logging</groupId>
124+
<artifactId>commons-logging</artifactId>
125+
<version>1.2</version>
126+
<scope>test</scope>
127+
</dependency>
111128
</dependencies>
112129
<build>
113130
<plugins>

src/main/java/se/bjurr/prnfb/ManualResource.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import se.bjurr.prnfb.admin.AdminFormValues;
3333
import se.bjurr.prnfb.admin.AdminFormValues.BUTTON_VISIBILITY;
34+
import se.bjurr.prnfb.http.ClientKeyStore;
3435
import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
3536
import se.bjurr.prnfb.listener.PrnfbPullRequestEventListener;
3637
import se.bjurr.prnfb.listener.PrnfbRenderer;
@@ -94,25 +95,27 @@ public Response get(@Context HttpServletRequest request, @QueryParam("repository
9495
}
9596
List<PrnfbButton> buttons = newArrayList();
9697
final PrnfbSettings settings = getSettings();
98+
ClientKeyStore clientKeyStore = new ClientKeyStore(settings);
9799
for (PrnfbButton candidate : settings.getButtons()) {
98100
UserKey userKey = userManager.getRemoteUserKey();
99101
PrnfbPullRequestAction pullRequestAction = PrnfbPullRequestAction.valueOf(BUTTON_TRIGGER);
100102
final PullRequest pullRequest = pullRequestService.getById(repositoryId, pullRequestId);
101103
Map<PrnfbVariable, Supplier<String>> variables = getVariables(settings, candidate.getFormIdentifier());
102104
if (allowedUseButton(candidate, userManager.isAdmin(userKey), userManager.isSystemAdmin(userKey))
103-
&& triggeredByAction(settings, pullRequestAction, pullRequest, variables, request)) {
105+
&& triggeredByAction(clientKeyStore, settings, pullRequestAction, pullRequest, variables, request)) {
104106
buttons.add(candidate);
105107
}
106108
}
107109
return ok(gson.toJson(buttons), APPLICATION_JSON).build();
108110
}
109111

110-
private boolean triggeredByAction(PrnfbSettings settings, PrnfbPullRequestAction pullRequestAction,
111-
PullRequest pullRequest, Map<PrnfbVariable, Supplier<String>> variables, HttpServletRequest request) {
112+
private boolean triggeredByAction(ClientKeyStore clientKeyStore, PrnfbSettings settings,
113+
PrnfbPullRequestAction pullRequestAction, PullRequest pullRequest, Map<PrnfbVariable, Supplier<String>> variables,
114+
HttpServletRequest request) {
112115
for (PrnfbNotification prnfbNotification : settings.getNotifications()) {
113116
PrnfbRenderer renderer = getRenderer(pullRequest, prnfbNotification, pullRequestAction, variables, request);
114117
if (prnfbPullRequestEventListener.notificationTriggeredByAction(prnfbNotification, pullRequestAction, renderer,
115-
pullRequest)) {
118+
pullRequest, clientKeyStore, settings.shouldAcceptAnyCertificate())) {
116119
return TRUE;
117120
}
118121
}
@@ -130,14 +133,16 @@ public Response post(@Context HttpServletRequest request, @QueryParam("repositor
130133
}
131134

132135
final PrnfbSettings settings = getSettings();
136+
ClientKeyStore clientKeyStore = new ClientKeyStore(settings);
133137
for (PrnfbNotification prnfbNotification : settings.getNotifications()) {
134138
PrnfbPullRequestAction pullRequestAction = PrnfbPullRequestAction.valueOf(BUTTON_TRIGGER);
135139
final PullRequest pullRequest = pullRequestService.getById(repositoryId, pullRequestId);
136140
Map<PrnfbVariable, Supplier<String>> variables = getVariables(settings, formIdentifier);
137141
PrnfbRenderer renderer = getRenderer(pullRequest, prnfbNotification, pullRequestAction, variables, request);
138142
if (prnfbPullRequestEventListener.notificationTriggeredByAction(prnfbNotification, pullRequestAction, renderer,
139-
pullRequest)) {
140-
prnfbPullRequestEventListener.notify(prnfbNotification, pullRequestAction, pullRequest, variables, renderer);
143+
pullRequest, clientKeyStore, settings.shouldAcceptAnyCertificate())) {
144+
prnfbPullRequestEventListener.notify(prnfbNotification, pullRequestAction, pullRequest, variables, renderer,
145+
clientKeyStore, settings.shouldAcceptAnyCertificate());
141146
}
142147
}
143148
return status(OK).build();

src/main/java/se/bjurr/prnfb/admin/AdminFormError.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ public String getField() {
2525
public String getValue() {
2626
return error;
2727
}
28+
29+
@Override
30+
public String toString() {
31+
return field + " " + error;
32+
}
2833
}

src/main/java/se/bjurr/prnfb/admin/AdminFormValues.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public enum FIELDS {
5353
injection_url, //
5454
injection_url_regexp, //
5555
trigger_if_isconflicting, //
56-
trigger_ignore_state//
56+
trigger_ignore_state, //
57+
accept_any_certificate, //
58+
key_store, //
59+
key_store_type, //
60+
key_store_password;
5761
}
5862
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package se.bjurr.prnfb.http;
2+
3+
import static com.google.common.base.Optional.fromNullable;
4+
5+
import java.io.File;
6+
import java.io.FileInputStream;
7+
import java.security.KeyStore;
8+
import java.security.KeyStoreException;
9+
10+
import se.bjurr.prnfb.settings.PrnfbSettings;
11+
12+
import com.google.common.base.Optional;
13+
14+
/**
15+
* A keystore based on the definition from the application properties.<br>
16+
* <br>
17+
* Inspired by:<br>
18+
* Philip Dodds (pdodds) https://github.com/pdodds
19+
*/
20+
public class ClientKeyStore {
21+
22+
private KeyStore keyStore = null;
23+
private char[] password = null;
24+
25+
public ClientKeyStore(PrnfbSettings settings) {
26+
if (settings.getKeyStore().isPresent()) {
27+
File keyStoreFile = new File(settings.getKeyStore().get());
28+
try {
29+
keyStore = getKeyStore(settings.getKeyStoreType());
30+
31+
if (settings.getKeyStorePassword().isPresent()) {
32+
password = settings.getKeyStorePassword().get().toCharArray();
33+
}
34+
35+
keyStore.load(new FileInputStream(keyStoreFile), password);
36+
} catch (Exception e) {
37+
throw new RuntimeException("Unable to build keystore from " + keyStoreFile.getAbsolutePath(), e);
38+
}
39+
}
40+
}
41+
42+
public Optional<KeyStore> getKeyStore() {
43+
return fromNullable(keyStore);
44+
}
45+
46+
public char[] getPassword() {
47+
return password;
48+
}
49+
50+
private KeyStore getKeyStore(String keyStoreType) throws KeyStoreException {
51+
if (keyStoreType != null) {
52+
return KeyStore.getInstance(keyStoreType);
53+
} else {
54+
return KeyStore.getInstance(KeyStore.getDefaultType());
55+
}
56+
}
57+
}

src/main/java/se/bjurr/prnfb/listener/Invoker.java renamed to src/main/java/se/bjurr/prnfb/http/Invoker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package se.bjurr.prnfb.listener;
1+
package se.bjurr.prnfb.http;
2+
23

34
public interface Invoker {
45
void invoke(UrlInvoker urlInvoker);

0 commit comments

Comments
 (0)