From 67a63a806e63692a9ab6614f2258f00d2400c794 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Mon, 6 Jun 2016 12:05:38 +0200 Subject: [PATCH] KEYCLOAK-3054: Fix potential NPE in RealmsResource Prior to PR .well-known Endpoint threw NPE with if unknown Protocol was provided. --- .../org/keycloak/services/resources/RealmsResource.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/src/main/java/org/keycloak/services/resources/RealmsResource.java b/services/src/main/java/org/keycloak/services/resources/RealmsResource.java index ae743f399d..f80234df33 100755 --- a/services/src/main/java/org/keycloak/services/resources/RealmsResource.java +++ b/services/src/main/java/org/keycloak/services/resources/RealmsResource.java @@ -98,9 +98,14 @@ public class RealmsResource { final @PathParam("protocol") String protocol) { RealmModel realm = init(name); + LoginProtocolFactory factory = (LoginProtocolFactory)session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, protocol); + if(factory == null){ + logger.debugv("protocol %s not found", protocol); + throw new NotFoundException("Protocol not found"); + } + EventBuilder event = new EventBuilder(realm, session, clientConnection); - LoginProtocolFactory factory = (LoginProtocolFactory)session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, protocol); Object endpoint = factory.createProtocolEndpoint(realm, event); ResteasyProviderFactory.getInstance().injectProperties(endpoint);