All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kawanfw.sql.api.server.session.SessionIdentifierGenerator Maven / Gradle / Ivy

/*
 * Copyright (c)2022 KawanSoft S.A.S. All rights reserved.
 * 
 * Use of this software is governed by the Business Source License included
 * in the LICENSE.TXT file in the project's root directory.
 *
 * Change Date: 2026-11-01
 *
 * On the date above, in accordance with the Business Source License, use
 * of this software will be governed by version 2.0 of the Apache License.
 */
package org.kawanfw.sql.api.server.session;

import java.security.SecureRandom;

/**
 * 
 * Session id generator with 26 long strings.
 * 

* Uses a static {@code SecureRandom}.
* Each call to {@code nextSessionId()} calls {@code SecureRandom#nextInt(int)}. *
* See Open Source Edition source * code. * * @author Nicolas de Pomereu * */ public class SessionIdentifierGenerator { private static final String AB = "0123456789abcdefghijklmnopqrstuvwxyz"; private static SecureRandom rnd = new SecureRandom(); /** * Returns the next session id using a {@code SecureRandom} * * @return the next session id using a {@code SecureRandom} */ public String nextSessionId() { return randomString(26); } private String randomString(int len) { StringBuilder sb = new StringBuilder(len); for (int i = 0; i < len; i++) sb.append(AB.charAt(rnd.nextInt(AB.length()))); return sb.toString(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy