Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
bded790f
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,发现更多精彩内容 >>
提交
bded790f
编写于
3月 11, 2014
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
User.impersonate() now does the loadUserDetailsByName call.
So ApiTokenFilter no longer needs to do that.
上级
b173e8d4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
22 deletion
+24
-22
core/src/main/java/hudson/model/User.java
core/src/main/java/hudson/model/User.java
+9
-2
core/src/main/java/jenkins/security/ApiTokenFilter.java
core/src/main/java/jenkins/security/ApiTokenFilter.java
+15
-20
未找到文件。
core/src/main/java/hudson/model/User.java
浏览文件 @
bded790f
...
...
@@ -250,10 +250,17 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
/**
* Creates an {@link Authentication} object that represents this user.
*
*
* This method checks with {@link SecurityRealm} if the user is a valid user that can login to the security realm.
* If {@link SecurityRealm} is a kind that does not support querying information about other users, this will
* use {@link LastGrantedAuthoritiesProperty} to pick up the granted authorities as of the last time the user has
* logged in.
*
* @throws UsernameNotFoundException
* If this user is not a valid user in the backend {@link SecurityRealm}.
* @since 1.419
*/
public
Authentication
impersonate
()
{
public
Authentication
impersonate
()
throws
UsernameNotFoundException
{
try
{
UserDetails
u
=
Jenkins
.
getInstance
().
getSecurityRealm
().
loadUserByUsername
(
id
);
return
new
UsernamePasswordAuthenticationToken
(
u
.
getUsername
(),
""
,
u
.
getAuthorities
());
...
...
core/src/main/java/jenkins/security/ApiTokenFilter.java
浏览文件 @
bded790f
...
...
@@ -2,9 +2,7 @@ package jenkins.security;
import
hudson.model.User
;
import
hudson.security.ACL
;
import
hudson.security.UserMayOrMayNotExistException
;
import
hudson.util.Scrambler
;
import
jenkins.model.Jenkins
;
import
org.acegisecurity.context.SecurityContext
;
import
org.acegisecurity.context.SecurityContextHolder
;
import
org.acegisecurity.userdetails.UsernameNotFoundException
;
...
...
@@ -45,32 +43,29 @@ public class ApiTokenFilter implements Filter {
int
idx
=
uidpassword
.
indexOf
(
':'
);
if
(
idx
>=
0
)
{
String
username
=
uidpassword
.
substring
(
0
,
idx
);
try
{
Jenkins
.
getInstance
().
getSecurityRealm
().
loadUserByUsername
(
username
);
}
catch
(
UserMayOrMayNotExistException
x
)
{
// OK, give them the benefit of the doubt.
}
catch
(
UsernameNotFoundException
x
)
{
// Not/no longer a user; deny the API token. (But do not leak the information that this happened.)
chain
.
doFilter
(
request
,
response
);
return
;
}
catch
(
DataAccessException
x
)
{
throw
new
ServletException
(
x
);
}
String
password
=
uidpassword
.
substring
(
idx
+
1
);
// attempt to authenticate as API token
User
u
=
User
.
get
(
username
);
ApiTokenProperty
t
=
u
.
getProperty
(
ApiTokenProperty
.
class
);
if
(
t
!=
null
&&
t
.
matchesPassword
(
password
))
{
// even if we fail to match the password, we aren't rejecting it.
// as the user might be passing in a real password.
SecurityContext
oldContext
=
ACL
.
impersonate
(
u
.
impersonate
());
try
{
request
.
setAttribute
(
ApiTokenProperty
.
class
.
getName
(),
u
);
chain
.
doFilter
(
request
,
response
);
// even if we fail to match the password, we aren't rejecting it.
// as the user might be passing in a real password.
SecurityContext
oldContext
=
ACL
.
impersonate
(
u
.
impersonate
());
try
{
request
.
setAttribute
(
ApiTokenProperty
.
class
.
getName
(),
u
);
chain
.
doFilter
(
request
,
response
);
return
;
}
finally
{
SecurityContextHolder
.
setContext
(
oldContext
);
}
}
catch
(
UsernameNotFoundException
x
)
{
// Not/no longer a user; deny the API token. (But do not leak the information that this happened.)
chain
.
doFilter
(
request
,
response
);
return
;
}
finally
{
SecurityContextHolder
.
setContext
(
oldContext
);
}
catch
(
DataAccessException
x
)
{
throw
new
ServletException
(
x
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录