Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F56596271
PhabricatorAuthenticationToken.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Mar 29, 09:04
Size
3 KB
Mime Type
text/x-java
Expires
Sun, Mar 31, 10:04 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
16738950
Attached To
rPHOAUTH phab-oauth-jenkins
PhabricatorAuthenticationToken.java
View Options
/**
The MIT License
Copyright (c) 2011 Michael O'Cleirigh
Copyright (c) 2016 Jean-Baptiste Aubort
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package
org.jenkinsci.plugins
;
import
hudson.security.SecurityRealm
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.logging.Logger
;
import
java.util.logging.Level
;
import
jenkins.model.Jenkins
;
import
org.acegisecurity.GrantedAuthority
;
import
org.acegisecurity.providers.AbstractAuthenticationToken
;
import
org.acegisecurity.BadCredentialsException
;
public
class
PhabricatorAuthenticationToken
extends
AbstractAuthenticationToken
{
private
static
final
long
serialVersionUID
=
1L
;
private
final
String
accessToken
;
private
final
String
userName
;
private
PhabricatorSecurityRealm
myRealm
=
null
;
private
final
List
<
GrantedAuthority
>
authorities
=
new
ArrayList
<
GrantedAuthority
>();
public
PhabricatorAuthenticationToken
(
String
accessToken
)
throws
IOException
{
super
(
new
GrantedAuthority
[]
{});
this
.
accessToken
=
accessToken
;
authorities
.
add
(
SecurityRealm
.
AUTHENTICATED_AUTHORITY
);
if
(
Jenkins
.
getInstance
().
getSecurityRealm
()
instanceof
PhabricatorSecurityRealm
)
{
if
(
myRealm
==
null
)
{
myRealm
=
(
PhabricatorSecurityRealm
)
Jenkins
.
getInstance
()
.
getSecurityRealm
();
}
}
PhabricatorUser
user
=
authUsingToken
(
accessToken
);
if
(
user
==
null
){
throw
new
BadCredentialsException
(
"Unexpected authentication type"
);
}
userName
=
user
.
getUsername
();
setAuthenticated
(
true
);
}
private
PhabricatorUser
authUsingToken
(
String
token
)
throws
IOException
{
String
serverURL
=
myRealm
.
getServerURL
();
String
result
=
myRealm
.
getUrlContent
(
serverURL
+
myRealm
.
PHAB_API
+
"?access_token="
+
token
);
LOGGER
.
log
(
Level
.
WARNING
,
"content="
+
result
);
return
new
PhabricatorUser
(
"blah"
);
}
public
String
getAccessToken
()
{
return
accessToken
;
}
public
Object
getCredentials
()
{
return
""
;
// do not expose the credential
}
public
String
getPrincipal
()
{
return
this
.
userName
;
}
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
PhabricatorAuthenticationToken
.
class
.
getName
());
}
Event Timeline
Log In to Comment