From 9736322c9c195d5c0e064a6996dd5609749e53b7 Mon Sep 17 00:00:00 2001 From: Thumimku Date: Mon, 11 Nov 2024 15:35:34 +0530 Subject: [PATCH] clean web finger ep --- .../webfinger/DefaultWebFingerProcessor.java | 24 +++++++------- .../identity/webfinger/MessageContext.java | 2 -- .../identity/webfinger/WebFingerResponse.java | 2 -- .../carbon/identity/webfinger/WebLink.java | 2 -- .../DefaultWebFingerRequestBuilder.java | 4 +-- .../WebFingerOIDCResponseBuilder.java | 4 --- .../internal/WebFingerServiceComponent.java | 31 ++++++++----------- .../servlet/JSONResponseBuilder.java | 3 -- .../webfinger/servlet/WebFingerServlet.java | 4 +-- 9 files changed, 28 insertions(+), 48 deletions(-) diff --git a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/DefaultWebFingerProcessor.java b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/DefaultWebFingerProcessor.java index 4574128be4e..94243dadf4c 100644 --- a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/DefaultWebFingerProcessor.java +++ b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/DefaultWebFingerProcessor.java @@ -32,13 +32,12 @@ * Singleton class to process the webfinger request. */ public class DefaultWebFingerProcessor implements WebFingerProcessor { - private static final Log log = LogFactory.getLog(DefaultWebFingerProcessor.class); + private static final Log LOG = LogFactory.getLog(DefaultWebFingerProcessor.class); private static DefaultWebFingerProcessor defaultWebFingerProcessor = new DefaultWebFingerProcessor(); private DefaultWebFingerProcessor() { - if (log.isDebugEnabled()) { - log.debug("Initializing OIDCProcessor for OpenID connect discovery processor."); - } + + LOG.debug("Initializing OIDCProcessor for OpenID connect discovery processor."); } public static DefaultWebFingerProcessor getInstance() { @@ -56,27 +55,26 @@ public WebFingerResponse getResponse(HttpServletRequest request) throws WebFinge public int handleError(WebFingerEndpointException error) { String errorCode = error.getErrorCode(); if (WebFingerConstants.ERROR_CODE_INVALID_REQUEST.equals(errorCode)) { - if (log.isDebugEnabled()) { - log.debug(error); + if (LOG.isDebugEnabled()) { + LOG.debug(error); } return HttpServletResponse.SC_BAD_REQUEST; } else if (WebFingerConstants.ERROR_CODE_INVALID_RESOURCE.equals(errorCode)) { - if (log.isDebugEnabled()) { - log.debug(error); + if (LOG.isDebugEnabled()) { + LOG.debug(error); } return HttpServletResponse.SC_NOT_FOUND; } else if (WebFingerConstants.ERROR_CODE_JSON_EXCEPTION.equals(errorCode)) { - if (log.isDebugEnabled()) { - log.debug(error); + if (LOG.isDebugEnabled()) { + LOG.debug(error); } return HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE; } else if (WebFingerConstants.ERROR_CODE_NO_WEBFINGER_CONFIG.equals(errorCode)) { - log.error(WebFingerConstants.ERROR_MESSAGE_NO_WEBFINGER_CONFIG, error); + LOG.error(WebFingerConstants.ERROR_MESSAGE_NO_WEBFINGER_CONFIG, error); return HttpServletResponse.SC_NOT_FOUND; } else { - log.error("Internal server error occured. ", error); + LOG.error("Internal server error occured. ", error); return HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } - } } diff --git a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/MessageContext.java b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/MessageContext.java index 550a8e5a8cc..84adead0af9 100644 --- a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/MessageContext.java +++ b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/MessageContext.java @@ -51,6 +51,4 @@ public WebFingerResponse getResponse() { public void setResponse(WebFingerResponse response) { this.response = response; } - - } diff --git a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/WebFingerResponse.java b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/WebFingerResponse.java index 7a15b1e973b..8a9cf8d3e2e 100644 --- a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/WebFingerResponse.java +++ b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/WebFingerResponse.java @@ -18,7 +18,6 @@ package org.wso2.carbon.identity.webfinger; - import java.util.ArrayList; import java.util.List; @@ -52,5 +51,4 @@ public void addLink(String rel, String href) { link.setHref(href); this.links.add(link); } - } diff --git a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/WebLink.java b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/WebLink.java index c9e6ce23687..a6dfb955146 100644 --- a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/WebLink.java +++ b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/WebLink.java @@ -41,6 +41,4 @@ public String getRel() { public void setRel(String rel) { this.rel = rel; } - - } diff --git a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/builders/DefaultWebFingerRequestBuilder.java b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/builders/DefaultWebFingerRequestBuilder.java index 71631101539..c9c3b583c65 100644 --- a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/builders/DefaultWebFingerRequestBuilder.java +++ b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/builders/DefaultWebFingerRequestBuilder.java @@ -42,7 +42,7 @@ */ public class DefaultWebFingerRequestBuilder implements WebFingerRequestBuilder { - private static final Log log = LogFactory.getLog(DefaultWebFingerRequestBuilder.class); + private static final Log LOG = LogFactory.getLog(DefaultWebFingerRequestBuilder.class); @Override public WebFingerRequest buildRequest(HttpServletRequest request) throws WebFingerEndpointException { @@ -59,7 +59,7 @@ public WebFingerRequest buildRequest(HttpServletRequest request) throws WebFinge webFingerRequest.setResource(resource); if (StringUtils.isBlank(resource)) { - log.warn("Can't normalize null or empty URI: " + resource); + LOG.warn("Can't normalize null or empty URI: " + resource); throw new WebFingerEndpointException(WebFingerConstants.ERROR_CODE_INVALID_RESOURCE, "Null or empty URI."); } else { diff --git a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/builders/WebFingerOIDCResponseBuilder.java b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/builders/WebFingerOIDCResponseBuilder.java index efd46eab379..7b86b03df8a 100644 --- a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/builders/WebFingerOIDCResponseBuilder.java +++ b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/builders/WebFingerOIDCResponseBuilder.java @@ -18,8 +18,6 @@ package org.wso2.carbon.identity.webfinger.builders; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.wso2.carbon.base.ServerConfigurationException; import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; import org.wso2.carbon.identity.oauth2.util.OAuth2Util; @@ -38,8 +36,6 @@ */ public class WebFingerOIDCResponseBuilder { - private static final Log log = LogFactory.getLog(WebFingerOIDCResponseBuilder.class); - public WebFingerResponse buildWebFingerResponse(WebFingerRequest request) throws WebFingerEndpointException, ServerConfigurationException { diff --git a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/internal/WebFingerServiceComponent.java b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/internal/WebFingerServiceComponent.java index caebb95345c..a50f446ab8b 100644 --- a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/internal/WebFingerServiceComponent.java +++ b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/internal/WebFingerServiceComponent.java @@ -43,7 +43,7 @@ immediate = true ) public class WebFingerServiceComponent { - private static final Log log = LogFactory.getLog(WebFingerServiceComponent.class); + private static final Log LOG = LogFactory.getLog(WebFingerServiceComponent.class); protected void activate(ComponentContext context) { try { @@ -51,9 +51,8 @@ protected void activate(ComponentContext context) { WebFingerProcessor webFingerProcessor = DefaultWebFingerProcessor.getInstance(); bundleContext.registerService(WebFingerProcessor.class.getName(), webFingerProcessor, null); WebFingerServiceComponentHolder.setWebFingerProcessor(webFingerProcessor); - if (log.isDebugEnabled()) { - log.debug("OpenID WebFinger bundle is activated."); - } + LOG.debug("OpenID WebFinger bundle is activated."); + // Register OpenID Connect WebFinger servlet HttpService httpService = WebFingerServiceComponentHolder.getHttpService(); @@ -63,11 +62,11 @@ protected void activate(ComponentContext context) { httpService.registerServlet("/.well-known/webfinger", webFingerServlet, null, null); } catch (Exception e) { String errMsg = "Error when registering Web Finger Servlet via the HttpService."; - log.error(errMsg, e); + LOG.error(errMsg, e); throw new RuntimeException(errMsg, e); } } catch (Throwable e) { - log.error("Error while activating the WebFingerServiceComponent", e); + LOG.error("Error while activating the WebFingerServiceComponent", e); } } @@ -79,16 +78,14 @@ protected void activate(ComponentContext context) { unbind = "unsetRealmService" ) protected void setRealmService(RealmService realmService) { - if (log.isDebugEnabled()) { - log.info("Setting the Realm Service"); - } + + LOG.info("Setting the Realm Service"); WebFingerServiceComponentHolder.setRealmService(realmService); } protected void unsetRealmService(RealmService realmService) { - if (log.isDebugEnabled()) { - log.info("Unsetting the Realm Service"); - } + + LOG.info("Unsetting the Realm Service"); WebFingerServiceComponentHolder.setRealmService(null); } @@ -100,16 +97,14 @@ protected void unsetRealmService(RealmService realmService) { unbind = "unsetHttpService" ) protected void setHttpService(HttpService httpService) { - if (log.isDebugEnabled()) { - log.debug("HTTP Service is set in the OpenID Connect WebFinger bundle"); - } + + LOG.debug("HTTP Service is set in the OpenID Connect WebFinger bundle"); WebFingerServiceComponentHolder.setHttpService(httpService); } protected void unsetHttpService(HttpService httpService) { - if (log.isDebugEnabled()) { - log.debug("HTTP Service is unset in the OpenID Connect WebFinger bundle"); - } + + LOG.debug("HTTP Service is unset in the OpenID Connect WebFinger bundle"); WebFingerServiceComponentHolder.setHttpService(null); } } diff --git a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/servlet/JSONResponseBuilder.java b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/servlet/JSONResponseBuilder.java index 3c53c365cc3..0edd745a098 100644 --- a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/servlet/JSONResponseBuilder.java +++ b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/servlet/JSONResponseBuilder.java @@ -20,8 +20,6 @@ import com.google.gson.Gson; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.webfinger.WebFingerEndpointException; import org.wso2.carbon.identity.webfinger.WebFingerResponse; import org.wso2.carbon.identity.webfinger.builders.WebFingerResponseBuilder; @@ -30,7 +28,6 @@ * Webfinger response builder */ public class JSONResponseBuilder implements WebFingerResponseBuilder { - private static final Log log = LogFactory.getLog(JSONResponseBuilder.class); @Override public String getOIDProviderIssuerString(WebFingerResponse webFingerResponse) throws WebFingerEndpointException { diff --git a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/servlet/WebFingerServlet.java b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/servlet/WebFingerServlet.java index 1e9351cc3e2..78c25e541cc 100644 --- a/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/servlet/WebFingerServlet.java +++ b/components/org.wso2.carbon.identity.webfinger/src/main/java/org/wso2/carbon/identity/webfinger/servlet/WebFingerServlet.java @@ -38,7 +38,7 @@ * Webfinger endpoint. Servelet is registered for the path /.well-known/webfinger */ public class WebFingerServlet extends HttpServlet { - private static final Log log = LogFactory.getLog(WebFingerServlet.class); + private static final Log LOG = LogFactory.getLog(WebFingerServlet.class); @Override protected void doGet(HttpServletRequest httpServletRequest, @@ -57,7 +57,7 @@ public void getOIDProviderIssuer(HttpServletRequest httpServletRequest, httpServletResponse.setStatus(processor.handleError(e)); return; } catch (ServerConfigurationException e) { - log.error("Server Configuration error occurred.", e); + LOG.error("Server Configuration error occurred.", e); httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; }