com.jeesuite.common.util.TokenGenerator Java Examples

The following examples show how to use com.jeesuite.common.util.TokenGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogContext.java    From oneplatform with Apache License 2.0 6 votes vote down vote up
public static void start(HttpServletRequest request) {
	if(!request.getMethod().equals(HttpMethod.POST.name()))return;
	LogObject log = holder.get();
	if (log == null) {
		log = new LogObject();
		log.setRequestTime(new Date());
		holder.set(log);
	}

	String requestId = request.getHeader("x-request-id");
	if (requestId == null) {
		requestId = TokenGenerator.generate();
		log.setEntrylog(true);
	}
	log.setRequestId(requestId);
	log.setRequestIp(IpUtils.getIpAddr(request));
	log.setUri(request.getRequestURI());
	log.setOrigin(request.getHeader(HttpHeaders.REFERER));
	UserSession session = LoginContext.getUserSession();
	if(session != null && !session.isAnonymous()){
		log.setRequestUid(LoginContext.getIntFormatUserId());
		log.setRequestUname(LoginContext.getUserName());
	}
}
 
Example #2
Source File: WebUtils.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> getCustomHeaders(){
	Map<String, String> headers = new HashMap<>();
	 HttpServletRequest request = RequestContextHelper.getRequest();
	Enumeration<String> headerNames = request.getHeaderNames();
	 while(headerNames.hasMoreElements()){
		 String headerName = headerNames.nextElement().toLowerCase();
		 if(headerName.startsWith(WebConstants.HEADER_PREFIX)){				 
			 String headerValue = request.getHeader(headerName);
			 if(headerValue != null)headers.put(headerName, headerValue);
		 }
	 }
	 //
	 headers.put(WebConstants.HEADER_INVOKER_IP, IpUtils.getLocalIpAddr());
	 
	 if(!headers.containsKey(WebConstants.HEADER_AUTH_TOKEN)){			 
		 headers.put(WebConstants.HEADER_AUTH_TOKEN, TokenGenerator.generateWithSign());
	 }
	 
	 return headers;
}
 
Example #3
Source File: LoginSession.java    From oneplatform with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	LoginSession session = new LoginSession();
	session.setSessionId(TokenGenerator.generate());
	session.setUserId(1000);
	session.setUserName("周大福");
	String encodeString = session.toEncodeString();
	System.out.println(encodeString);
	LoginSession session2 = decode(encodeString);
	System.out.println(session2);

	
}
 
Example #4
Source File: SecurityOauth2Manager.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
public AccessToken createAccessToken(BaseUserInfo user){
	AccessToken accessToken = new AccessToken();
	accessToken.setAccess_token(TokenGenerator.generate());
	accessToken.setRefresh_token(TokenGenerator.generate());
	accessToken.setExpires_in(TOKEN_EXPIRED_SECONDS);
	tokenCache.setObject(accessToken.getAccess_token(), accessToken);
	return accessToken;
}
 
Example #5
Source File: SecurityCryptUtils.java    From oneplatform with Apache License 2.0 4 votes vote down vote up
public static String generateAuthCode(){
	String str = DigestUtils.md5Short(TokenGenerator.generate()).concat(String.valueOf(System.currentTimeMillis()));	
	return SecurityCryptUtils.encrypt(str);
}
 
Example #6
Source File: ConfigcenterContext.java    From jeesuite-config with Apache License 2.0 4 votes vote down vote up
public String buildTokenParameter(String url){
	if(tokenCryptKey == null)return url;
	return url + (url.contains("?") ? "&" : "?") + "authtoken=" + TokenGenerator.generateWithSign("jeesuite.configcenter");
}
 
Example #7
Source File: DefaultMessage.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public DefaultMessage(Serializable body) {
	this(TokenGenerator.generate(), body);
}
 
Example #8
Source File: DefaultMessage.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public DefaultMessage(String msgId, Serializable body) {
	this.msgId = StringUtils.isBlank(msgId) ? TokenGenerator.generate() : msgId;
	this.body = body;
}
 
Example #9
Source File: DefaultMessage.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public String getMsgId() {
	if(StringUtils.isBlank(msgId)){
		msgId =  TokenGenerator.generate();
	}
	return msgId;
}
 
Example #10
Source File: SecurityTicketManager.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public String setTicketObject(Object ticketObject){
	String ticket = TokenGenerator.generate();
	cache.setObject(ticket, ticketObject);
	return ticket;
}
 
Example #11
Source File: UserSession.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public static UserSession create(){
	UserSession session = new UserSession();
	session.sessionId = TokenGenerator.generate();
	return session;
}
 
Example #12
Source File: SecurityOauth2Manager.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public String createOauth2AuthCode(Serializable userId){
	String authCode = TokenGenerator.generateWithSign();
	cache.setString(authCode, userId.toString());
	return authCode;
}