public void save() throws IOException { user.save(); }
public void save() throws IOException { user.save(); }
public synchronized void addIdentifier(String id) throws IOException { identifiers.add(id); user.save(); } }
/** * Removes the recorded information */ public void invalidate() throws IOException { if (roles!=null) { roles = null; timestamp = System.currentTimeMillis(); user.save(); } }
/** * Updates the user object by adding a property. */ public synchronized void addProperty(@Nonnull UserProperty p) throws IOException { UserProperty old = getProperty(p.getClass()); List<UserProperty> ps = new ArrayList<>(properties); if (old != null) ps.remove(old); ps.add(p); p.setUser(this); properties = ps; save(); }
/** * Persist the information with the new {@link UserDetails}. */ public void update(@Nonnull Authentication auth) throws IOException { List<String> roles = new ArrayList<String>(); for (GrantedAuthority ga : auth.getAuthorities()) { roles.add(ga.getAuthority()); } String[] a = roles.toArray(new String[roles.size()]); if (!Arrays.equals(this.roles,a)) { this.roles = a; this.timestamp = System.currentTimeMillis(); user.save(); } }
public static void createUser(User newUser) { newUser.save(); renderText("success"); } public static void updateUser(Long id, User user) { User dbUser = User.findById(id); dbUser.updateDetails(user); // some model logic you would write to do a safe merge dbUser.save(); renderText("success"); } public static void deleteUser(Long id) { // first check authority User.findById(id).delete(); renderText("success"); } public static void getUser(Long id) { User user = User.findById(id) renderJSON(user); } public static void getUserJSON(Long id) { User user = User.findById(id) renderJSON(user); }
public static void createUser(User newUser) { newUser.save(); user(newUser.id); } public static void updateUser(Long id, User user) { User dbUser = User.findById(id); dbUser.updateDetails(user); // some model logic you would write to do a safe merge dbUser.save(); user(id); } public static void deleteUser(Long id) { User.findById(id).delete(); renderText("success"); } public static void user(Long id) { User user = User.findById(id) render(user); }
/** * Retrieve a user by its ID, and create a new one if requested. * * @return An existing or created user. May be {@code null} if a user does not exist and * {@code create} is false. */ private static @Nullable User getOrCreateById(@Nonnull String id, @Nonnull String fullName, boolean create) { User u = AllUsers.get(id); if (u == null && (create || UserIdMapper.getInstance().isMapped(id))) { u = new User(id, fullName); AllUsers.put(id, u); if (!id.equals(fullName) && !UserIdMapper.getInstance().isMapped(id)) { try { u.save(); } catch (IOException x) { LOGGER.log(Level.WARNING, "Failed to save user configuration for " + id, x); } } } return u; }
/** * 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; }
/** * Accepts the new description. */ @RequirePOST public void doSubmitDescription(StaplerRequest req, StaplerResponse rsp) throws IOException { checkPermission(Jenkins.ADMINISTER); description = req.getParameter("description"); save(); rsp.sendRedirect("."); // go to the top page }
/** * Only usable if the user still has the legacy API token. * @deprecated Each token can be revoked now and new tokens can be requested without altering existing ones. */ @Deprecated public void changeApiToken() throws IOException { // just to keep the same level of security user.checkPermission(Jenkins.ADMINISTER); LOGGER.log(Level.FINE, "Deprecated usage of changeApiToken"); ApiTokenStore.HashedToken existingLegacyToken = tokenStore.getLegacyToken(); _changeApiToken(); tokenStore.regenerateTokenFromLegacy(apiToken); if(existingLegacyToken != null){ tokenStats.removeId(existingLegacyToken.getUuid()); } user.save(); }
@RequirePOST public HttpResponse doRevokeAllSelected(@JsonBody RevokeAllSelectedModel content) throws IOException { for (RevokeAllSelectedUserAndUuid value : content.values) { if (value.userId == null) { // special case not managed by JSONObject value.userId = "null"; } User user = User.getById(value.userId, false); if (user == null) { LOGGER.log(Level.INFO, "User not found id={0}", value.userId); } else { ApiTokenProperty apiTokenProperty = user.getProperty(ApiTokenProperty.class); if (apiTokenProperty == null) { LOGGER.log(Level.INFO, "User without apiTokenProperty found id={0}", value.userId); } else { ApiTokenStore.HashedToken revokedToken = apiTokenProperty.getTokenStore().revokeToken(value.uuid); if (revokedToken == null) { LOGGER.log(Level.INFO, "User without selected token id={0}, tokenUuid={1}", new Object[]{value.userId, value.uuid}); } else { apiTokenProperty.deleteApiToken(); user.save(); LOGGER.log(Level.INFO, "Revocation success for user id={0}, tokenUuid={1}", new Object[]{value.userId, value.uuid}); } } } } return HttpResponses.ok(); }
@RequirePOST public HttpResponse doRename(@AncestorInPath User u, @QueryParameter String tokenUuid, @QueryParameter String newName) throws IOException { // only current user + administrator can rename token u.checkPermission(Jenkins.ADMINISTER); if (StringUtils.isBlank(newName)) { return HttpResponses.errorJSON("The name cannot be empty"); } if(StringUtils.isBlank(tokenUuid)){ // using the web UI this should not occur return HttpResponses.errorWithoutStack(400, "The tokenUuid cannot be empty"); } ApiTokenProperty p = u.getProperty(ApiTokenProperty.class); if (p == null) { return HttpResponses.errorWithoutStack(400, "The user does not have any ApiToken yet, try generating one before."); } boolean renameOk = p.tokenStore.renameToken(tokenUuid, newName); if(!renameOk){ // that could potentially happen if the token is removed from another page // between your page loaded and your action return HttpResponses.errorJSON("No token found, try refreshing the page"); } u.save(); return HttpResponses.ok(); }
@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); }}); }
@RequirePOST public HttpResponse doRevoke(@AncestorInPath User u, @QueryParameter String tokenUuid) throws IOException { // only current user + administrator can revoke token u.checkPermission(Jenkins.ADMINISTER); if(StringUtils.isBlank(tokenUuid)){ // using the web UI this should not occur return HttpResponses.errorWithoutStack(400, "The tokenUuid cannot be empty"); } ApiTokenProperty p = u.getProperty(ApiTokenProperty.class); if (p == null) { return HttpResponses.errorWithoutStack(400, "The user does not have any ApiToken yet, try generating one before."); } ApiTokenStore.HashedToken revoked = p.tokenStore.revokeToken(tokenUuid); if(revoked != null){ if(revoked.isLegacy()){ // if the user revoked the API Token, we can delete it p.apiToken = null; } p.tokenStats.removeId(revoked.getUuid()); } u.save(); return HttpResponses.ok(); } }
} finally { if (admin != null) { admin.save(); // recreate this initial user if something failed
public synchronized void addIdentifier(String id) throws IOException { identifiers.add(id); user.save(); } }
public class Users extends Controller { public static void save(@Valid User user) { //check for user validaton user = user.save(); QueueService queueService = new QueueSerice(); queueService.publishMessage(user); } }