Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011-2013, James Zhan 詹波 ( Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package com.jfinal.plugin.auth;
TODO 考虑改名为 SessionIdBuilder
public class AccessTokenBuilder {
	private static Random random;
    private static boolean weakRandom;
    private static int hashCode = new AccessTokenBuilder().hashCode();
    private AccessTokenBuilder() {
		try {
			// This operation may block on some systems with low entropy. See
			// this page for workaround suggestions:
			// System.out.println("Init SecureRandom.");
			 = new SecureRandom();
			 = false;
catch (Exception e) {
			 = new Random();
			 = true;
			..println("Could not generate SecureRandom for accessToken randomness");
	public static String getAccessToken(HttpServletRequest request) {
		String accessToken = null;
        while (accessToken == null || accessToken.length() == 0) {
            long r0 =  ? ( ^ Runtime.getRuntime().freeMemory() ^ .nextInt() ^ (((long)request.hashCode()) << 32)) : .nextLong();
            long r1 = .nextLong();
            if (r0 < 0) r0 = -r0;
            if (r1 < 0) r1 = -r1;
            accessToken = Long.toString(r0, 36) + Long.toString(r1, 36);
        return accessToken;
New to GrepCode? Check out our FAQ X