mohamicorp / stash-jenkins-postreceive-webhook

Webhook used to notify Jenkins when commits are made to Stash
Other
138 stars 98 forks source link

Fix ssh urls #106

Closed bbaetz closed 9 years ago

bbaetz commented 9 years ago

Getting the SSH url requires repository read permission in newer stash versions.

bbaetz commented 9 years ago

Stacktrace is:

org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext at org.springframework.security.access.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:339) ~[AbstractSecurityInterceptor.class:3.2.5.RELEASE] at com.atlassian.stash.internal.ssh.service.DefaultSshCloneUrlResolver.getCloneUrl(DefaultSshCloneUrlResolver.java:34) ~[na:na] at com.nerdwin15.stash.webhook.Notifier.getUrl(Notifier.java:230) [plugin.415263950538720458.stash-webhook-jenkins-2.6.2-20150128.024502-1_1423455745000.jar:na] at com.nerdwin15.stash.webhook.Notifier.notify(Notifier.java:177) [plugin.415263950538720458.stash-webhook-jenkins-2.6.2-20150128.024502-1_1423455745000.jar:na] at com.nerdwin15.stash.webhook.Notifier.notify(Notifier.java:149) [plugin.415263950538720458.stash-webhook-jenkins-2.6.2-20150128.024502-1_1423455745000.jar:na] at com.nerdwin15.stash.webhook.Notifier$1.call(Notifier.java:130) [plugin.415263950538720458.stash-webhook-jenkins-2.6.2-20150128.024502-1_1423455745000.jar:na] at com.nerdwin15.stash.webhook.Notifier$1.call(Notifier.java:127) [plugin.415263950538720458.stash-webhook-jenkins-2.6.2-20150128.024502-1_1423455745000.jar:na] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_31] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_31] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]

This worked as-is in the 2.4 version that the plugin depends on (which is where I did all my testing), but fails in newer ones (probably 2.11, which is when the SshCloneUrlResolver was deprecated and forwards to a RespositoryService method that applies the access controls). Technically this is an undocumented API change in Stash, but that was about a year ago so its simpler to just fix it this way.

BTW, a lot of these APIs are deprecated and marked to be removed in stash 4 - it won't be possible to keep compat with such old Stash versions for much longer.

bbaetz commented 9 years ago

Can this please get merged?

mikesir87 commented 9 years ago

Yes. I'll go ahead and get this in. Sorry it's taken a while to get to it.

In regards to the APIs being deprecated, I'm looking at doing a rewrite to better make use of global configuration, etc. So, there will probably be a version 3.0 when Stash 4 comes out. If not, I'll at least take out the deprecated code. Thanks!