Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
6d2a3eb7
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6d2a3eb7
编写于
5月 24, 2010
作者:
W
weijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6882687: KerberosTime too imprecise
Reviewed-by: valeriep
上级
98fdc610
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
86 addition
and
14 deletion
+86
-14
src/share/classes/sun/security/krb5/internal/KerberosTime.java
...hare/classes/sun/security/krb5/internal/KerberosTime.java
+33
-14
test/sun/security/krb5/MicroTime.java
test/sun/security/krb5/MicroTime.java
+53
-0
未找到文件。
src/share/classes/sun/security/krb5/internal/KerberosTime.java
浏览文件 @
6d2a3eb7
...
@@ -57,11 +57,20 @@ import java.io.IOException;
...
@@ -57,11 +57,20 @@ import java.io.IOException;
* specification available at
* specification available at
* <a href="http://www.ietf.org/rfc/rfc4120.txt">
* <a href="http://www.ietf.org/rfc/rfc4120.txt">
* http://www.ietf.org/rfc/rfc4120.txt</a>.
* http://www.ietf.org/rfc/rfc4120.txt</a>.
*
* The implementation also includes the microseconds info so that the
* same class can be used as a precise timestamp in Authenticator etc.
*/
*/
public
class
KerberosTime
implements
Cloneable
{
public
class
KerberosTime
implements
Cloneable
{
private
long
kerberosTime
;
// milliseconds since epoch, a Date.getTime() value
private
long
kerberosTime
;
// milliseconds since epoch, a Date.getTime() value
private
int
microSeconds
;
// the last three digits of the microsecond value
// The time when this class is loaded. Used in setNow()
private
static
final
long
initMilli
=
System
.
currentTimeMillis
();
private
static
final
long
initMicro
=
System
.
nanoTime
()
/
1000
;
private
static
long
syncTime
;
private
static
long
syncTime
;
private
static
boolean
DEBUG
=
Krb5
.
DEBUG
;
private
static
boolean
DEBUG
=
Krb5
.
DEBUG
;
...
@@ -77,9 +86,13 @@ public class KerberosTime implements Cloneable {
...
@@ -77,9 +86,13 @@ public class KerberosTime implements Cloneable {
kerberosTime
=
time
;
kerberosTime
=
time
;
}
}
private
KerberosTime
(
long
time
,
int
micro
)
{
kerberosTime
=
time
;
microSeconds
=
micro
;
}
public
Object
clone
()
{
public
Object
clone
()
{
return
new
KerberosTime
(
kerberosTime
);
return
new
KerberosTime
(
kerberosTime
,
microSeconds
);
}
}
// This constructor is used in the native code
// This constructor is used in the native code
...
@@ -109,8 +122,8 @@ public class KerberosTime implements Cloneable {
...
@@ -109,8 +122,8 @@ public class KerberosTime implements Cloneable {
// | | | | | | |
// | | | | | | |
// 0 4 6 8 | | |
// 0 4 6 8 | | |
// 10 | |
// 10 | |
//
12 |
// 12 |
//
14
// 14
if
(
time
.
length
()
!=
15
)
if
(
time
.
length
()
!=
15
)
throw
new
Asn1Exception
(
Krb5
.
ASN1_BAD_TIMEFORMAT
);
throw
new
Asn1Exception
(
Krb5
.
ASN1_BAD_TIMEFORMAT
);
...
@@ -148,11 +161,8 @@ public class KerberosTime implements Cloneable {
...
@@ -148,11 +161,8 @@ public class KerberosTime implements Cloneable {
public
KerberosTime
(
boolean
initToNow
)
{
public
KerberosTime
(
boolean
initToNow
)
{
if
(
initToNow
)
{
if
(
initToNow
)
{
Date
temp
=
new
Date
();
setNow
();
setTime
(
temp
);
}
}
else
kerberosTime
=
0
;
}
}
/**
/**
...
@@ -192,10 +202,12 @@ public class KerberosTime implements Cloneable {
...
@@ -192,10 +202,12 @@ public class KerberosTime implements Cloneable {
public
void
setTime
(
Date
time
)
{
public
void
setTime
(
Date
time
)
{
kerberosTime
=
time
.
getTime
();
// (time.getTimezoneOffset() * 60000L);
kerberosTime
=
time
.
getTime
();
// (time.getTimezoneOffset() * 60000L);
microSeconds
=
0
;
}
}
public
void
setTime
(
long
time
)
{
public
void
setTime
(
long
time
)
{
kerberosTime
=
time
;
kerberosTime
=
time
;
microSeconds
=
0
;
}
}
public
Date
toDate
()
{
public
Date
toDate
()
{
...
@@ -205,16 +217,18 @@ public class KerberosTime implements Cloneable {
...
@@ -205,16 +217,18 @@ public class KerberosTime implements Cloneable {
}
}
public
void
setNow
()
{
public
void
setNow
()
{
Date
temp
=
new
Date
();
long
microElapsed
=
System
.
nanoTime
()
/
1000
-
initMicro
;
setTime
(
temp
);
setTime
(
initMilli
+
microElapsed
/
1000
);
microSeconds
=
(
int
)(
microElapsed
%
1000
);
}
}
public
int
getMicroSeconds
()
{
public
int
getMicroSeconds
()
{
Long
temp_long
=
new
Long
((
kerberosTime
%
1000L
)
*
1000L
);
Long
temp_long
=
new
Long
((
kerberosTime
%
1000L
)
*
1000L
);
return
temp_long
.
intValue
();
return
temp_long
.
intValue
()
+
microSeconds
;
}
}
public
void
setMicroSeconds
(
int
usec
)
{
public
void
setMicroSeconds
(
int
usec
)
{
microSeconds
=
usec
%
1000
;
Integer
temp_int
=
new
Integer
(
usec
);
Integer
temp_int
=
new
Integer
(
usec
);
long
temp_long
=
temp_int
.
longValue
()
/
1000L
;
long
temp_long
=
temp_int
.
longValue
()
/
1000L
;
kerberosTime
=
kerberosTime
-
(
kerberosTime
%
1000L
)
+
temp_long
;
kerberosTime
=
kerberosTime
-
(
kerberosTime
%
1000L
)
+
temp_long
;
...
@@ -222,6 +236,7 @@ public class KerberosTime implements Cloneable {
...
@@ -222,6 +236,7 @@ public class KerberosTime implements Cloneable {
public
void
setMicroSeconds
(
Integer
usec
)
{
public
void
setMicroSeconds
(
Integer
usec
)
{
if
(
usec
!=
null
)
{
if
(
usec
!=
null
)
{
microSeconds
=
usec
.
intValue
()
%
1000
;
long
temp_long
=
usec
.
longValue
()
/
1000L
;
long
temp_long
=
usec
.
longValue
()
/
1000L
;
kerberosTime
=
kerberosTime
-
(
kerberosTime
%
1000L
)
+
temp_long
;
kerberosTime
=
kerberosTime
-
(
kerberosTime
%
1000L
)
+
temp_long
;
}
}
...
@@ -262,7 +277,9 @@ public class KerberosTime implements Cloneable {
...
@@ -262,7 +277,9 @@ public class KerberosTime implements Cloneable {
}
}
public
boolean
greaterThan
(
KerberosTime
time
)
{
public
boolean
greaterThan
(
KerberosTime
time
)
{
return
kerberosTime
>
time
.
kerberosTime
;
return
kerberosTime
>
time
.
kerberosTime
||
kerberosTime
==
time
.
kerberosTime
&&
microSeconds
>
time
.
microSeconds
;
}
}
public
boolean
equals
(
Object
obj
)
{
public
boolean
equals
(
Object
obj
)
{
...
@@ -274,15 +291,17 @@ public class KerberosTime implements Cloneable {
...
@@ -274,15 +291,17 @@ public class KerberosTime implements Cloneable {
return
false
;
return
false
;
}
}
return
kerberosTime
==
((
KerberosTime
)
obj
).
kerberosTime
;
return
kerberosTime
==
((
KerberosTime
)
obj
).
kerberosTime
&&
microSeconds
==
((
KerberosTime
)
obj
).
microSeconds
;
}
}
public
int
hashCode
()
{
public
int
hashCode
()
{
return
37
*
17
+
(
int
)(
kerberosTime
^
(
kerberosTime
>>>
32
));
int
result
=
37
*
17
+
(
int
)(
kerberosTime
^
(
kerberosTime
>>>
32
));
return
result
*
17
+
microSeconds
;
}
}
public
boolean
isZero
()
{
public
boolean
isZero
()
{
return
kerberosTime
==
0
;
return
kerberosTime
==
0
&&
microSeconds
==
0
;
}
}
public
int
getSeconds
()
{
public
int
getSeconds
()
{
...
...
test/sun/security/krb5/MicroTime.java
0 → 100644
浏览文件 @
6d2a3eb7
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6882687
* @summary KerberosTime too imprecise
*/
import
sun.security.krb5.internal.KerberosTime
;
public
class
MicroTime
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// We count how many different KerberosTime values
// can be acquired within one second.
KerberosTime
t1
=
new
KerberosTime
(
true
);
KerberosTime
last
=
t1
;
int
count
=
0
;
while
(
true
)
{
KerberosTime
t2
=
new
KerberosTime
(
true
);
if
(
t2
.
getTime
()
-
t1
.
getTime
()
>
1000
)
break
;
if
(!
last
.
equals
(
t2
))
{
last
=
t2
;
count
++;
}
}
// We believe a nice KerberosTime can at least tell the
// difference of 100 musec.
if
(
count
<
10000
)
{
throw
new
Exception
(
"What? only "
+
(
1000000
/
count
)
+
" musec precision?"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录