本文整理汇总了Java中hudson.model.User类的典型用法代码示例。如果您正苦于以下问题:Java User类的具体用法?Java User怎么用?Java User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
User类属于hudson.model包,在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: abortShouldNotRetry
import hudson.model.User; //导入依赖的package包/类
@Issue("JENKINS-41276")
@Test
public void abortShouldNotRetry() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"int count = 0; retry(3) { echo 'trying '+(count++); semaphore 'start'; echo 'NotHere' } echo 'NotHere'", true));
final WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("start/1", b);
ACL.impersonate(User.get("dev").impersonate(), new Runnable() {
@Override public void run() {
b.getExecutor().doStop();
}
});
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
r.assertLogContains("trying 0", b);
r.assertLogContains("Aborted by dev", b);
r.assertLogNotContains("trying 1", b);
r.assertLogNotContains("trying 2", b);
r.assertLogNotContains("NotHere", b);
}
示例2: specialStatus
import hudson.model.User; //导入依赖的package包/类
@Test public void specialStatus() throws Exception {
User.get("smrt");
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"catchError {\n" +
" semaphore 'specialStatus'\n" +
"}", true));
SemaphoreStep.failure("specialStatus/1", new FlowInterruptedException(Result.UNSTABLE, new CauseOfInterruption.UserInterruption("smrt")));
WorkflowRun b = p.scheduleBuild2(0).get();
r.assertLogContains("smrt", r.assertBuildStatus(Result.UNSTABLE, b));
/* TODO fixing this is trickier since CpsFlowExecution.setResult does not implement a public method, and anyway CatchErrorStep in its current location could not refer to FlowExecution:
List<FlowNode> heads = b.getExecution().getCurrentHeads();
assertEquals(1, heads.size());
assertEquals(Result.UNSTABLE, ((FlowEndNode) heads.get(0)).getResult());
*/
}
示例3: getAuthorities
import hudson.model.User; //导入依赖的package包/类
/**
* Gets the names of the authorities that this action is associated with.
*
* @return the names of the authorities that this action is associated with.
*/
@NonNull
public List<String> getAuthorities() {
Authentication authentication = Jenkins.getAuthentication();
GrantedAuthority[] authorities = authentication.getAuthorities();
if (authorities == null) {
return Collections.emptyList();
}
String id = authentication.getName();
List<String> result = new ArrayList<>(authorities.length);
for (GrantedAuthority a : authorities) {
String n = a.getAuthority();
if (n != null && !User.idStrategy().equals(n, id)) {
result.add(n);
}
}
Collections.sort(result, String.CASE_INSENSITIVE_ORDER);
return result;
}
示例4: verifyFormData
import hudson.model.User; //导入依赖的package包/类
@Override
public void verifyFormData(HudsonSecurityRealmRegistration securityRealmRegistration, JSONObject object)
throws RegistrationException, InvalidSecurityRealmException {
final String activationCode = BaseFormField.ACTIVATION_CODE.fromJSON(object);
if (StringUtils.isEmpty(activationCode)) {
throw new RegistrationException(Messages.RRError_Hudson_ActiviationCodeInvalid());
}
final User user = RRHudsonUserProperty.getUserForActivationCode(activationCode);
final RRHudsonUserProperty hudsonUserProperty = RRHudsonUserProperty.getPropertyForUser(user);
if (hudsonUserProperty == null) {
throw new RegistrationException(Messages.RRError_Hudson_ActiviationCodeInvalid());
}
if (hudsonUserProperty.getActivated()) {
throw new RegistrationException(Messages.RRError_Hudson_UserIsActivated());
}
final Mailer.UserProperty mailerProperty = user.getProperty(Mailer.UserProperty.class);
if (mailerProperty == null) {
throw new RegistrationException(Messages.RRError_Hudson_UserNoEmailAddress());
}
final String emailAddress = Utils.fixEmptyString(mailerProperty.getAddress());
if (!EmailValidator.getInstance().isValid(emailAddress)) {
throw new RegistrationException(Messages.RRError_Hudson_UserInvalidEmail(emailAddress));
}
}
示例5: doLatchPairConnection
import hudson.model.User; //导入依赖的package包/类
public FormValidation doLatchPairConnection(@QueryParameter("pairToken") final String pairToken,
@AncestorInPath User user,
@QueryParameter("csrf") final String csrf) throws IOException {
if (validCSRF(csrf)) {
if (pairToken != null && !pairToken.isEmpty()) {
LatchApp latchApp = LatchSDK.getInstance();
if (latchApp != null) {
LatchResponse pairResponse = latchApp.pair(pairToken);
if (pairResponse == null) {
return FormValidation.error(Messages.LatchAccountProperty_UnreachableConnection());
} else if (pairResponse.getError() != null && pairResponse.getError().getCode() != 205) {
return FormValidation.error(Messages.LatchAccountProperty_Invalid_Token());
} else {
LatchAccountProperty lap = newInstance(user);
lap.accountId = pairResponse.getData().get("accountId").getAsString();
user.addProperty(lap);
return FormValidation.ok(Messages.LatchAccountProperty_Pair());
}
}
return FormValidation.ok(Messages.LatchAccountProperty_PluginDisabled());
}
return FormValidation.error(Messages.LatchAccountProperty_Invalid_Token());
}
return FormValidation.error(Messages.LatchAccountProperty_Csrf());
}
示例6: doLatchUnpairConnection
import hudson.model.User; //导入依赖的package包/类
public FormValidation doLatchUnpairConnection(@AncestorInPath User user,
@QueryParameter("csrf") final String csrf) throws IOException {
if (validCSRF(csrf)) {
LatchAccountProperty lap = user.getProperty(LatchAccountProperty.class);
LatchApp latchApp = LatchSDK.getInstance();
if (latchApp != null) {
LatchResponse unpairResponse = latchApp.unpair(lap.getAccountId());
if (unpairResponse == null) {
return FormValidation.error(Messages.LatchAccountProperty_UnreachableConnection());
} else if (unpairResponse.getError() != null && unpairResponse.getError().getCode() != 201) {
return FormValidation.error(unpairResponse.getError().getMessage());
} else {
lap.accountId = null;
lap.user.save();
return FormValidation.ok(Messages.LatchAccountProperty_Unpair());
}
}
return FormValidation.ok(Messages.LatchAccountProperty_PluginDisabled());
}
return FormValidation.error(Messages.LatchAccountProperty_Csrf());
}
示例7: getAuthor
import hudson.model.User; //导入依赖的package包/类
/**
* Gets the user who made this change.
*
* This is a mandatory part of the Change Log Architecture
*
* @return the author of the checkin (aka commit)
*/
@Exported
public User getAuthor() {
User user = User.get(author, false);
if (user == null) {
user = User.get(author, true);
// set email address for user
if (fixEmpty(authorEmail) != null) {
try {
user.addProperty(new Mailer.UserProperty(authorEmail));
} catch (IOException e) {
// ignore error
}
}
}
return user;
}
示例8: newInstance
import hudson.model.User; //导入依赖的package包/类
/**
* Creates a new instance of the GitLabUserInformation object containing information about the logged in user.
*
* @return the UserPropery object
*/
@Override
public UserProperty newInstance(User user) {
Authentication auth = Jenkins.getAuthentication();
if (auth instanceof GitLabUserDetails) {
GitLabUserInfo gitLabUser;
try {
gitLabUser = GitLab.getUser(((GitLabUserDetails) auth.getPrincipal()).getId());
return new GitLabUserProperty(gitLabUser);
} catch (GitLabApiException e) {
LOGGER.warning(e.getMessage());
}
}
return new GitLabUserProperty();
}
示例9: TestGitRepo
import hudson.model.User; //导入依赖的package包/类
public TestGitRepo(String name, File tmpDir, TaskListener listener) throws IOException, InterruptedException {
this.name = name;
this.listener = listener;
envVars = new EnvVars();
gitDir = tmpDir;
User john = User.get(johnDoe.getName(), true);
UserProperty johnsMailerProperty = new Mailer.UserProperty(johnDoe.getEmailAddress());
john.addProperty(johnsMailerProperty);
User jane = User.get(janeDoe.getName(), true);
UserProperty janesMailerProperty = new Mailer.UserProperty(janeDoe.getEmailAddress());
jane.addProperty(janesMailerProperty);
// initialize the git interface.
gitDirPath = new FilePath(gitDir);
git = Git.with(listener, envVars).in(gitDir).getClient();
// finally: initialize the repo
git.init();
}
示例10: initPython
import hudson.model.User; //导入依赖的package包/类
private void initPython() {
if (pexec == null) {
pexec = new PythonExecutor(this);
String[] jMethods = new String[1];
jMethods[0] = "findNameFor";
String[] pFuncs = new String[1];
pFuncs[0] = "find_name_for";
Class[][] argTypes = new Class[1][];
argTypes[0] = new Class[1];
argTypes[0][0] = User.class;
pexec.checkAbstrMethods(jMethods, pFuncs, argTypes);
String[] functions = new String[0];
int[] argsCount = new int[0];
pexec.registerFunctions(functions, argsCount);
}
}
示例11: initPython
import hudson.model.User; //导入依赖的package包/类
private void initPython() {
if (pexec == null) {
pexec = new PythonExecutor(this);
String[] jMethods = new String[1];
jMethods[0] = "findAvatarFor";
String[] pFuncs = new String[1];
pFuncs[0] = "find_avatar_for";
Class[][] argTypes = new Class[1][];
argTypes[0] = new Class[3];
argTypes[0][0] = User.class;
argTypes[0][1] = int.class;
argTypes[0][2] = int.class;
pexec.checkAbstrMethods(jMethods, pFuncs, argTypes);
String[] functions = new String[0];
int[] argsCount = new int[0];
pexec.registerFunctions(functions, argsCount);
}
}
示例12: testRebuildNotAuthorized
import hudson.model.User; //导入依赖的package包/类
@Test
public void testRebuildNotAuthorized() throws Exception {
FreeStyleProject projectA = jenkins.createFreeStyleProject("A");
jenkins.createFreeStyleProject("B");
projectA.getPublishersList().add(new BuildPipelineTrigger("B", null));
jenkins.getInstance().rebuildDependencyGraph();
DeliveryPipelineView view = new DeliveryPipelineView("View");
jenkins.getInstance().addView(view);
jenkins.getInstance().setSecurityRealm(jenkins.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Permission.READ, "devel");
jenkins.getInstance().setAuthorizationStrategy(gmas);
SecurityContext oldContext = ACL.impersonate(User.get("devel").impersonate());
try {
view.triggerRebuild("B", "1");
fail();
} catch (AuthenticationException e) {
//Should throw this
}
SecurityContextHolder.setContext(oldContext);
}
示例13: getEmailAddress
import hudson.model.User; //导入依赖的package包/类
public String getEmailAddress(String username) {
String address = null;
User u = User.get(username);
if (u == null) {
println("failed obtaining user for name " + username);
return address;
}
Mailer.UserProperty p = u.getProperty(Mailer.UserProperty.class);
if (p == null) {
println("failed obtaining email address for user " + username);
return address;
}
if (p.getAddress() == null) {
println("failed obtaining email address (is null) for user " + username);
return address;
}
return p.getAddress();
}
示例14: setUp
import hudson.model.User; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.SEVERE);
project = createFreeStyleProject(projectName);
DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> publishers = new DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>>(
project);
publishers.add(new QuarantineTestDataPublisher());
QuarantinableJUnitResultArchiver archiver = new QuarantinableJUnitResultArchiver("*.xml");
archiver.setTestDataPublishers(publishers);
project.getPublishersList().add(archiver);
hudson.setAuthorizationStrategy(new FullControlOnceLoggedInAuthorizationStrategy());
hudson.setSecurityRealm(createDummySecurityRealm());
User u = User.get("user1");
u.addProperty(new Mailer.UserProperty(user1Mail));
}
示例15: generatedMessage
import hudson.model.User; //导入依赖的package包/类
private String generatedMessage(AbstractBuild<?, ?> build) {
final StringBuilder userBuilder = new StringBuilder();
for(User user: build.getCulprits()) {
userBuilder.append(user.getFullName() + " ");
}
final StringBuilder changeSetBuilder = new StringBuilder();
for(ChangeLogSet.Entry entry: build.getChangeSet()) {
changeSetBuilder.append(entry.getAuthor() + " : " + entry.getMsg() + "\n");
}
String replacedMessage = message.replace("${user}", userBuilder.toString());
replacedMessage = replacedMessage.replace("${result}", build.getResult().toString());
replacedMessage = replacedMessage.replace("${project}", build.getProject().getName());
replacedMessage = replacedMessage.replace("${number}", String.valueOf(build.number));
replacedMessage = replacedMessage.replace("${url}", JenkinsLocationConfiguration.get().getUrl() + build.getUrl());
replacedMessage = replacedMessage.replace("${changeSet}", changeSetBuilder.toString());
return replacedMessage;
}