Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
931df26d
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
931df26d
编写于
7月 26, 2016
作者:
S
Stephen Connolly
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ENKINS-36923] Make the type safety easier to use
上级
31728891
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
82 addition
and
10 deletion
+82
-10
core/src/main/java/hudson/TcpSlaveAgentListener.java
core/src/main/java/hudson/TcpSlaveAgentListener.java
+1
-1
core/src/main/java/jenkins/model/identity/IdentityRootAction.java
.../main/java/jenkins/model/identity/IdentityRootAction.java
+4
-3
core/src/main/java/jenkins/model/identity/InstanceIdentityProvider.java
...java/jenkins/model/identity/InstanceIdentityProvider.java
+77
-6
未找到文件。
core/src/main/java/hudson/TcpSlaveAgentListener.java
浏览文件 @
931df26d
...
...
@@ -117,7 +117,7 @@ public final class TcpSlaveAgentListener extends Thread {
@Nullable
public
String
getIdentityPublicKey
()
{
InstanceIdentityProvider
<
RSAPublicKey
,
RSAPrivateKey
>
provider
=
InstanceIdentityProvider
.
get
(
RSAPrivateKey
.
class
);
InstanceIdentityProvider
.
get
(
InstanceIdentityProvider
.
RSA
);
RSAPublicKey
key
=
provider
==
null
?
null
:
provider
.
getPublicKey
();
return
key
==
null
?
null
:
new
String
(
Base64
.
encodeBase64
(
key
.
getEncoded
()),
Charset
.
forName
(
"UTF-8"
));
}
...
...
core/src/main/java/jenkins/model/identity/IdentityRootAction.java
浏览文件 @
931df26d
...
...
@@ -39,7 +39,8 @@ public class IdentityRootAction implements UnprotectedRootAction {
*/
@Override
public
String
getUrlName
()
{
return
InstanceIdentityProvider
.
get
(
RSAPrivateKey
.
class
)
==
null
?
null
:
"instance-identity"
;
return
InstanceIdentityProvider
.
get
(
InstanceIdentityProvider
.
RSA
)
==
null
?
null
:
"instance-identity"
;
}
/**
...
...
@@ -49,7 +50,7 @@ public class IdentityRootAction implements UnprotectedRootAction {
*/
public
String
getPublicKey
()
{
InstanceIdentityProvider
<
RSAPublicKey
,
RSAPrivateKey
>
provider
=
InstanceIdentityProvider
.
get
(
RSAPrivateKey
.
class
);
InstanceIdentityProvider
.
get
(
InstanceIdentityProvider
.
RSA
);
RSAPublicKey
key
=
provider
==
null
?
null
:
provider
.
getPublicKey
();
if
(
key
==
null
)
{
return
null
;
...
...
@@ -75,7 +76,7 @@ public class IdentityRootAction implements UnprotectedRootAction {
*/
public
String
getFingerprint
()
{
InstanceIdentityProvider
<
RSAPublicKey
,
RSAPrivateKey
>
provider
=
InstanceIdentityProvider
.
get
(
RSAPrivateKey
.
class
);
InstanceIdentityProvider
.
get
(
InstanceIdentityProvider
.
RSA
);
RSAPublicKey
key
=
provider
==
null
?
null
:
provider
.
getPublicKey
();
if
(
key
==
null
)
{
return
null
;
...
...
core/src/main/java/jenkins/model/identity/InstanceIdentityProvider.java
浏览文件 @
931df26d
...
...
@@ -29,8 +29,14 @@ import java.security.KeyPair;
import
java.security.PrivateKey
;
import
java.security.PublicKey
;
import
java.security.cert.X509Certificate
;
import
java.security.interfaces.DSAPrivateKey
;
import
java.security.interfaces.DSAPublicKey
;
import
java.security.interfaces.ECPrivateKey
;
import
java.security.interfaces.ECPublicKey
;
import
java.security.interfaces.RSAPrivateKey
;
import
java.security.interfaces.RSAPublicKey
;
import
javax.annotation.CheckForNull
;
import
javax.annotation.N
ullable
;
import
javax.annotation.N
onnull
;
/**
* A source of instance identity.
...
...
@@ -41,6 +47,22 @@ import javax.annotation.Nullable;
*/
public
abstract
class
InstanceIdentityProvider
<
PUB
extends
PublicKey
,
PRIV
extends
PrivateKey
>
implements
ExtensionPoint
{
/**
* RSA keys.
*/
public
static
final
KeyTypes
<
RSAPublicKey
,
RSAPrivateKey
>
RSA
=
new
KeyTypes
<>(
RSAPublicKey
.
class
,
RSAPrivateKey
.
class
);
/**
* DSA keys.
*/
public
static
final
KeyTypes
<
DSAPublicKey
,
DSAPrivateKey
>
DSA
=
new
KeyTypes
<>(
DSAPublicKey
.
class
,
DSAPrivateKey
.
class
);
/**
* EC keys
*/
public
static
final
KeyTypes
<
ECPublicKey
,
ECPrivateKey
>
EC
=
new
KeyTypes
<>(
ECPublicKey
.
class
,
ECPrivateKey
.
class
);
/**
* Gets the {@link KeyPair} that comprises the instance identity.
*
...
...
@@ -85,21 +107,70 @@ public abstract class InstanceIdentityProvider<PUB extends PublicKey, PRIV exten
/**
* Gets the provider of the required identity type.
*
* @param
keyType the type of private key
.
* @param <PUB>
the type of public key.
* @param <PRIV>
the type of private key.
* @param
type the type of keys
.
* @param <PUB> the type of public key.
* @param <PRIV> the type of private key.
* @return the provider or {@code null} if no provider of the specified type is available.
*/
@CheckForNull
@SuppressWarnings
(
"unchecked"
)
public
static
<
PUB
extends
PublicKey
,
PRIV
extends
PrivateKey
>
InstanceIdentityProvider
<
PUB
,
PRIV
>
get
(
Class
<
PRIV
>
keyT
ype
)
{
@Nonnull
KeyTypes
<
PUB
,
PRIV
>
t
ype
)
{
for
(
InstanceIdentityProvider
provider
:
ExtensionList
.
lookup
(
InstanceIdentityProvider
.
class
))
{
KeyPair
keyPair
=
provider
.
getKeyPair
();
if
(
keyPair
!=
null
&&
keyType
.
isInstance
(
keyPair
.
getPrivate
()))
{
if
(
keyPair
!=
null
&&
type
.
pubKeyType
.
isInstance
(
keyPair
.
getPublic
())
&&
type
.
privKeyType
.
isInstance
(
keyPair
.
getPrivate
()))
{
return
(
InstanceIdentityProvider
<
PUB
,
PRIV
>)
provider
;
}
}
return
null
;
}
/**
* Holds information about the paired keytypes that can be used to form the various identity keys.
*
* @param <PUB> the type of public key.
* @param <PRIV> the type of private key.
*/
public
static
final
class
KeyTypes
<
PUB
extends
PublicKey
,
PRIV
extends
PrivateKey
>
{
/**
* The interface for the public key.
*/
private
final
Class
<
PUB
>
pubKeyType
;
/**
* The interface for the private key.
*/
private
final
Class
<
PRIV
>
privKeyType
;
/**
* Constructor.
*
* @param pubKeyType the interface for the public key.
* @param privKeyType the interface for the private key.
*/
private
KeyTypes
(
Class
<
PUB
>
pubKeyType
,
Class
<
PRIV
>
privKeyType
)
{
this
.
pubKeyType
=
pubKeyType
;
this
.
privKeyType
=
privKeyType
;
}
/**
* Gets the interface for the public key.
*
* @return the interface for the public key.
*/
public
Class
<
PUB
>
getPublicKeyClass
()
{
return
pubKeyType
;
}
/**
* Gets the interface for the private key.
*
* @return the interface for the private key.
*/
public
Class
<
PRIV
>
getPrivateKeyClass
()
{
return
privKeyType
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录