From aa22aeb8434aa31e3bfa038ca8c4cbc477e6efe7 Mon Sep 17 00:00:00 2001 From: JANG Date: Sun, 28 Apr 2024 01:33:15 +0900 Subject: [PATCH 1/4] Code Refactory --- ...WebSessionServerOAuth2AuthorizedClientRepository.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java index e3b462ebac3..313e85c1555 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java @@ -94,14 +94,11 @@ public Mono removeAuthorizedClient(String clientRegistrationId, Authentica // @formatter:on } - @SuppressWarnings("unchecked") private Map getAuthorizedClients(WebSession session) { - Map authorizedClients = (session != null) - ? (Map) session.getAttribute(this.sessionAttributeName) : null; - if (authorizedClients == null) { - authorizedClients = new HashMap<>(); + if (session == null) { + return new HashMap<>(); } - return authorizedClients; + return session.getAttribute(this.sessionAttributeName); } } From 19f0aa2fffbb8f0c16ec31cf6ebae61f8695978a Mon Sep 17 00:00:00 2001 From: JANG Date: Sun, 28 Apr 2024 01:42:50 +0900 Subject: [PATCH 2/4] refactory --- ...bSessionServerOAuth2AuthorizedClientRepository.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java index 313e85c1555..480b1cfa353 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java @@ -95,10 +95,12 @@ public Mono removeAuthorizedClient(String clientRegistrationId, Authentica } private Map getAuthorizedClients(WebSession session) { - if (session == null) { - return new HashMap<>(); - } - return session.getAttribute(this.sessionAttributeName); + if (session == null) { + return new HashMap<>(); + } + Map authorizedClients = session.getAttribute(this.sessionAttributeName); + return authorizedClients != null ? authorizedClients : new HashMap<>(); } + } From 6571d9480b65a0f49aa26139303cbe12d83220a9 Mon Sep 17 00:00:00 2001 From: JANG Date: Sun, 28 Apr 2024 01:53:35 +0900 Subject: [PATCH 3/4] NPE --- .../WebSessionServerOAuth2AuthorizedClientRepository.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java index 480b1cfa353..f364ed13391 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java @@ -95,9 +95,7 @@ public Mono removeAuthorizedClient(String clientRegistrationId, Authentica } private Map getAuthorizedClients(WebSession session) { - if (session == null) { - return new HashMap<>(); - } + Assert.notNull(session, "WebSession cannot be null. Ensure the session is properly initialized before accessing authorized clients."); Map authorizedClients = session.getAttribute(this.sessionAttributeName); return authorizedClients != null ? authorizedClients : new HashMap<>(); } From d5f737ade90564086eeee075991cbdb36287b082 Mon Sep 17 00:00:00 2001 From: Hyeon Sung Date: Sat, 4 May 2024 00:45:57 +0900 Subject: [PATCH 4/4] message & checkStyle & newline Remove --- ...WebSessionServerOAuth2AuthorizedClientRepository.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java index f364ed13391..b37d325ea3c 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,10 +95,9 @@ public Mono removeAuthorizedClient(String clientRegistrationId, Authentica } private Map getAuthorizedClients(WebSession session) { - Assert.notNull(session, "WebSession cannot be null. Ensure the session is properly initialized before accessing authorized clients."); - Map authorizedClients = session.getAttribute(this.sessionAttributeName); - return authorizedClients != null ? authorizedClients : new HashMap<>(); + Assert.notNull(session, "session cannot be null"); + Map authorizedClients = session.getAttribute(this.sessionAttributeName); + return (authorizedClients != null) ? authorizedClients : new HashMap<>(); } - }