Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
e1d175c9
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
未验证
提交
e1d175c9
编写于
12月 03, 2017
作者:
O
Oleg Nenashev
提交者:
GitHub
12月 03, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3140 from oleg-nenashev/javadoc/CanonicalUserIdResolver
Document and refactor the CanonicalIdResolver extension point
上级
61712210
80b9ee6f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
13 deletion
+61
-13
core/src/main/java/hudson/model/User.java
core/src/main/java/hudson/model/User.java
+61
-13
未找到文件。
core/src/main/java/hudson/model/User.java
浏览文件 @
e1d175c9
...
...
@@ -405,23 +405,16 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
* An existing or created user. May be {@code null} if a user does not exist and
* {@code create} is false.
*/
public
static
@Nullable
User
get
(
String
idOrFullName
,
boolean
create
,
Map
context
)
{
public
static
@Nullable
User
get
(
String
idOrFullName
,
boolean
create
,
@Nonnull
Map
context
)
{
if
(
idOrFullName
==
null
)
return
null
;
//
sort resolvers by priority
List
<
CanonicalIdResolver
>
resolvers
=
new
ArrayList
<
CanonicalIdResolver
>(
ExtensionList
.
lookup
(
CanonicalIdResolver
.
class
));
Collections
.
sort
(
resolvers
);
//
TODO: In many cases the method should receive the canonical ID.
// Maybe it makes sense to try AllUsers.byName().get(idkey) before invoking all resolvers and other stuff
// oleg-nenashev: FullNameResolver with User.getAll() loading and iteration makes me think it's a good idea.
String
id
=
null
;
for
(
CanonicalIdResolver
resolver
:
resolvers
)
{
id
=
resolver
.
resolveCanonicalId
(
idOrFullName
,
context
);
if
(
id
!=
null
)
{
LOGGER
.
log
(
Level
.
FINE
,
"{0} mapped {1} to {2}"
,
new
Object
[]
{
resolver
,
idOrFullName
,
id
});
break
;
}
}
String
id
=
CanonicalIdResolver
.
resolve
(
idOrFullName
,
context
);
// DefaultUserCanonicalIdResolver will always return a non-null id if all other CanonicalIdResolver failed
if
(
id
==
null
)
{
throw
new
IllegalStateException
(
"The user id should be always non-null thanks to DefaultUserCanonicalIdResolver"
);
...
...
@@ -1081,6 +1074,16 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
}
/**
* Resolves User IDs by ID, full names or other strings.
*
* This extension point may be useful to map SCM user names to Jenkins {@link User} IDs.
* Currently the extension point is used in {@link User#get(String, boolean, Map)}.
*
* @since 1.479
* @see jenkins.model.DefaultUserCanonicalIdResolver
* @see FullNameIdResolver
*/
public
static
abstract
class
CanonicalIdResolver
extends
AbstractDescribableImpl
<
CanonicalIdResolver
>
implements
ExtensionPoint
,
Comparable
<
CanonicalIdResolver
>
{
/**
...
...
@@ -1090,6 +1093,7 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
*/
public
static
final
String
REALM
=
"realm"
;
@Override
public
int
compareTo
(
CanonicalIdResolver
o
)
{
// reverse priority order
int
i
=
getPriority
();
...
...
@@ -1101,12 +1105,56 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
* extract user ID from idOrFullName with help from contextual infos.
* can return <code>null</code> if no user ID matched the input
*/
public
abstract
@CheckForNull
String
resolveCanonicalId
(
String
idOrFullName
,
Map
<
String
,
?>
context
);
public
abstract
@CheckForNull
String
resolveCanonicalId
(
String
idOrFullName
,
@Nonnull
Map
<
String
,
?>
context
);
/**
* Gets priority of the resolver.
* Higher priority means that it will be checked earlier.
*
* Overriding methods must not use {@link Integer#MIN_VALUE}, because it will cause collisions
* with {@link jenkins.model.DefaultUserCanonicalIdResolver}.
*
* @return Priority of the resolver.
*/
public
int
getPriority
()
{
return
1
;
}
//TODO: It is too late to use Extension Point ordinals, right?
//Such sorting and collection rebuild is not good for User#get(...) method performance.
/**
* Gets all extension points, sorted by priority.
* @return Sorted list of extension point implementations.
* @since TODO
*/
public
static
List
<
CanonicalIdResolver
>
all
()
{
List
<
CanonicalIdResolver
>
resolvers
=
new
ArrayList
<>(
ExtensionList
.
lookup
(
CanonicalIdResolver
.
class
));
Collections
.
sort
(
resolvers
);
return
resolvers
;
}
/**
* Resolves users using all available {@link CanonicalIdResolver}s.
* @param idOrFullName ID or full name of the user
* @param context Context
* @return Resolved User ID or {@code null} if the user ID cannot be resolved.
* @since TODO
*/
@CheckForNull
public
static
String
resolve
(
@Nonnull
String
idOrFullName
,
@Nonnull
Map
<
String
,
?>
context
)
{
for
(
CanonicalIdResolver
resolver
:
CanonicalIdResolver
.
all
())
{
//TODO: add try/catch for Runtime exceptions? It should not happen now && it may cause performance degradation
String
id
=
resolver
.
resolveCanonicalId
(
idOrFullName
,
context
);
if
(
id
!=
null
)
{
LOGGER
.
log
(
Level
.
FINE
,
"{0} mapped {1} to {2}"
,
new
Object
[]
{
resolver
,
idOrFullName
,
id
});
return
id
;
}
}
// De-facto it is not going to happen OOTB, because the current DefaultUserCanonicalIdResolver
// always returns a value. But we still need to check nulls if somebody disables the extension point
return
null
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录