From 550e23c8f6709563d18a6e9a97d602d90eb77a15 Mon Sep 17 00:00:00 2001 From: Stan Silvert Date: Mon, 18 Jan 2016 16:35:51 -0500 Subject: [PATCH] KEYCLOAK-1280: i18n logging for org.keycloak.protocol.oidc --- .../keycloak/protocol/oidc/OIDCLoginProtocol.java | 8 ++++---- .../protocol/oidc/OIDCLoginProtocolFactory.java | 6 +++--- .../protocol/oidc/OIDCLoginProtocolService.java | 4 ++-- .../org/keycloak/protocol/oidc/TokenManager.java | 4 ++-- .../java/org/keycloak/services/ServicesLogger.java | 13 +++++++++++++ 5 files changed, 24 insertions(+), 11 deletions(-) mode change 100755 => 100644 services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocolService.java diff --git a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java index 40bcc67dc2..e064fd5132 100755 --- a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java @@ -21,7 +21,6 @@ */ package org.keycloak.protocol.oidc; -import org.jboss.logging.Logger; import org.keycloak.OAuth2Constants; import org.keycloak.events.Details; import org.keycloak.events.EventBuilder; @@ -37,6 +36,7 @@ import org.keycloak.protocol.oidc.utils.OIDCRedirectUriBuilder; import org.keycloak.protocol.oidc.utils.OIDCResponseMode; import org.keycloak.protocol.oidc.utils.OIDCResponseType; import org.keycloak.representations.AccessTokenResponse; +import org.keycloak.services.ServicesLogger; import org.keycloak.services.managers.ClientSessionCode; import org.keycloak.services.managers.ResourceAdminManager; @@ -68,7 +68,7 @@ public class OIDCLoginProtocol implements LoginProtocol { public static final String RESPONSE_MODE_PARAM = "response_mode"; - private static final Logger log = Logger.getLogger(OIDCLoginProtocol.class); + private static final ServicesLogger logger = ServicesLogger.ROOT_LOGGER; protected KeycloakSession session; @@ -143,7 +143,7 @@ public class OIDCLoginProtocol implements LoginProtocol { String redirect = clientSession.getRedirectUri(); OIDCRedirectUriBuilder redirectUri = OIDCRedirectUriBuilder.fromUri(redirect, responseMode); String state = clientSession.getNote(OIDCLoginProtocol.STATE_PARAM); - log.debugv("redirectAccessCode: state: {0}", state); + logger.debugv("redirectAccessCode: state: {0}", state); if (state != null) redirectUri.addParam(OAuth2Constants.STATE, state); @@ -203,7 +203,7 @@ public class OIDCLoginProtocol implements LoginProtocol { case PASSIVE_LOGIN_REQUIRED: return "login_required"; default: - log.warn("Untranslated protocol Error: " + error.name() + " so we return default SAML error"); + logger.untranslatedProtocol(error.name()); return "access_denied"; } } diff --git a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocolFactory.java b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocolFactory.java index a215e4cc06..8a13d9cd15 100755 --- a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocolFactory.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocolFactory.java @@ -16,7 +16,6 @@ */ package org.keycloak.protocol.oidc; -import org.jboss.logging.Logger; import org.keycloak.common.constants.KerberosConstants; import org.keycloak.common.util.UriUtils; import org.keycloak.events.EventBuilder; @@ -34,6 +33,7 @@ import org.keycloak.protocol.oidc.mappers.UserPropertyMapper; import org.keycloak.protocol.oidc.mappers.UserSessionNoteMapper; import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientTemplateRepresentation; +import org.keycloak.services.ServicesLogger; import org.keycloak.services.managers.AuthenticationManager; import java.util.ArrayList; @@ -50,7 +50,7 @@ import org.keycloak.protocol.oidc.mappers.UserAttributeMapper; * @version $Revision: 1 $ */ public class OIDCLoginProtocolFactory extends AbstractLoginProtocolFactory { - private static Logger logger = Logger.getLogger(OIDCLoginProtocolFactory.class); + private static ServicesLogger logger = ServicesLogger.ROOT_LOGGER; public static final String USERNAME = "username"; public static final String EMAIL = "email"; @@ -195,7 +195,7 @@ public class OIDCLoginProtocolFactory extends AbstractLoginProtocolFactory { // Backwards compatibility only if (rep.isDirectGrantsOnly() != null) { - logger.warn("Using deprecated 'directGrantsOnly' configuration in JSON representation. It will be removed in future versions"); + logger.usingDeprecatedDirectGrantsOnly(); newClient.setStandardFlowEnabled(!rep.isDirectGrantsOnly()); newClient.setDirectAccessGrantsEnabled(rep.isDirectGrantsOnly()); } else { diff --git a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocolService.java b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocolService.java old mode 100755 new mode 100644 index 6f6be0ceee..625317e744 --- a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocolService.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocolService.java @@ -1,6 +1,5 @@ package org.keycloak.protocol.oidc; -import org.jboss.logging.Logger; import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.keycloak.OAuth2Constants; @@ -16,6 +15,7 @@ import org.keycloak.protocol.oidc.endpoints.LogoutEndpoint; import org.keycloak.protocol.oidc.endpoints.TokenEndpoint; import org.keycloak.protocol.oidc.endpoints.UserInfoEndpoint; import org.keycloak.protocol.oidc.representations.JSONWebKeySet; +import org.keycloak.services.ServicesLogger; import org.keycloak.services.resources.RealmsResource; import javax.ws.rs.GET; @@ -37,7 +37,7 @@ import javax.ws.rs.core.UriInfo; */ public class OIDCLoginProtocolService { - protected static final Logger logger = Logger.getLogger(OIDCLoginProtocolService.class); + protected static final ServicesLogger logger = ServicesLogger.ROOT_LOGGER; private RealmModel realm; private TokenManager tokenManager; diff --git a/services/src/main/java/org/keycloak/protocol/oidc/TokenManager.java b/services/src/main/java/org/keycloak/protocol/oidc/TokenManager.java index 0051434477..7a3d5dc7da 100755 --- a/services/src/main/java/org/keycloak/protocol/oidc/TokenManager.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/TokenManager.java @@ -1,6 +1,5 @@ package org.keycloak.protocol.oidc; -import org.jboss.logging.Logger; import org.keycloak.common.ClientConnection; import org.keycloak.OAuth2Constants; import org.keycloak.OAuthErrorException; @@ -34,6 +33,7 @@ import org.keycloak.representations.AccessTokenResponse; import org.keycloak.representations.IDToken; import org.keycloak.representations.RefreshToken; import org.keycloak.services.ErrorResponseException; +import org.keycloak.services.ServicesLogger; import org.keycloak.services.managers.AuthenticationManager; import org.keycloak.services.managers.ClientSessionCode; import org.keycloak.services.managers.UserSessionManager; @@ -59,7 +59,7 @@ import java.util.Set; * @version $Revision: 1 $ */ public class TokenManager { - protected static final Logger logger = Logger.getLogger(TokenManager.class); + protected static final ServicesLogger logger = ServicesLogger.ROOT_LOGGER; public static void applyScope(RoleModel role, RoleModel scope, Set visited, Set requested) { if (visited.contains(scope)) return; diff --git a/services/src/main/java/org/keycloak/services/ServicesLogger.java b/services/src/main/java/org/keycloak/services/ServicesLogger.java index ab540de773..b7be23c917 100644 --- a/services/src/main/java/org/keycloak/services/ServicesLogger.java +++ b/services/src/main/java/org/keycloak/services/ServicesLogger.java @@ -17,6 +17,7 @@ package org.keycloak.services; +import java.net.URI; import org.jboss.logging.BasicLogger; import org.jboss.logging.Logger; import org.jboss.logging.annotations.Cause; @@ -188,4 +189,16 @@ public interface ServicesLogger extends BasicLogger { @LogMessage(level = ERROR) @Message(id=38, value="Error importing roles") void roleImportError(@Cause Exception e); + + @LogMessage(level = WARN) + @Message(id=39, value="Untranslated protocol Error: %s so we return default SAML error") + void untranslatedProtocol(String errorName); + + @LogMessage(level = WARN) + @Message(id=40, value="Using deprecated 'directGrantsOnly' configuration in JSON representation. It will be removed in future versions") + void usingDeprecatedDirectGrantsOnly(); + + @LogMessage(level = WARN) + @Message(id=41, value="Invoking deprecated endpoint %s") + void invokingDeprecatedEndpoint(URI requestUri); }