public String getUsername() { return user.getId(); }
Replacer(User u) { id = u.getId(); }
public UserInterruption(@Nonnull User user) { this.user = user.getId(); }
public UserCause(@CheckForNull User user, @CheckForNull String message) { this( user != null ? user.getId() : null, message != null ? " : " + message : "" ); }
/** * Constructor, which uses the current {@link User}. */ public UserIdCause() { User user = User.current(); this.userId = (user == null) ? null : user.getId(); }
private @CheckForNull File getUserFolder(){ File userFolder = parent; if (userFolder == null && this.user != null) { userFolder = user.getUserFolder(); if (userFolder == null) { LOGGER.log(Level.INFO, "No user folder yet for user {0}", user.getId()); return null; } this.parent = userFolder; } return userFolder; }
@Nonnull private String getUserIdOrUnknown() { return userId != null ? userId : User.getUnknown().getId(); }
@SuppressWarnings("deprecation") private Object readResolve() throws ObjectStreamException { if (user != null) { String id = user.getId(); if (id != null) { userId = id; } else { // The user field is not properly deserialized so id may be missing. Look the user up by fullname User user = User.get(this.user.getFullName(), true, Collections.emptyMap()); userId = user.getId(); } this.user = null; } return this; } }
@Override public String resolveCanonicalId(String idOrFullName, Map<String, ?> context) { for (User user : getAll()) { if (idOrFullName.equals(user.getFullName())) return user.getId(); } return null; }
private ApiTokenProperty forceNewInstance(User user, boolean withLegacyToken) { if(withLegacyToken){ return new ApiTokenProperty(API_KEY_SEED.mac(user.getId())); }else{ return new ApiTokenProperty(null); } }
@Nonnull @Restricted(NoExternalUse.class) /*package*/ String getApiTokenInsecure() { if(apiToken == null){ return Messages.ApiTokenProperty_NoLegacyToken(); } String p = apiToken.getPlainText(); if (p.equals(Util.getDigestOf(Jenkins.getInstance().getSecretKey()+":"+user.getId()))) { // if the current token is the initial value created by pre SECURITY-49 Jenkins, we can't use that. // force using the newer value apiToken = Secret.fromString(p=API_KEY_SEED.mac(user.getId())); } return Util.getDigestOf(p); }
/** * Only for legacy token */ private boolean hasPermissionToSeeToken() { // Administrators can do whatever they want if (SHOW_LEGACY_TOKEN_TO_ADMINS && Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { return true; } User current = User.current(); if (current == null) { // Anonymous return false; } // SYSTEM user is always eligible to see tokens if (Jenkins.getAuthentication() == ACL.SYSTEM) { return true; } return User.idStrategy().equals(user.getId(), current.getId()); }
/** * 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; }
@Restricted(NoExternalUse.class) public boolean hasCurrentUserRightToGenerateNewToken(User propertyOwner){ if (ADMIN_CAN_GENERATE_NEW_TOKENS && Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { return true; } User currentUser = User.current(); if (currentUser == null) { // Anonymous return false; } if (Jenkins.getAuthentication() == ACL.SYSTEM) { // SYSTEM user is always eligible to see tokens return true; } return User.idStrategy().equals(propertyOwner.getId(), currentUser.getId()); }
/** * 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; }
/** * true if {@link AbstractBuild#hasParticipant} or {@link hudson.model.Cause.UserIdCause} */ private boolean relatedTo(@Nonnull AbstractBuild<?, ?> b) { if (b.hasParticipant(this)) { return true; } for (Cause cause : b.getCauses()) { if (cause instanceof Cause.UserIdCause) { String userId = ((Cause.UserIdCause) cause).getUserId(); if (userId != null && idStrategy().equals(userId, getId())) { return true; } } } return false; }
/** * Lets the current user silently login as the given user and report back accordingly. */ @SuppressWarnings("ACL.impersonate") private void loginAndTakeBack(StaplerRequest req, StaplerResponse rsp, User u) throws ServletException, IOException { HttpSession session = req.getSession(false); if (session != null) { // avoid session fixation session.invalidate(); } req.getSession(true); // ... and let him login Authentication a = new UsernamePasswordAuthenticationToken(u.getId(),req.getParameter("password1")); a = this.getSecurityComponents().manager.authenticate(a); SecurityContextHolder.getContext().setAuthentication(a); SecurityListener.fireLoggedIn(u.getId()); // then back to top req.getView(this,"success.jelly").forward(req,rsp); }
@Override protected int run() throws Exception { final Jenkins jenkins = Jenkins.getActiveInstance(); jenkins.checkPermission(Computer.CREATE); final Node newNode = (Node) Jenkins.XSTREAM2.fromXML(stdin); if (nodeName != null) { // Using deprecated method but it's contract is preserved newNode.setNodeName(nodeName); } if(newNode instanceof Slave) { //change userId too User user = User.current(); ((Slave) newNode).setUserId(user==null ? "anonymous" : user.getId()); } if (jenkins.getNode(newNode.getNodeName()) != null) { throw new IllegalStateException("Node '" + newNode.getNodeName() + "' already exists"); } jenkins.addNode(newNode); return 0; }
@Override protected synchronized JSON data() { JSONArray r = new JSONArray(); for (User u : modified) { UserInfo i = users.get(u); JSONObject entry = new JSONObject(). accumulate("id", u.getId()). accumulate("fullName", u.getFullName()). accumulate("url", u.getUrl()). accumulate("avatar", i.avatar != null ? i.avatar : Stapler.getCurrentRequest().getContextPath() + Functions.getResourcePath() + "/images/" + iconSize + "/user.png"). accumulate("timeSortKey", i.getTimeSortKey()). accumulate("lastChangeTimeString", i.getLastChangeTimeString()); Job<?,?> p = i.getJob(); if (p != null) { entry.accumulate("projectUrl", p.getUrl()).accumulate("projectFullDisplayName", p.getFullDisplayName()); } r.add(entry); } modified.clear(); return r; }