Skip to content

Commit

Permalink
[JENKINS-30574] Strategies can change the configuration behavior for …
Browse files Browse the repository at this point in the history
…GlobalQueueItemAuthenticator.
  • Loading branch information
ikedam committed Mar 6, 2016
1 parent 12a36be commit 52e0649
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
Expand Up @@ -114,4 +114,12 @@ public void configureFromGlobalSecurity(StaplerRequest req, JSONObject js) throw
public boolean isEnabledByDefault() {
return true;
}

/**
* @return whether configurable for {@link GlobalQueueItemAuthenticator}
* @since 1.1.1
*/
public boolean isApplicableToGlobal() {
return true;
}
}
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.authorizeproject;

import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.Job;
import hudson.model.Queue;
import jenkins.security.QueueItemAuthenticator;
Expand All @@ -9,6 +10,9 @@
import org.jenkinsci.plugins.authorizeproject.strategy.AnonymousAuthorizationStrategy;
import org.kohsuke.stapler.DataBoundConstructor;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

/**
* A global default authenticator to allow changing the default for all projects.
*
Expand Down Expand Up @@ -41,6 +45,23 @@ public String getDisplayName() {
return Messages.GlobalQueueItemAuthenticator_DisplayName();
}

/**
* @return Descriptors for {@link AuthorizeProjectStrategy} applicable to {@link GlobalQueueItemAuthenticator}.
*/
public Iterable<Descriptor<AuthorizeProjectStrategy>> getStrategyDescriptors() {
return Iterables.filter(
AuthorizeProjectStrategy.all(),
new Predicate<Descriptor<AuthorizeProjectStrategy>>() {
public boolean apply(Descriptor<AuthorizeProjectStrategy> d) {
if (!(d instanceof AuthorizeProjectStrategyDescriptor)) {
return true;
}
return ((AuthorizeProjectStrategyDescriptor)d).isApplicableToGlobal();
}
}
);
}

public AuthorizeProjectStrategy getDefaultStrategy() {
return new AnonymousAuthorizationStrategy();
}
Expand Down
Expand Up @@ -257,7 +257,7 @@ protected SpecificUsersAuthorizationStrategy newInstanceWithoutAuthentication(
JSONObject formData
) throws FormException {
String userid = formData.getString("userid");
boolean noNeedReauthentication = formData.getBoolean("noNeedReauthentication");
boolean noNeedReauthentication = formData.optBoolean("noNeedReauthentication", false);

if (StringUtils.isBlank(userid)) {
throw new FormException("userid must be specified", "userid");
Expand Down
Expand Up @@ -23,11 +23,16 @@ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:hack="/org/jenkinsci/plugins/authorizeproject/form">
<j:scope>
<j:set var="authorizeProjectContext" value="project" />
<st:adjunct includes="org.jenkinsci.plugins.authorizeproject.nestedHelp"/>
<f:optionalBlock name="${descriptor.propertyName}" title="${descriptor.displayName}" checked="${instance != null}">
<!--
What fun that dropdownDescriptorSelector doesn't add 'it' to the render on demand captured variables
-->
<hack:dropdownDescriptorSelector title="${%Authorize Strategy}" field="strategy" descriptors="${descriptor.enabledAuthorizeProjectStrategyDescriptorList}" />
<hack:dropdownDescriptorSelector title="${%Authorize Strategy}" field="strategy" descriptors="${descriptor.enabledAuthorizeProjectStrategyDescriptorList}"
capture="authorizeProjectContext"
/>
</f:optionalBlock>
</j:scope>
</j:jelly>
Expand Up @@ -24,5 +24,11 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:hack="/org/jenkinsci/plugins/authorizeproject/form">
<hack:dropdownDescriptorSelector field="strategy" default="${descriptor.defaultStrategy}" title="${%Strategy}"/>
<j:scope>
<j:set var="authorizeProjectContext" value="global" />
<hack:dropdownDescriptorSelector field="strategy" default="${descriptor.defaultStrategy}" title="${%Strategy}"
descriptors="${descriptor.strategyDescriptors}"
capture="authorizeProjectContext"
/>
</j:scope>
</j:jelly>
Expand Up @@ -39,7 +39,7 @@ THE SOFTWARE.
<st:attribute name="title" use="required">
Human readable title of this control.
</st:attribute>
<st:attribute name="lazy">
<st:attribute name="capture">
If specified, the additional the variables to be captured. See the @capture of &lt;renderOnDemand> tag.
</st:attribute>
<st:attribute name="descriptors">
Expand All @@ -66,7 +66,7 @@ THE SOFTWARE.
<f:dropdownListBlock value="${loop.index}" title="${descriptor.displayName}"
selected="${current.descriptor==descriptor || (current==null and descriptor==attrs.default)}"
staplerClass="${descriptor.clazz.name}"
lazy="${attrs.lazy?attrs.lazy+',':''}descriptor,it">
lazy="${(attrs.capture != null and attrs.capture != '')?attrs.capture+',':''}descriptor,it">
<l:ajax>
<j:set var="instance" value="${current.descriptor==descriptor ? current : null}"/>
<st:include from="${descriptor}" page="${descriptor.configPage}"/>
Expand Down
Expand Up @@ -31,6 +31,7 @@ THE SOFTWARE.
<f:entry title="${%User ID}" field="userid">
<f:textbox checkPasswordRequestedUrl="${descriptor.calcCheckPasswordRequestedUrl()}" />
</f:entry>
<j:if test="${authorizeProjectContext != 'global'}">
<f:entry title="${%Password}" field="password">
<div class="specific-user-authorization-password">
<f:password />
Expand All @@ -43,9 +44,12 @@ THE SOFTWARE.
<f:entry title="${%No need for re-authentication}" field="noNeedReauthentication">
<f:checkbox />
</f:entry>
</j:if> <!-- authorizeProjectContext -->
</table></f:block>
<j:if test="${authorizeProjectContext != 'global'}">
<st:once>
<st:adjunct includes="org.jenkinsci.plugins.authorizeproject.strategy.SpecificUsersAuthorizationStrategy.checkPasswordRequested" />
<st:adjunct includes="org.jenkinsci.plugins.authorizeproject.strategy.SpecificUsersAuthorizationStrategy.passwordApitokenSwitch" />
</st:once>
</j:if> <!-- authorizeProjectContext -->
</j:jelly>

0 comments on commit 52e0649

Please sign in to comment.