package hudson.security;

import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Jobs;

/**
 * {@link GlobalMatrixAuthorizationStrategy} plus per-project ACL.
 *
 * <p>
 * Per-project ACL is stored in {@link AuthorizationMatrixProperty}.
 *
 * @author Kohsuke Kawaguchi
 */
public class ProjectMatrixAuthorizationStrategy extends GlobalMatrixAuthorizationStrategy {
    @Override
    public ACL getACL(AbstractProject<?,?> project) {
        AuthorizationMatrixProperty amp = project.getProperty(AuthorizationMatrixProperty.class);
        if (amp != null && amp.isUseProjectSecurity()) {
            return amp.getACL();
        } else {
            return getRootACL();
        }
    }

    public Descriptor<AuthorizationStrategy> getDescriptor() {
        return DESCRIPTOR;
    }

    public static final Descriptor<AuthorizationStrategy> DESCRIPTOR = new DescriptorImpl(ProjectMatrixAuthorizationStrategy.class) {
        @Override
        protected GlobalMatrixAuthorizationStrategy create() {
            return new ProjectMatrixAuthorizationStrategy();
        }

        @Override
        public String getDisplayName() {
            return Messages.ProjectMatrixAuthorizationStrategy_DisplayName();
        }
    };

    static {
        LIST.add(DESCRIPTOR);
        Jobs.PROPERTIES.add(AuthorizationMatrixProperty.DESCRIPTOR);
    }
}


@@ -118,16 +118,282 @@
 l.Jobs;%0D
+%0Aimport hudson.util.RobustReflectionConverter;%0D%0Aimport com.thoughtworks.xstream.io.HierarchicalStreamReader;%0D%0Aimport com.thoughtworks.xstream.converters.UnmarshallingContext;%0D%0Aimport com.thoughtworks.xstream.mapper.Mapper;%0D%0Aimport com.thoughtworks.xstream.core.JVM;%0D
 %0A%0D%0A/**%0D%0A
@@ -1558,24 +1558,1083 @@
 %0D%0A    %7D;%0D%0A%0D%0A
+    public static class ConverterImpl extends GlobalMatrixAuthorizationStrategy.ConverterImpl %7B%0D%0A        private RobustReflectionConverter ref;%0D%0A%0D%0A        public ConverterImpl(Mapper m) %7B%0D%0A            ref = new RobustReflectionConverter(m,new JVM().bestReflectionProvider());%0D%0A        %7D%0D%0A%0D%0A        protected GlobalMatrixAuthorizationStrategy create() %7B%0D%0A            return new GlobalMatrixAuthorizationStrategy();%0D%0A        %7D%0D%0A%0D%0A        public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) %7B%0D%0A            String name = reader.peekNextChild();%0D%0A            if(name!=null && name.equals(%22permission%22))%0D%0A                // the proper serialization form%0D%0A                return super.unmarshal(reader, context);%0D%0A            else%0D%0A                // remain compatible with earlier problem where we used reflection converter%0D%0A                return ref.unmarshal(reader,context);%0D%0A        %7D%0D%0A%0D%0A        public boolean canConvert(Class type) %7B%0D%0A            return type==ProjectMatrixAuthorizationStrategy.class;%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A
     static %7B

Fixed the serialized form of project-based matrix authorization strategy.