Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
19d0f8c4
Commit
19d0f8c4
authored
5 years ago
by
srosse
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/OpenOLAT_14.2'
parents
d1d62fc6
0917b1e9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/olat/login/oauth/spi/JSONWebToken.java
+36
-16
36 additions, 16 deletions
src/main/java/org/olat/login/oauth/spi/JSONWebToken.java
with
36 additions
and
16 deletions
src/main/java/org/olat/login/oauth/spi/JSONWebToken.java
+
36
−
16
View file @
19d0f8c4
...
@@ -19,8 +19,10 @@
...
@@ -19,8 +19,10 @@
*/
*/
package
org.olat.login.oauth.spi
;
package
org.olat.login.oauth.spi
;
import
org.apache.logging.log4j.Logger
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
org.olat.core.logging.Tracing
;
import
org.olat.core.util.StringHelper
;
import
org.olat.core.util.StringHelper
;
import
com.github.scribejava.core.model.OAuth2AccessToken
;
import
com.github.scribejava.core.model.OAuth2AccessToken
;
...
@@ -33,6 +35,8 @@ import com.github.scribejava.core.model.OAuth2AccessToken;
...
@@ -33,6 +35,8 @@ import com.github.scribejava.core.model.OAuth2AccessToken;
*/
*/
public
class
JSONWebToken
{
public
class
JSONWebToken
{
private
static
final
Logger
log
=
Tracing
.
createLoggerFor
(
JSONWebToken
.
class
);
private
final
String
header
;
private
final
String
header
;
private
final
String
payload
;
private
final
String
payload
;
private
final
JSONObject
jsonPayload
;
private
final
JSONObject
jsonPayload
;
...
@@ -56,24 +60,40 @@ public class JSONWebToken {
...
@@ -56,24 +60,40 @@ public class JSONWebToken {
}
}
public
static
JSONWebToken
parse
(
OAuth2AccessToken
token
)
throws
JSONException
{
public
static
JSONWebToken
parse
(
OAuth2AccessToken
token
)
throws
JSONException
{
String
accessToken
=
token
.
getAccessToken
();
try
{
String
accessToken
=
token
.
getAccessToken
();
int
firstIndex
=
accessToken
.
indexOf
(
'.'
);
int
secondIndex
=
accessToken
.
indexOf
(
'.'
,
firstIndex
+
1
);
int
firstIndex
=
accessToken
.
indexOf
(
'.'
);
int
secondIndex
=
accessToken
.
indexOf
(
'.'
,
firstIndex
+
1
);
String
header
=
StringHelper
.
decodeBase64
(
accessToken
.
substring
(
0
,
firstIndex
));
String
payload
=
StringHelper
.
decodeBase64
(
accessToken
.
substring
(
firstIndex
,
secondIndex
));
String
header
=
StringHelper
.
decodeBase64
(
accessToken
.
substring
(
0
,
firstIndex
));
JSONObject
jsonPayload
=
new
JSONObject
(
payload
);
String
payload
=
StringHelper
.
decodeBase64
(
accessToken
.
substring
(
firstIndex
,
secondIndex
));
return
new
JSONWebToken
(
header
,
payload
,
jsonPayload
);
JSONObject
jsonPayload
=
new
JSONObject
(
payload
);
return
new
JSONWebToken
(
header
,
payload
,
jsonPayload
);
}
catch
(
JSONException
e
)
{
log
.
error
(
"Cannot parse token: {}"
,
token
.
getAccessToken
());
throw
e
;
}
catch
(
Exception
e
)
{
log
.
error
(
"Cannot parse token: {}"
,
token
.
getAccessToken
());
throw
new
JSONException
(
e
);
}
}
}
public
static
JSONWebToken
parse
(
String
accessToken
)
throws
JSONException
{
public
static
JSONWebToken
parse
(
String
accessToken
)
throws
JSONException
{
int
firstIndex
=
accessToken
.
indexOf
(
'.'
);
try
{
int
secondIndex
=
accessToken
.
indexOf
(
'.'
,
firstIndex
+
1
);
int
firstIndex
=
accessToken
.
indexOf
(
'.'
);
int
secondIndex
=
accessToken
.
indexOf
(
'.'
,
firstIndex
+
1
);
String
header
=
StringHelper
.
decodeBase64
(
accessToken
.
substring
(
0
,
firstIndex
));
String
payload
=
StringHelper
.
decodeBase64
(
accessToken
.
substring
(
firstIndex
,
secondIndex
));
String
header
=
StringHelper
.
decodeBase64
(
accessToken
.
substring
(
0
,
firstIndex
));
JSONObject
jsonPayload
=
new
JSONObject
(
payload
);
String
payload
=
StringHelper
.
decodeBase64
(
accessToken
.
substring
(
firstIndex
,
secondIndex
));
return
new
JSONWebToken
(
header
,
payload
,
jsonPayload
);
JSONObject
jsonPayload
=
new
JSONObject
(
payload
);
return
new
JSONWebToken
(
header
,
payload
,
jsonPayload
);
}
catch
(
JSONException
e
)
{
log
.
error
(
"Cannot parse token: {}"
,
accessToken
);
throw
e
;
}
catch
(
Exception
e
)
{
log
.
error
(
"Cannot parse token: {}"
,
accessToken
);
throw
new
JSONException
(
e
);
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment