本文整理了Java中hudson.model.User.addProperty()
方法的一些代码示例,展示了User.addProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。User.addProperty()
方法的具体详情如下:
包路径:hudson.model.User
类名称:User
方法名:addProperty
[英]Updates the user object by adding a property.
[中]通过添加属性更新用户对象。
代码示例来源:origin: jenkinsci/jenkins
/**
* Creates a new account from a valid signup info. A signup info is valid if its {@link SignupInfo#errors}
* field is empty.
*
* @param si the valid signup info to create an account from
* @return a valid {@link User} object created from given signup info
* @throws IllegalArgumentException if an invalid signup info is passed
*/
private User createAccount(SignupInfo si) throws IOException {
if (!si.errors.isEmpty()) {
String messages = getErrorMessages(si);
throw new IllegalArgumentException("invalid signup info passed to createAccount(si): " + messages);
}
// register the user
User user = createAccount(si.username, si.password1);
user.setFullName(si.fullname);
if (isMailerPluginPresent()) {
try {
// legacy hack. mail support has moved out to a separate plugin
Class<?> up = Jenkins.getInstance().pluginManager.uberClassLoader.loadClass("hudson.tasks.Mailer$UserProperty");
Constructor<?> c = up.getDeclaredConstructor(String.class);
user.addProperty((UserProperty) c.newInstance(si.email));
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
user.save();
return user;
}
代码示例来源:origin: jenkinsci/jenkins
@Override
protected void loggedIn(@Nonnull String username) {
try {
// user should have been created but may not have been saved for some realms
// but as this is a callback of a successful login we can safely create the user.
User u = User.getById(username, true);
LastGrantedAuthoritiesProperty o = u.getProperty(LastGrantedAuthoritiesProperty.class);
if (o==null)
u.addProperty(o=new LastGrantedAuthoritiesProperty());
Authentication a = Jenkins.getAuthentication();
if (a!=null && a.getName().equals(username))
o.update(a); // just for defensive sanity checking
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to record granted authorities",e);
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Creates a new user account by registering a password to the user.
*/
public User createAccount(String userName, String password) throws IOException {
User user = User.getById(userName, true);
user.addProperty(Details.fromPlainPassword(password));
SecurityListener.fireUserCreated(user.getId());
return user;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Creates a new user account by registering a JBCrypt Hashed password with the user.
*
* @param userName The user's name
* @param hashedPassword A hashed password, must begin with <code>#jbcrypt:</code>
*/
public User createAccountWithHashedPassword(String userName, String hashedPassword) throws IOException {
if (!PASSWORD_ENCODER.isPasswordHashed(hashedPassword)) {
throw new IllegalArgumentException("this method should only be called with a pre-hashed password");
}
User user = User.getById(userName, true);
user.addProperty(Details.fromHashedPassword(hashedPassword));
SecurityListener.fireUserCreated(user.getId());
return user;
}
代码示例来源:origin: jenkinsci/jenkins
@RequirePOST
public HttpResponse doGenerateNewToken(@AncestorInPath User u, @QueryParameter String newTokenName) throws IOException {
if(!hasCurrentUserRightToGenerateNewToken(u)){
return HttpResponses.forbidden();
}
final String tokenName;
if (StringUtils.isBlank(newTokenName)) {
tokenName = String.format("Token created on %s", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()));
}else{
tokenName = newTokenName;
}
ApiTokenProperty p = u.getProperty(ApiTokenProperty.class);
if (p == null) {
p = forceNewInstance(u, false);
u.addProperty(p);
}
ApiTokenStore.TokenUuidAndPlainValue tokenUuidAndPlainValue = p.tokenStore.generateNewToken(tokenName);
u.save();
return HttpResponses.okJSON(new HashMap<String, String>() {{
put("tokenUuid", tokenUuidAndPlainValue.tokenUuid);
put("tokenName", tokenName);
put("tokenValue", tokenUuidAndPlainValue.plainValue);
}});
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Adds this identity to the specified user.
*/
public void addTo(User u) throws IOException {
FederatedLoginServiceUserProperty p = u.getProperty(getUserPropertyClass());
if (p==null) {
p = (FederatedLoginServiceUserProperty) UserProperty.all().find(getUserPropertyClass()).newInstance(u);
u.addProperty(p);
}
p.addIdentifier(getIdentifier());
}
代码示例来源:origin: jenkinsci/jenkins
/**
* @deprecated use {@link #doGenerateNewToken(User, String)} instead
*/
@Deprecated
@RequirePOST
public HttpResponse doChangeToken(@AncestorInPath User u, StaplerResponse rsp) throws IOException {
// you are the user or you have ADMINISTER permission
u.checkPermission(Jenkins.ADMINISTER);
LOGGER.log(Level.FINE, "Deprecated action /changeToken used, consider using /generateNewToken instead");
if(!mustDisplayLegacyApiToken(u)){
// user does not have legacy token and the capability to create one without an existing one is disabled
return HttpResponses.html(Messages.ApiTokenProperty_ChangeToken_CapabilityNotAllowed());
}
ApiTokenProperty p = u.getProperty(ApiTokenProperty.class);
if (p == null) {
p = forceNewInstance(u, true);
p.setUser(u);
u.addProperty(p);
} else {
// even if the user does not have legacy token, this method let some legacy system to regenerate one
p.changeApiToken();
}
rsp.setHeader("script","document.getElementById('apiToken').value='"+p.getApiToken()+"'");
return HttpResponses.html(p.hasPermissionToSeeToken()
? Messages.ApiTokenProperty_ChangeToken_Success()
: Messages.ApiTokenProperty_ChangeToken_SuccessHidden());
}
代码示例来源:origin: org.jenkins-ci.plugins/git
private void setMail(User user, String csAuthorEmail) throws IOException {
user.addProperty(new hudson.tasks.Mailer.UserProperty(csAuthorEmail));
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* Creates a new user account by registering a password to the user.
*/
public User createAccount(String userName, String password) throws IOException {
User user = User.getById(userName, true);
user.addProperty(Details.fromPlainPassword(password));
return user;
}
代码示例来源:origin: org.eclipse.hudson/hudson-core
/**
* Creates a new user account by registering a password to the user.
* @param userName
* @param password
* @return
* @throws java.io.IOException
*/
public User createAccount(String userName, String password) throws IOException {
User user = User.get(userName);
user.addProperty(Details.fromPlainPassword(password));
return user;
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
/**
* Creates a new user account by registering a password to the user.
*/
public User createAccount(String userName, String password) throws IOException {
User user = User.get(userName);
user.addProperty(Details.fromPlainPassword(password));
return user;
}
代码示例来源:origin: hudson/hudson-2.x
/**
* Creates a new user account by registering a password to the user.
*/
public User createAccount(String userName, String password) throws IOException {
User user = User.get(userName);
user.addProperty(Details.fromPlainPassword(password));
return user;
}
代码示例来源:origin: org.eclipse.hudson.main/hudson-core
/**
* Creates a new user account by registering a password to the user.
*/
public User createAccount(String userName, String password) throws IOException {
User user = User.get(userName);
user.addProperty(Details.fromPlainPassword(password));
return user;
}
代码示例来源:origin: jenkinsci/github-oauth-plugin
public static void put(@Nonnull User user, @Nonnull String accessToken) {
Log.debug("Populating the cache for username: " + user.getId());
try {
user.addProperty(new GithubAccessTokenProperty(accessToken));
} catch (IOException e) {
Log.warn("Received an exception when trying to add the GitHub access token to the user: " + user.getId(), e);
}
}
}
代码示例来源:origin: org.eclipse.hudson.main/hudson-core
/**
* Adds this identity to the specified user.
*/
public void addTo(User u) throws IOException {
FederatedLoginServiceUserProperty p = u.getProperty(getUserPropertyClass());
if (p==null) {
p = (FederatedLoginServiceUserProperty) UserProperty.all().find(getUserPropertyClass()).newInstance(u);
u.addProperty(p);
}
p.addIdentifier(getIdentifier());
}
代码示例来源:origin: hudson/hudson-2.x
/**
* Adds this identity to the specified user.
*/
public void addTo(User u) throws IOException {
FederatedLoginServiceUserProperty p = u.getProperty(getUserPropertyClass());
if (p==null) {
p = (FederatedLoginServiceUserProperty) UserProperty.all().find(getUserPropertyClass()).newInstance(u);
u.addProperty(p);
}
p.addIdentifier(getIdentifier());
}
代码示例来源:origin: org.eclipse.hudson/hudson-core
/**
* Adds this identity to the specified user.
*/
public void addTo(User u) throws IOException {
FederatedLoginServiceUserProperty p = u.getProperty(getUserPropertyClass());
if (p == null) {
p = (FederatedLoginServiceUserProperty) UserProperty.all().find(getUserPropertyClass()).newInstance(u);
u.addProperty(p);
}
p.addIdentifier(getIdentifier());
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* Adds this identity to the specified user.
*/
public void addTo(User u) throws IOException {
FederatedLoginServiceUserProperty p = u.getProperty(getUserPropertyClass());
if (p==null) {
p = (FederatedLoginServiceUserProperty) UserProperty.all().find(getUserPropertyClass()).newInstance(u);
u.addProperty(p);
}
p.addIdentifier(getIdentifier());
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
/**
* Adds this identity to the specified user.
*/
public void addTo(User u) throws IOException {
FederatedLoginServiceUserProperty p = u.getProperty(getUserPropertyClass());
if (p==null) {
p = (FederatedLoginServiceUserProperty) UserProperty.all().find(getUserPropertyClass()).newInstance(u);
u.addProperty(p);
}
p.addIdentifier(getIdentifier());
}
代码示例来源:origin: org.jenkins-ci.plugins/oic-auth
private UsernamePasswordAuthenticationToken loginAndSetUserData(String userName, GrantedAuthority[] authorities, IdToken idToken) throws IOException {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userName, "", authorities);
SecurityContextHolder.getContext().setAuthentication(token);
User u = User.get(token.getName());
String email = getField(idToken, emailFieldName);
if(email != null) {
u.addProperty(new Mailer.UserProperty(email));
}
String fullName = getField(idToken, fullNameFieldName);
if (fullName != null) {
u.setFullName(fullName);
}
return token;
}
内容来源于网络,如有侵权,请联系作者删除!