Skip to content

Commit

Permalink
Merge pull request #3 from ikedam/feature/JENKINS-20812_GlobalConfigu…
Browse files Browse the repository at this point in the history
…ration

[JENKINS-20812] Configuration view in Configure Global Security
  • Loading branch information
ikedam committed Dec 1, 2013
2 parents 0d1f0d9 + 9ef60d0 commit 93a27c3
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 6 deletions.
@@ -0,0 +1,100 @@
/*
* The MIT License
*
* Copyright (c) 2013 IKEDA Yasuyuki
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.authorizeproject;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONObject;

import org.kohsuke.stapler.StaplerRequest;

import hudson.model.Descriptor;

/**
*
*/
public abstract class AuthorizeProjectStrategyDescriptor extends Descriptor<AuthorizeProjectStrategy> {
/**
*
*/
public AuthorizeProjectStrategyDescriptor() {
super();
}

/**
* @param clazz
*/
public AuthorizeProjectStrategyDescriptor(Class<? extends AuthorizeProjectStrategy> clazz) {
super(clazz);
}


/**
* @return return a page to shown in "Configure Global Security" as a child of {@link ProjectQueueItemAuthenticator}.
*/
public String getGlobalSecurityConfigPage() {
for (String cand: getPossibleViewNames("global-security")) {
String page = getViewPage(clazz, cand);
// Unfortunately, Descriptor#getViewPage returns passed value
// when that view is not found.
// When found, path to that file is returned,
// so I can check whether found
// by comparing passing value and returned value.
if (page != null && !page.equals(cand)) {
return page;
}
}
return null;
}

/**
* @return descriptors to display page in "Configure Global Security" as a child of {@link ProjectQueueItemAuthenticator}.
*/
public static List<AuthorizeProjectStrategyDescriptor> getDescriptorsForGlobalSecurityConfigPage() {
List<Descriptor<AuthorizeProjectStrategy>> all = AuthorizeProjectStrategy.all();
List<AuthorizeProjectStrategyDescriptor> r = new ArrayList<AuthorizeProjectStrategyDescriptor>(all.size());
for (Descriptor<AuthorizeProjectStrategy> d: all) {
if (
d instanceof AuthorizeProjectStrategyDescriptor
&& ((AuthorizeProjectStrategyDescriptor)d).getGlobalSecurityConfigPage() != null
) {
r.add((AuthorizeProjectStrategyDescriptor)d);
}
}
return r;
}

/**
* Invoked when configuration is submitted from "Configure Global Security" as a child of {@link ProjectQueueItemAuthenticator}.
* You should call save() by yourself.
*
* @param req
* @param js
* @throws FormException
*/
public void configureFromGlobalSecurity(StaplerRequest req, JSONObject js) throws FormException {
}
}
Expand Up @@ -24,14 +24,19 @@

package org.jenkinsci.plugins.authorizeproject;

import java.util.List;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Queue;

import javax.annotation.CheckForNull;

import net.sf.json.JSONObject;

import org.acegisecurity.Authentication;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import jenkins.security.QueueItemAuthenticatorConfiguration;
import jenkins.security.QueueItemAuthenticatorDescriptor;
Expand Down Expand Up @@ -81,6 +86,35 @@ public static class DescriptorImpl extends QueueItemAuthenticatorDescriptor {
public String getDisplayName() {
return Messages.ProjectQueueItemAuthenticator_DisplayName();
}

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

/**
* Creates new {@link ProjectQueueItemAuthenticator} from inputs.
* Additional to that, configure global configurations of {@link AuthorizeProjectStrategy}.
*
* @param req
* @param formData
* @return
* @throws hudson.model.Descriptor.FormException
* @see hudson.model.Descriptor#newInstance(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject)
*/
@Override
public ProjectQueueItemAuthenticator newInstance(StaplerRequest req, JSONObject formData)
throws FormException
{
ProjectQueueItemAuthenticator r = (ProjectQueueItemAuthenticator)super.newInstance(req, formData);

for (AuthorizeProjectStrategyDescriptor d : getDescriptorsForGlobalSecurityConfigPage()) {
String name = d.getJsonSafeClassName();
JSONObject js = formData.has(name) ? formData.getJSONObject(name) : new JSONObject();
d.configureFromGlobalSecurity(req, js);
}

return r;
}
}

/**
Expand Down
Expand Up @@ -26,12 +26,12 @@

import jenkins.model.Jenkins;
import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.Queue;
import hudson.model.AbstractProject;

import org.acegisecurity.Authentication;
import org.jenkinsci.plugins.authorizeproject.AuthorizeProjectStrategy;
import org.jenkinsci.plugins.authorizeproject.AuthorizeProjectStrategyDescriptor;
import org.kohsuke.stapler.DataBoundConstructor;

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ public Authentication authenticate(AbstractProject<?, ?> project, Queue.Item ite
*
*/
@Extension
public static class DescriptorImpl extends Descriptor<AuthorizeProjectStrategy> {
public static class DescriptorImpl extends AuthorizeProjectStrategyDescriptor {
/**
* @return the name shown in project configuration pages.
* @see hudson.model.Descriptor#getDisplayName()
Expand Down
Expand Up @@ -36,7 +36,6 @@
import hudson.model.Queue;
import hudson.model.User;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.util.FormValidation;

Expand All @@ -48,6 +47,7 @@
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.authorizeproject.AuthorizeProjectStrategy;
import org.jenkinsci.plugins.authorizeproject.AuthorizeProjectStrategyDescriptor;
import org.jenkinsci.plugins.authorizeproject.AuthorizeProjectProperty;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -184,7 +184,7 @@ protected static SpecificUsersAuthorizationStrategy getCurrentStrategy(AbstractP
*
*/
@Extension
public static class DescriptorImpl extends Descriptor<AuthorizeProjectStrategy> {
public static class DescriptorImpl extends AuthorizeProjectStrategyDescriptor {
/**
*
*/
Expand Down
Expand Up @@ -31,13 +31,13 @@
import hudson.model.Cause.UserIdCause;
import hudson.model.Queue;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Run;
import hudson.model.User;
import java.util.Collections;

import org.acegisecurity.Authentication;
import org.jenkinsci.plugins.authorizeproject.AuthorizeProjectStrategy;
import org.jenkinsci.plugins.authorizeproject.AuthorizeProjectStrategyDescriptor;
import org.kohsuke.stapler.DataBoundConstructor;

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ private UserIdCause getRootUserIdCause(Queue.Item item) {
*
*/
@Extension
public static class DescriptorImpl extends Descriptor<AuthorizeProjectStrategy> {
public static class DescriptorImpl extends AuthorizeProjectStrategyDescriptor {
/**
* @return the name shown in project configuration pages.
* @see hudson.model.Descriptor#getDisplayName()
Expand Down
@@ -0,0 +1,33 @@
<!--
The MIT License
Copyright (c) 2013 IKEDA Yasuyuki
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
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">
<!-- configurations for AuthorizeProjectStrategy -->
<j:forEach var="d" items="${descriptor.descriptorsForGlobalSecurityConfigPage}">
<j:set var="instance" value="${d}" />
<f:rowSet name="${d.jsonSafeClassName}">
<st:include page="${d.globalSecurityConfigPage}" from="${d}" />
</f:rowSet>
</j:forEach>
</j:jelly>

0 comments on commit 93a27c3

Please sign in to comment.