File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
logicaldoc-core/src/main/java/com/logicaldoc/core/security Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -451,6 +451,7 @@ public Session getSession(HttpServletRequest request) {
451451 * <li>Request attribute <code>PARAM_SID</code></li>
452452 * <li>Session attribute <code>PARAM_SID</code></li>
453453 * <li>Cookie <code>COOKIE_SID</code></li>
454+ * <li>Header <code>X-API-KEY</code></li>
454455 * <li>Spring SecurityContextHolder</li>
455456 * <li>Client ID</li>
456457 * </ol>
@@ -522,9 +523,26 @@ else if (request.getSession(true).getAttribute(PARAM_SID) != null
522523 else
523524 sid = getSessionIdFromCookie (request );
524525
526+ if (StringUtils .isEmpty (sid ))
527+ sid = getSessionFromApiKey (request );
528+
525529 return sid ;
526530 }
527531
532+ private String getSessionFromApiKey (HttpServletRequest request ) {
533+ try {
534+ if (StringUtils .isNotEmpty (request .getHeader (HEADER_APIKEY ))) {
535+ String apiKey = CryptUtil .encryptSHA256 (request .getHeader (HEADER_APIKEY ));
536+ return getSessions ().stream ().filter (s -> apiKey .equals (s .getKey ())).map (s -> s .getSid ()).findFirst ()
537+ .orElse (null );
538+ }
539+ } catch (NoSuchAlgorithmException e ) {
540+ log .warn (e .getMessage (), e );
541+ }
542+
543+ return null ;
544+ }
545+
528546 private String getSessionIdFromCookie (HttpServletRequest request ) {
529547 Cookie [] cookies = request .getCookies ();
530548 if (cookies != null )
You can’t perform that action at this time.
0 commit comments