Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
benjamin.ertl
aai-identity-harmonization
Commits
d4169efa
Commit
d4169efa
authored
Jan 20, 2016
by
benjamin.ertl
Browse files
change oauth2 tokens to oidc tokens
parent
b50ac6fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/edu/kit/scc/RestServiceController.java
View file @
d4169efa
package
edu.kit.scc
;
import
java.text.ParseException
;
import
org.apache.commons.codec.binary.Base64
;
import
org.json.JSONObject
;
import
org.slf4j.Logger
;
...
...
@@ -15,6 +17,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.nimbusds.jwt.JWT
;
import
com.nimbusds.jwt.JWTClaimsSet
;
import
com.nimbusds.openid.connect.sdk.token.OIDCTokens
;
import
edu.kit.scc.http.HttpClient
;
import
edu.kit.scc.http.HttpResponse
;
import
edu.kit.scc.ldap.LdapClient
;
...
...
@@ -74,12 +80,20 @@ public class RestServiceController {
}
// OIDC
JSONObject
oidcJson
=
n
ull
;
JSONObject
oidcJson
=
n
ew
JSONObject
()
;
try
{
String
token
=
body
.
split
(
"="
)[
1
];
oidcJson
=
oidcClient
.
requestUserInfo
(
token
);
// oidcJson = oidcClient.requestUserInfo(token);
OIDCTokens
tokens
=
oidcClient
.
requestTokens
(
token
);
JWT
jwt
=
tokens
.
getIDToken
();
JWTClaimsSet
claimsSet
=
jwt
.
getJWTClaimsSet
();
log
.
debug
(
claimsSet
.
toJSONObject
().
toJSONString
());
}
catch
(
ArrayIndexOutOfBoundsException
e
)
{
throw
new
UnauthorizedException
();
}
catch
(
ParseException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
if
(
oidcJson
!=
null
&&
!
oidcJson
.
isNull
(
"error"
))
{
...
...
@@ -91,6 +105,9 @@ public class RestServiceController {
JSONObject
scimJson
=
scimClient
.
getUser
(
name
);
// we are looking for "roles" in the SCIM response and sync with LDAP
// if nothing succeeded, fail
throw
new
UnauthorizedException
();
}
@ResponseStatus
(
value
=
HttpStatus
.
UNAUTHORIZED
)
...
...
src/main/java/edu/kit/scc/oidc/OidcClient.java
View file @
d4169efa
...
...
@@ -32,6 +32,7 @@ import com.nimbusds.oauth2.sdk.token.Tokens;
import
com.nimbusds.openid.connect.sdk.OIDCTokenResponse
;
import
com.nimbusds.openid.connect.sdk.OIDCTokenResponseParser
;
import
com.nimbusds.openid.connect.sdk.UserInfoRequest
;
import
com.nimbusds.openid.connect.sdk.token.OIDCTokens
;
import
edu.kit.scc.http.CustomSSLContext
;
import
edu.kit.scc.http.NullHostNameVerifier
;
...
...
@@ -126,10 +127,10 @@ public class OidcClient {
* the OAuth2 authorization code
* @return a {@link Tokens} bundle with all OIDC tokens
*/
public
Tokens
requestTokens
(
String
authorizationCode
)
{
public
OIDC
Tokens
requestTokens
(
String
authorizationCode
)
{
AuthorizationCode
code
=
new
AuthorizationCode
(
authorizationCode
);
Tokens
tokens
=
null
;
OIDC
Tokens
tokens
=
null
;
try
{
URI
redirectUri
=
new
URI
(
this
.
redirectUri
);
...
...
@@ -162,10 +163,9 @@ public class OidcClient {
OIDCTokenResponse
oidcTokenResponse
=
(
OIDCTokenResponse
)
response
;
tokens
=
oidcTokenResponse
.
getTokens
();
log
.
debug
(
tokens
.
toJSONObject
().
toJSONString
());
tokens
=
oidcTokenResponse
.
getOIDCTokens
();
log
.
debug
(
oidcTokenResponse
.
getOIDCTokens
().
toJSONObject
().
toJSONString
());
return
tokens
;
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment