Skip to content
Permalink
Browse files
[JENKINS-28298] Displays only enabled strategies in project configura…
…tion pages.
  • Loading branch information
ikedam committed Jul 2, 2015
1 parent 369cb10 commit b22196085641ee3b3a80bbe08bbeff0c68e0df61
Showing 3 changed files with 47 additions and 5 deletions.
@@ -24,6 +24,9 @@

package org.jenkinsci.plugins.authorizeproject;

import java.util.Collections;
import java.util.List;

import jenkins.model.Jenkins;
import jenkins.security.QueueItemAuthenticatorConfiguration;

@@ -36,6 +39,7 @@
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.model.Describable;
import hudson.model.DescriptorVisibilityFilter;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
@@ -129,10 +133,22 @@ public String getPropertyName() {
/**
* @return all the registered {@link AuthorizeProjectStrategy}.
*/
@Deprecated
public DescriptorExtensionList<AuthorizeProjectStrategy, Descriptor<AuthorizeProjectStrategy>> getStrategyList() {
return AuthorizeProjectStrategy.all();
}

/**
* @return enabled {@link AuthorizeProjectStrategy}, empty if authorize-project is not enabled.
*/
public List<Descriptor<AuthorizeProjectStrategy>> getEnabledAuthorizeProjectStrategyDescriptorList() {
ProjectQueueItemAuthenticator authenticator = ProjectQueueItemAuthenticator.getConfigured();
if (authenticator == null) {
return Collections.emptyList();
}
return DescriptorVisibilityFilter.apply(authenticator, AuthorizeProjectStrategy.all());
}

/**
* Create a new {@link AuthorizeProjectProperty} from user inputs.
*
@@ -30,6 +30,7 @@
import java.util.Map;

import hudson.Extension;
import hudson.model.DescriptorVisibilityFilter;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Job;
@@ -125,12 +126,16 @@ public String getDisplayName() {
return Messages.ProjectQueueItemAuthenticator_DisplayName();
}

@Deprecated
public List<AuthorizeProjectStrategyDescriptor> getDescriptorsForGlobalSecurityConfigPage() {
return AuthorizeProjectStrategyDescriptor.getDescriptorsForGlobalSecurityConfigPage();
}

/**
* @return all installed {@link AuthorizeProjectStrategy}
*/
public List<Descriptor<AuthorizeProjectStrategy>> getAvailableDescriptorList() {
return Jenkins.getInstance().getDescriptorList(AuthorizeProjectStrategy.class);
return AuthorizeProjectStrategy.all();
}

/**
@@ -169,14 +174,35 @@ public ProjectQueueItemAuthenticator newInstance(StaplerRequest req, JSONObject
}

/**
* @return whether Jenkins is configured to use {@link ProjectQueueItemAuthenticator}.
* @return instance configured in Global Security configuration.
*/
public static boolean isConfigured() {
public static ProjectQueueItemAuthenticator getConfigured() {
for (QueueItemAuthenticator authenticator: QueueItemAuthenticatorConfiguration.get().getAuthenticators()) {
if (authenticator instanceof ProjectQueueItemAuthenticator) {
return (ProjectQueueItemAuthenticator)authenticator;
}
}
return null;
}

/**
* @return whether Jenkins is configured to use {@link ProjectQueueItemAuthenticator}.
*/
public static boolean isConfigured() {
return getConfigured() != null;
}

@Extension
public static class DescriptorVisibilityFilterImpl extends DescriptorVisibilityFilter
{
@Override
public boolean filter(Object context, @SuppressWarnings("rawtypes") Descriptor descriptor)
{
if(!(context instanceof ProjectQueueItemAuthenticator))
{
return true;
}
return ((ProjectQueueItemAuthenticator)context).isStrategyEnabled(descriptor);
}
return false;
}
}
@@ -25,6 +25,6 @@ THE SOFTWARE.
<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">
<st:adjunct includes="org.jenkinsci.plugins.authorizeproject.nestedHelp"/>
<f:optionalBlock name="${descriptor.propertyName}" title="${descriptor.displayName}" checked="${instance != null}">
<f:dropdownDescriptorSelector title="${%Authorize Strategy}" field="strategy" descriptors="${descriptor.strategyList}" />
<f:dropdownDescriptorSelector title="${%Authorize Strategy}" field="strategy" descriptors="${descriptor.enabledAuthorizeProjectStrategyDescriptorList}" />
</f:optionalBlock>
</j:jelly>

0 comments on commit b221960

Please sign in to comment.