use of hudson.security.AuthorizationMatrixProperty in project hudson-2.x by hudson.
the class FreeStyleProjectTest method testOnCopiedFrom.
@Test
public void testOnCopiedFrom() {
Hudson hudson = createMock(Hudson.class);
AuthorizationStrategy authorizationStrategy = createMock(ProjectMatrixAuthorizationStrategy.class);
expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
User user = createMock(User.class);
expect(user.getId()).andReturn(USER).times(2);
mockStatic(User.class);
expect(User.current()).andReturn(user);
replayAll();
MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCopiedFrom(matrixProjectProject);
verifyAll();
assertEquals(freeStyleProject.getNextBuildNumber(), 1);
assertTrue(freeStyleProject.isHoldOffBuildUntilSave());
assertNotNull(freeStyleProject.getCreationTime());
assertEquals(freeStyleProject.getCreatedBy(), USER);
List properties = freeStyleProject.getAllProperties();
assertEquals(properties.size(), 1);
AuthorizationMatrixProperty property = (AuthorizationMatrixProperty) properties.get(0);
assertEquals(property.getGrantedPermissions().keySet().size(), 7);
assertNotNull(property.getGrantedPermissions().get(Item.CONFIGURE));
assertTrue(property.getGrantedPermissions().get(Item.CONFIGURE).contains(USER));
}
use of hudson.security.AuthorizationMatrixProperty in project hudson-2.x by hudson.
the class Job method grantProjectMatrixPermissions.
/**
* Grants project permissions to the user.
*
* @param user user
*/
protected void grantProjectMatrixPermissions(User user) {
if (Hudson.getInstance().getAuthorizationStrategy() instanceof ProjectMatrixAuthorizationStrategy) {
Map<Permission, Set<String>> grantedPermissions = new HashMap<Permission, Set<String>>();
Set<String> users = Sets.newHashSet(user.getId());
grantedPermissions.put(Item.BUILD, users);
grantedPermissions.put(Item.CONFIGURE, users);
grantedPermissions.put(Item.DELETE, users);
grantedPermissions.put(Item.READ, users);
grantedPermissions.put(Item.WORKSPACE, users);
grantedPermissions.put(Run.DELETE, users);
grantedPermissions.put(Run.UPDATE, users);
AuthorizationMatrixProperty amp = new AuthorizationMatrixProperty(grantedPermissions);
amp.setOwner(this);
properties.add(amp);
}
}
use of hudson.security.AuthorizationMatrixProperty in project hudson-2.x by hudson.
the class Job method submit.
/**
* Derived class can override this to perform additional config submission
* work.
*/
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
JSONObject json = req.getSubmittedForm();
description = req.getParameter("description");
keepDependencies = req.getParameter("keepDependencies") != null;
properties.clear();
setCascadingProjectName(StringUtils.trimToNull(req.getParameter("cascadingProjectName")));
CopyOnWriteList parameterDefinitionProperties = new CopyOnWriteList();
int i = 0;
for (JobPropertyDescriptor d : JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())) {
if (!CascadingUtil.isCascadableJobProperty(d)) {
String name = "jobProperty" + i;
JSONObject config = json.getJSONObject(name);
JobProperty prop = d.newInstance(req, config);
if (null != prop) {
prop.setOwner(this);
if (prop instanceof AuthorizationMatrixProperty) {
properties.add(prop);
} else if (prop instanceof ParametersDefinitionProperty) {
parameterDefinitionProperties.add(prop);
}
}
} else {
BaseProjectProperty property = CascadingUtil.getBaseProjectProperty(this, d.getJsonSafeClassName());
JobProperty prop = d.newInstance(req, json.getJSONObject(d.getJsonSafeClassName()));
if (null != prop) {
prop.setOwner(this);
}
property.setValue(prop);
addCascadingJobProperty(property);
}
i++;
}
setParameterDefinitionProperties(parameterDefinitionProperties);
LogRotator logRotator = null;
if (null != req.getParameter("logrotate")) {
logRotator = LogRotator.DESCRIPTOR.newInstance(req, json.getJSONObject("logrotate"));
}
setLogRotator(logRotator);
}
use of hudson.security.AuthorizationMatrixProperty in project hudson-2.x by hudson.
the class Job method convertCascadingJobProperties.
/**
* Method converts JobProperties to cascading values.
* <p/>
* If property is {@link AuthorizationMatrixProperty} - it will be skipped.
* If property is {@link ParametersDefinitionProperty} - it will be added to list of parameterDefinition properties.
* All the rest properties will be converted to {@link BaseProjectProperty} classes and added
* to cascadingJobProperties set.
*
* @param properties list of {@link JobProperty}
*/
private void convertCascadingJobProperties(CopyOnWriteList<JobProperty<? super JobT>> properties) {
CopyOnWriteList parameterDefinitionProperties = new CopyOnWriteList();
for (JobProperty property : properties) {
if (property instanceof AuthorizationMatrixProperty) {
continue;
}
if (property instanceof ParametersDefinitionProperty) {
parameterDefinitionProperties.add(property);
continue;
}
BaseProjectProperty projectProperty = CascadingUtil.getBaseProjectProperty(this, property.getDescriptor().getJsonSafeClassName());
addCascadingJobProperty(projectProperty);
}
if (null == getProperty(PARAMETERS_DEFINITION_JOB_PROPERTY_PROPERTY_NAME)) {
setParameterDefinitionProperties(parameterDefinitionProperties);
}
}
use of hudson.security.AuthorizationMatrixProperty in project hudson-2.x by hudson.
the class FreeStyleProjectTest method testOnCreatedFromScratch.
@Test
public void testOnCreatedFromScratch() {
Hudson hudson = createMock(Hudson.class);
AuthorizationStrategy authorizationStrategy = createMock(ProjectMatrixAuthorizationStrategy.class);
expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
User user = createMock(User.class);
expect(user.getId()).andReturn(USER).times(2);
mockStatic(User.class);
expect(User.current()).andReturn(user);
replayAll();
FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCreatedFromScratch();
verifyAll();
assertNotNull(freeStyleProject.getCreationTime());
assertEquals(freeStyleProject.getCreatedBy(), USER);
List properties = freeStyleProject.getAllProperties();
assertEquals(properties.size(), 1);
AuthorizationMatrixProperty property = (AuthorizationMatrixProperty) properties.get(0);
assertEquals(property.getGrantedPermissions().keySet().size(), 7);
assertNotNull(property.getGrantedPermissions().get(Item.CONFIGURE));
assertTrue(property.getGrantedPermissions().get(Item.CONFIGURE).contains(USER));
}
Aggregations