summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/AuthenticationCookieUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/AuthenticationCookieUtils.java')
-rw-r--r--openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/AuthenticationCookieUtils.java32
1 files changed, 18 insertions, 14 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/AuthenticationCookieUtils.java b/openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/AuthenticationCookieUtils.java
index f0a33da8a7..d71c8593f3 100644
--- a/openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/AuthenticationCookieUtils.java
+++ b/openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/AuthenticationCookieUtils.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,16 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.securityutil;
+import java.io.IOException;
+import javax.servlet.http.Cookie;
import org.openecomp.sdc.securityutil.filters.SessionValidationFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.servlet.http.Cookie;
-import java.io.IOException;
-
public class AuthenticationCookieUtils {
private static final Logger log = LoggerFactory.getLogger(SessionValidationFilter.class.getName());
@@ -43,10 +41,12 @@ public class AuthenticationCookieUtils {
* @throws CipherUtilException
* @throws IOException
*/
- public static Cookie updateSessionTime(Cookie cookie, ISessionValidationFilterConfiguration filterConfiguration) throws CipherUtilException, IOException {
+ public static Cookie updateSessionTime(Cookie cookie, ISessionValidationFilterConfiguration filterConfiguration)
+ throws CipherUtilException, IOException {
AuthenticationCookie authenticationCookie = getAuthenticationCookie(cookie, filterConfiguration);
long newTime = System.currentTimeMillis();
- log.debug("SessionValidationFilter: Going to set new session time in cookie, old value: {}, new value: {}", authenticationCookie.getCurrentSessionTime(), newTime);
+ log.debug("SessionValidationFilter: Going to set new session time in cookie, old value: {}, new value: {}",
+ authenticationCookie.getCurrentSessionTime(), newTime);
authenticationCookie.setCurrentSessionTime(newTime);
String encryptedCookie = getEncryptedCookie(authenticationCookie, filterConfiguration);
return createUpdatedCookie(cookie, encryptedCookie, filterConfiguration);
@@ -54,13 +54,14 @@ public class AuthenticationCookieUtils {
/**
* Create new Cookie object with same attributes as original cookie
+ *
* @param cookie
* @param encryptedCookie
* @param cookieConfiguration
* @return
*/
public static Cookie createUpdatedCookie(Cookie cookie, String encryptedCookie, ISessionValidationCookieConfiguration cookieConfiguration) {
- Cookie updatedCookie = new Cookie(cookie.getName(), encryptedCookie );
+ Cookie updatedCookie = new Cookie(cookie.getName(), encryptedCookie);
updatedCookie.setSecure(true);
updatedCookie.setPath(cookieConfiguration.getCookiePath());
updatedCookie.setDomain(cookieConfiguration.getCookieDomain());
@@ -77,7 +78,8 @@ public class AuthenticationCookieUtils {
* @throws IOException
* @throws CipherUtilException
*/
- public static String getEncryptedCookie(AuthenticationCookie authenticationCookie, ISessionValidationFilterConfiguration filterConfiguration) throws IOException, CipherUtilException {
+ public static String getEncryptedCookie(AuthenticationCookie authenticationCookie, ISessionValidationFilterConfiguration filterConfiguration)
+ throws IOException, CipherUtilException {
String changedCookieJson = RepresentationUtils.toRepresentation(authenticationCookie);
return CipherUtil.encryptPKC(changedCookieJson, filterConfiguration.getSecurityKey());
}
@@ -90,7 +92,8 @@ public class AuthenticationCookieUtils {
* @return
* @throws CipherUtilException
*/
- public static AuthenticationCookie getAuthenticationCookie(Cookie cookie, ISessionValidationFilterConfiguration filterConfiguration) throws CipherUtilException {
+ public static AuthenticationCookie getAuthenticationCookie(Cookie cookie, ISessionValidationFilterConfiguration filterConfiguration)
+ throws CipherUtilException {
String originalCookieJson = CipherUtil.decryptPKC(cookie.getValue(), filterConfiguration.getSecurityKey());
return RepresentationUtils.fromRepresentation(originalCookieJson, AuthenticationCookie.class);
}
@@ -108,7 +111,8 @@ public class AuthenticationCookieUtils {
long sessionExpirationDate = authenticationCookie.getMaxSessionTime() + filterConfiguration.getMaxSessionTimeOut();
long sessionTime = authenticationCookie.getCurrentSessionTime();
long currentTime = System.currentTimeMillis();
- log.debug("SessionValidationFilter: Checking if session expired: session time: {}, expiration time: {}, current time: {}", sessionTime, sessionExpirationDate, currentTime);
+ log.debug("SessionValidationFilter: Checking if session expired: session time: {}, expiration time: {}, current time: {}", sessionTime,
+ sessionExpirationDate, currentTime);
return currentTime > sessionExpirationDate || isSessionIdle(sessionTime, currentTime, filterConfiguration);
}
@@ -123,8 +127,8 @@ public class AuthenticationCookieUtils {
private static boolean isSessionIdle(long sessionTimeValue, long currentTime, ISessionValidationFilterConfiguration filterConfiguration) {
long currentIdleTime = currentTime - sessionTimeValue;
long maxIdleTime = filterConfiguration.getSessionIdleTimeOut();
- log.debug("SessionValidationFilter: Checking if session idle: session time: {}, current idle time: {}, max idle time: {}", currentTime, currentIdleTime, maxIdleTime);
+ log.debug("SessionValidationFilter: Checking if session idle: session time: {}, current idle time: {}, max idle time: {}", currentTime,
+ currentIdleTime, maxIdleTime);
return currentIdleTime >= maxIdleTime;
}
-
}