• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aspectran / aspectran / #3633

30 Jul 2024 08:15PM CUT coverage: 34.073% (-0.002%) from 34.075%
#3633

Pull #683

github

web-flow
Bump jetty.version from 12.0.11 to 12.0.12

Bumps `jetty.version` from 12.0.11 to 12.0.12.

Updates `org.eclipse.jetty.ee10:jetty-ee10-servlets` from 12.0.11 to 12.0.12

Updates `org.eclipse.jetty.ee10:jetty-ee10-webapp` from 12.0.11 to 12.0.12

Updates `org.eclipse.jetty.ee10.websocket:jetty-ee10-websocket-jakarta-server` from 12.0.11 to 12.0.12

---
updated-dependencies:
- dependency-name: org.eclipse.jetty.ee10:jetty-ee10-servlets
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: org.eclipse.jetty.ee10:jetty-ee10-webapp
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: org.eclipse.jetty.ee10.websocket:jetty-ee10-websocket-jakarta-server
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #683: Bump jetty.version from 12.0.11 to 12.0.12

13345 of 39166 relevant lines covered (34.07%)

0.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.7
/core/src/main/java/com/aspectran/core/component/session/SessionIdGenerator.java
1
/*
2
 * Copyright (c) 2008-2024 The Aspectran Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.aspectran.core.component.session;
17

18
import com.aspectran.utils.annotation.jsr305.NonNull;
19
import com.aspectran.utils.logging.Logger;
20
import com.aspectran.utils.logging.LoggerFactory;
21

22
import java.security.SecureRandom;
23
import java.util.Random;
24
import java.util.concurrent.atomic.AtomicLong;
25

26
/**
27
 * The Session ID Generator.
28
 *
29
 * <p>Created: 2017. 6. 12.</p>
30
 */
31
public class SessionIdGenerator {
32

33
    private static final Logger logger = LoggerFactory.getLogger(SessionIdGenerator.class);
1✔
34

35
    private static final AtomicLong COUNTER = new AtomicLong();
1✔
36

37
    private final String workerName;
38

39
    private final Random random;
40

41
    private boolean weakRandom;
42

43
    public SessionIdGenerator() {
44
        this(null);
×
45
    }
×
46

47
    public SessionIdGenerator(String workerName) {
1✔
48
        if (workerName != null && workerName.contains(".")) {
1✔
49
            throw new IllegalArgumentException("Worker name cannot contain '.'");
×
50
        }
51
        this.workerName = workerName;
1✔
52
        this.random = initRandom();
1✔
53
    }
1✔
54

55
    /**
56
     * Returns a new unique session id.
57
     * @param seedTerm the seed for RNG
58
     * @return a new unique session id
59
     */
60
    public String createSessionId(long seedTerm) {
61
        synchronized (random) {
1✔
62
            long r0;
63
            if (weakRandom) {
1✔
64
                r0 = hashCode() ^ Runtime.getRuntime().freeMemory() ^ random.nextInt() ^ (seedTerm << 32);
×
65
            } else {
66
                r0 = random.nextLong();
1✔
67
            }
68
            if (r0 < 0) {
1✔
69
                r0 = -r0;
×
70
            }
71
            long r1;
72
            if (weakRandom) {
1✔
73
                r1 = hashCode() ^ Runtime.getRuntime().freeMemory() ^ random.nextInt() ^ (seedTerm << 32);
×
74
            } else {
75
                r1 = random.nextLong();
1✔
76
            }
77
            if (r1 < 0) {
1✔
78
                r1 = -r1;
1✔
79
            }
80
            StringBuilder id = new StringBuilder();
1✔
81
            id.append(Long.toString(r0, Character.MAX_RADIX));
1✔
82
            id.append(Long.toString(r1, Character.MAX_RADIX));
1✔
83
            id.append(COUNTER.getAndIncrement());
1✔
84
            if (workerName != null) {
1✔
85
                id.append(".").append(workerName);
1✔
86
            }
87
            return id.toString();
1✔
88
        }
89
    }
90

91
    /**
92
     * Set up a random number generator for the session ids.
93
     * By preference, use a SecureRandom but allow to be injected.
94
     */
95
    @NonNull
96
    private Random initRandom() {
97
        try {
98
            return new SecureRandom();
1✔
99
        } catch (Exception e) {
×
100
            logger.warn("Could not generate SecureRandom for session-id randomness", e);
×
101
            weakRandom = true;
×
102
            return new Random();
×
103
        }
104
    }
105

106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc