commit
e1f2d296bf
22 changed files with 111 additions and 123 deletions
|
@ -42,6 +42,11 @@
|
||||||
<version>${hibernate.entitymanager.version}</version>
|
<version>${hibernate.entitymanager.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-mapper-asl</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -52,11 +57,6 @@
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package org.keycloak.audit.jpa;
|
package org.keycloak.audit.jpa;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
import org.codehaus.jackson.type.TypeReference;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
import org.keycloak.audit.AuditProvider;
|
import org.keycloak.audit.AuditProvider;
|
||||||
import org.keycloak.audit.Event;
|
import org.keycloak.audit.Event;
|
||||||
import org.keycloak.audit.EventQuery;
|
import org.keycloak.audit.EventQuery;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityTransaction;
|
import javax.persistence.EntityTransaction;
|
||||||
import java.util.HashMap;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -16,6 +18,11 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
public class JpaAuditProvider implements AuditProvider {
|
public class JpaAuditProvider implements AuditProvider {
|
||||||
|
|
||||||
|
private static final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
private static final TypeReference<Map<String, String>> mapType = new TypeReference<Map<String, String>>() {
|
||||||
|
};
|
||||||
|
private static final Logger logger = Logger.getLogger(JpaAuditProvider.class);
|
||||||
|
|
||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
private EntityTransaction tx;
|
private EntityTransaction tx;
|
||||||
|
|
||||||
|
@ -78,7 +85,11 @@ public class JpaAuditProvider implements AuditProvider {
|
||||||
e.setUserId(o.getUserId());
|
e.setUserId(o.getUserId());
|
||||||
e.setIpAddress(o.getIpAddress());
|
e.setIpAddress(o.getIpAddress());
|
||||||
e.setError(o.getError());
|
e.setError(o.getError());
|
||||||
e.setDetailsJson(new JSONObject(o.getDetails()).toString());
|
try {
|
||||||
|
e.setDetailsJson(mapper.writeValueAsString(o.getDetails()));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
logger.error("Failed to write log details", ex);
|
||||||
|
}
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,14 +102,12 @@ public class JpaAuditProvider implements AuditProvider {
|
||||||
e.setUserId(o.getUserId());
|
e.setUserId(o.getUserId());
|
||||||
e.setIpAddress(o.getIpAddress());
|
e.setIpAddress(o.getIpAddress());
|
||||||
e.setError(o.getError());
|
e.setError(o.getError());
|
||||||
|
try {
|
||||||
JSONObject object = new JSONObject(o.getDetailsJson());
|
Map<String, String> details = mapper.readValue(o.getDetailsJson(), mapType);
|
||||||
Map<String, String> details = new HashMap<String, String>();
|
e.setDetails(details);
|
||||||
for (Object k : object.keySet()) {
|
} catch (IOException ex) {
|
||||||
details.put((String) k, object.getString((String) k));
|
logger.error("Failed to read log details", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
e.setDetails(details);
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,6 @@
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -87,10 +87,6 @@
|
||||||
<artifactId>keycloak-social-core</artifactId>
|
<artifactId>keycloak-social-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.keycloak</groupId>
|
<groupId>org.keycloak</groupId>
|
||||||
<artifactId>keycloak-social-github</artifactId>
|
<artifactId>keycloak-social-github</artifactId>
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li><a href="#/realms/{{realm.realm}}">{{realm.realm}}</a></li>
|
<li><a href="#/realms/{{realm.realm}}">{{realm.realm}}</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}">Audit</a></li>
|
<li><a href="#/realms/{{realm.realm}}/audit">Audit</a></li>
|
||||||
<li class="active">Social</li>
|
<li class="active">Config</li>
|
||||||
</ol>
|
</ol>
|
||||||
<h2><span>{{realm.realm}}</span> Audit Config</h2>
|
<h2><span>{{realm.realm}}</span> Audit Config</h2>
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,7 @@
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li><a href="#/realms/{{realm.realm}}">{{realm.realm}}</a></li>
|
<li><a href="#/realms/{{realm.realm}}">{{realm.realm}}</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}">Audit</a></li>
|
<li class="active">Audit</li>
|
||||||
<li class="active">Social</li>
|
|
||||||
</ol>
|
</ol>
|
||||||
<h2><span>{{realm.realm}}</span> Audit Log</h2>
|
<h2><span>{{realm.realm}}</span> Audit Log</h2>
|
||||||
|
|
||||||
|
|
7
pom.xml
7
pom.xml
|
@ -33,7 +33,6 @@
|
||||||
<slf4j.version>1.5.10</slf4j.version>
|
<slf4j.version>1.5.10</slf4j.version>
|
||||||
<jboss.version>7.1.1.Final</jboss.version>
|
<jboss.version>7.1.1.Final</jboss.version>
|
||||||
<wildfly.version>8.0.0.Final</wildfly.version>
|
<wildfly.version>8.0.0.Final</wildfly.version>
|
||||||
<json.version>20131018</json.version>
|
|
||||||
|
|
||||||
<!-- maven-compiler-plugin -->
|
<!-- maven-compiler-plugin -->
|
||||||
<maven.compiler.target>1.6</maven.compiler.target>
|
<maven.compiler.target>1.6</maven.compiler.target>
|
||||||
|
@ -286,12 +285,6 @@
|
||||||
<version>2.3.19</version>
|
<version>2.3.19</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<version>${json.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Google+ -->
|
<!-- Google+ -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.http-client</groupId>
|
<groupId>com.google.http-client</groupId>
|
||||||
|
|
|
@ -73,10 +73,6 @@
|
||||||
<artifactId>keycloak-social-core</artifactId>
|
<artifactId>keycloak-social-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.keycloak</groupId>
|
<groupId>org.keycloak</groupId>
|
||||||
<artifactId>keycloak-social-github</artifactId>
|
<artifactId>keycloak-social-github</artifactId>
|
||||||
|
|
|
@ -68,10 +68,6 @@
|
||||||
<artifactId>keycloak-social-core</artifactId>
|
<artifactId>keycloak-social-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.keycloak</groupId>
|
<groupId>org.keycloak</groupId>
|
||||||
<artifactId>keycloak-social-github</artifactId>
|
<artifactId>keycloak-social-github</artifactId>
|
||||||
|
|
|
@ -234,13 +234,14 @@ public class AccountService {
|
||||||
e.setEvent(e.getEvent().replace('_', ' '));
|
e.setEvent(e.getEvent().replace('_', ' '));
|
||||||
|
|
||||||
Map<String, String> details = new HashMap<String, String>();
|
Map<String, String> details = new HashMap<String, String>();
|
||||||
Iterator<String> itr = e.getDetails().keySet().iterator();
|
if (e.getDetails() != null) {
|
||||||
for (Map.Entry<String, String> d : e.getDetails().entrySet()) {
|
Iterator<String> itr = e.getDetails().keySet().iterator();
|
||||||
if (AUDIT_DETAILS.contains(d.getKey())) {
|
for (Map.Entry<String, String> d : e.getDetails().entrySet()) {
|
||||||
details.put(d.getKey().replace('_', ' '), d.getValue());
|
if (AUDIT_DETAILS.contains(d.getKey())) {
|
||||||
|
details.put(d.getKey().replace('_', ' '), d.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e.setDetails(details);
|
e.setDetails(details);
|
||||||
}
|
}
|
||||||
account.setEvents(events);
|
account.setEvents(events);
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.json</groupId>
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
<artifactId>json</artifactId>
|
<artifactId>jackson-mapper-asl</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.keycloak.social;
|
package org.keycloak.social;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.keycloak.OAuth2Constants;
|
import org.keycloak.OAuth2Constants;
|
||||||
import org.keycloak.social.utils.SimpleHttp;
|
import org.keycloak.social.utils.SimpleHttp;
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@ import java.util.regex.Pattern;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractOAuth2Provider implements SocialProvider {
|
public abstract class AbstractOAuth2Provider implements SocialProvider {
|
||||||
|
|
||||||
|
private static ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
private static final String AUTHORIZATION_CODE = "authorization_code";
|
private static final String AUTHORIZATION_CODE = "authorization_code";
|
||||||
private static final String ACCESS_TOKEN = "access_token";
|
private static final String ACCESS_TOKEN = "access_token";
|
||||||
private static final String CLIENT_ID = "client_id";
|
private static final String CLIENT_ID = "client_id";
|
||||||
|
@ -76,7 +78,7 @@ public abstract class AbstractOAuth2Provider implements SocialProvider {
|
||||||
String accessToken;
|
String accessToken;
|
||||||
|
|
||||||
if (response.startsWith("{")) {
|
if (response.startsWith("{")) {
|
||||||
accessToken = new JSONObject(response).getString(ACCESS_TOKEN);
|
accessToken = mapper.readTree(response).get(ACCESS_TOKEN).getTextValue();
|
||||||
} else {
|
} else {
|
||||||
Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response);
|
Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.keycloak.social.utils;
|
package org.keycloak.social.utils;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.codehaus.jackson.JsonNode;
|
||||||
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -18,6 +19,8 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class SimpleHttp {
|
public class SimpleHttp {
|
||||||
|
|
||||||
|
private static ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
private String method;
|
private String method;
|
||||||
private Map<String, String> headers;
|
private Map<String, String> headers;
|
||||||
|
@ -52,8 +55,8 @@ public class SimpleHttp {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject asJson() throws IOException {
|
public JsonNode asJson() throws IOException {
|
||||||
return new JSONObject(asString());
|
return mapper.readTree(asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String asString() throws IOException {
|
public String asString() throws IOException {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.keycloak.social.utils;
|
||||||
|
|
||||||
import io.undertow.servlet.api.DeploymentInfo;
|
import io.undertow.servlet.api.DeploymentInfo;
|
||||||
import io.undertow.servlet.api.ServletInfo;
|
import io.undertow.servlet.api.ServletInfo;
|
||||||
import org.json.JSONObject;
|
import org.codehaus.jackson.JsonNode;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -45,56 +45,56 @@ public class SimpleHttpTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostNoParams() throws IOException {
|
public void testPostNoParams() throws IOException {
|
||||||
JSONObject o = SimpleHttp.doPost("http://localhost:8081/tojson").asJson();
|
JsonNode o = SimpleHttp.doPost("http://localhost:8081/tojson").asJson();
|
||||||
JSONObject p = o.getJSONObject("params");
|
JsonNode p = o.get("params");
|
||||||
|
|
||||||
assertEquals(0, p.length());
|
assertEquals(0, p.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost() throws IOException {
|
public void testPost() throws IOException {
|
||||||
JSONObject o = SimpleHttp.doPost("http://localhost:8081/tojson").param("key-one", "value one ;)").param("key-two", "value two!&").asJson();
|
JsonNode o = SimpleHttp.doPost("http://localhost:8081/tojson").param("key-one", "value one ;)").param("key-two", "value two!&").asJson();
|
||||||
JSONObject p = o.getJSONObject("params");
|
JsonNode p = o.get("params");
|
||||||
|
|
||||||
assertEquals(2, p.length());
|
assertEquals(2, p.size());
|
||||||
assertEquals("value one ;)", p.getString("key-one"));
|
assertEquals("value one ;)", p.get("key-one").getTextValue());
|
||||||
assertEquals("value two!&", p.getString("key-two"));
|
assertEquals("value two!&", p.get("key-two").getTextValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostCustomHeader() throws IOException {
|
public void testPostCustomHeader() throws IOException {
|
||||||
JSONObject o = SimpleHttp.doPost("http://localhost:8081/tojson").header("Accept", "application/json").header("Authorization", "bearer dsfsadfsdf").asJson();
|
JsonNode o = SimpleHttp.doPost("http://localhost:8081/tojson").header("Accept", "application/json").header("Authorization", "bearer dsfsadfsdf").asJson();
|
||||||
JSONObject h = o.getJSONObject("headers");
|
JsonNode h = o.get("headers");
|
||||||
|
|
||||||
assertEquals("application/json", h.getString("Accept"));
|
assertEquals("application/json", h.get("Accept").getTextValue());
|
||||||
assertEquals("bearer dsfsadfsdf", h.getString("Authorization"));
|
assertEquals("bearer dsfsadfsdf", h.get("Authorization").getTextValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetNoParams() throws IOException {
|
public void testGetNoParams() throws IOException {
|
||||||
JSONObject o = SimpleHttp.doGet("http://localhost:8081/tojson").asJson();
|
JsonNode o = SimpleHttp.doGet("http://localhost:8081/tojson").asJson();
|
||||||
JSONObject p = o.getJSONObject("params");
|
JsonNode p = o.get("params");
|
||||||
|
|
||||||
assertEquals(0, p.length());
|
assertEquals(0, p.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet() throws IOException {
|
public void testGet() throws IOException {
|
||||||
JSONObject o = SimpleHttp.doGet("http://localhost:8081/tojson").param("key-one", "value one ;)").param("key-two", "value two!&").asJson();
|
JsonNode o = SimpleHttp.doGet("http://localhost:8081/tojson").param("key-one", "value one ;)").param("key-two", "value two!&").asJson();
|
||||||
JSONObject p = o.getJSONObject("params");
|
JsonNode p = o.get("params");
|
||||||
|
|
||||||
assertEquals(2, p.length());
|
assertEquals(2, p.size());
|
||||||
assertEquals("value one ;)", p.getString("key-one"));
|
assertEquals("value one ;)", p.get("key-one").getTextValue());
|
||||||
assertEquals("value two!&", p.getString("key-two"));
|
assertEquals("value two!&", p.get("key-two").getTextValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCustomHeader() throws IOException {
|
public void testGetCustomHeader() throws IOException {
|
||||||
JSONObject o = SimpleHttp.doGet("http://localhost:8081/tojson").header("Accept", "application/json").header("Authorization", "bearer dsfsadfsdf").asJson();
|
JsonNode o = SimpleHttp.doGet("http://localhost:8081/tojson").header("Accept", "application/json").header("Authorization", "bearer dsfsadfsdf").asJson();
|
||||||
JSONObject h = o.getJSONObject("headers");
|
JsonNode h = o.get("headers");
|
||||||
|
|
||||||
assertEquals("application/json", h.getString("Accept"));
|
assertEquals("application/json", h.get("Accept"));
|
||||||
assertEquals("bearer dsfsadfsdf", h.getString("Authorization"));
|
assertEquals("bearer dsfsadfsdf", h.get("Authorization").getTextValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.keycloak.social.utils;
|
package org.keycloak.social.utils;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.codehaus.jackson.JsonNode;
|
||||||
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
import org.codehaus.jackson.node.ObjectNode;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
|
@ -14,6 +16,8 @@ import java.util.Enumeration;
|
||||||
*/
|
*/
|
||||||
public class ToJsonServlet extends HttpServlet {
|
public class ToJsonServlet extends HttpServlet {
|
||||||
|
|
||||||
|
private static final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
toJson(req, resp);
|
toJson(req, resp);
|
||||||
|
@ -25,9 +29,9 @@ public class ToJsonServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toJson(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
private void toJson(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||||
JSONObject o = new JSONObject();
|
ObjectNode o = mapper.createObjectNode();
|
||||||
|
|
||||||
JSONObject headers = new JSONObject();
|
ObjectNode headers = mapper.createObjectNode();
|
||||||
Enumeration<String> headerNames = req.getHeaderNames();
|
Enumeration<String> headerNames = req.getHeaderNames();
|
||||||
while (headerNames.hasMoreElements()) {
|
while (headerNames.hasMoreElements()) {
|
||||||
String n = headerNames.nextElement();
|
String n = headerNames.nextElement();
|
||||||
|
@ -35,7 +39,7 @@ public class ToJsonServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
o.put("headers", headers);
|
o.put("headers", headers);
|
||||||
|
|
||||||
JSONObject params = new JSONObject();
|
ObjectNode params = mapper.createObjectNode();
|
||||||
Enumeration<String> parameterNames = req.getParameterNames();
|
Enumeration<String> parameterNames = req.getParameterNames();
|
||||||
while (parameterNames.hasMoreElements()) {
|
while (parameterNames.hasMoreElements()) {
|
||||||
String n = parameterNames.nextElement();
|
String n = parameterNames.nextElement();
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
<description/>
|
<description/>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.keycloak</groupId>
|
<groupId>org.keycloak</groupId>
|
||||||
<artifactId>keycloak-social-core</artifactId>
|
<artifactId>keycloak-social-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-mapper-asl</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.keycloak.social.facebook;
|
package org.keycloak.social.facebook;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.codehaus.jackson.JsonNode;
|
||||||
import org.keycloak.social.AbstractOAuth2Provider;
|
import org.keycloak.social.AbstractOAuth2Provider;
|
||||||
import org.keycloak.social.AuthRequest;
|
import org.keycloak.social.AuthRequest;
|
||||||
import org.keycloak.social.SocialProviderConfig;
|
import org.keycloak.social.SocialProviderConfig;
|
||||||
|
@ -50,11 +50,12 @@ public class FacebookProvider extends AbstractOAuth2Provider {
|
||||||
@Override
|
@Override
|
||||||
protected SocialUser getProfile(String accessToken) throws SocialProviderException {
|
protected SocialUser getProfile(String accessToken) throws SocialProviderException {
|
||||||
try {
|
try {
|
||||||
JSONObject profile = SimpleHttp.doGet(PROFILE_URL).header("Authorization", "Bearer " + accessToken).asJson();
|
JsonNode profile = SimpleHttp.doGet(PROFILE_URL).header("Authorization", "Bearer " + accessToken).asJson();
|
||||||
|
|
||||||
SocialUser user = new SocialUser(profile.getString("id"), profile.getString("username"));
|
SocialUser user = new SocialUser(profile.get("id").getTextValue(), profile.get("username").getTextValue());
|
||||||
user.setName(profile.optString("first_name"), profile.optString("last_name"));
|
user.setName(profile.has("first_name") ? profile.get("first_name").getTextValue() : null,
|
||||||
user.setEmail(profile.optString("email"));
|
profile.has("last_name") ? profile.get("last_name").getTextValue() : null);
|
||||||
|
user.setEmail(profile.has("email") ? profile.get("email").getTextValue() : null);
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
<description/>
|
<description/>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.keycloak</groupId>
|
<groupId>org.keycloak</groupId>
|
||||||
<artifactId>keycloak-social-core</artifactId>
|
<artifactId>keycloak-social-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-mapper-asl</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package org.keycloak.social.github;
|
package org.keycloak.social.github;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.codehaus.jackson.JsonNode;
|
||||||
import org.keycloak.social.AbstractOAuth2Provider;
|
import org.keycloak.social.AbstractOAuth2Provider;
|
||||||
import org.keycloak.social.AuthRequest;
|
|
||||||
import org.keycloak.social.SocialProviderConfig;
|
|
||||||
import org.keycloak.social.SocialProviderException;
|
import org.keycloak.social.SocialProviderException;
|
||||||
import org.keycloak.social.SocialUser;
|
import org.keycloak.social.SocialUser;
|
||||||
import org.keycloak.social.utils.SimpleHttp;
|
import org.keycloak.social.utils.SimpleHttp;
|
||||||
|
@ -50,11 +48,11 @@ public class GitHubProvider extends AbstractOAuth2Provider {
|
||||||
@Override
|
@Override
|
||||||
protected SocialUser getProfile(String accessToken) throws SocialProviderException {
|
protected SocialUser getProfile(String accessToken) throws SocialProviderException {
|
||||||
try {
|
try {
|
||||||
JSONObject profile = SimpleHttp.doGet(PROFILE_URL).header("Authorization", "Bearer " + accessToken).asJson();
|
JsonNode profile = SimpleHttp.doGet(PROFILE_URL).header("Authorization", "Bearer " + accessToken).asJson();
|
||||||
|
|
||||||
SocialUser user = new SocialUser(profile.get("id").toString(), profile.getString("login"));
|
SocialUser user = new SocialUser(profile.get("id").toString(), profile.get("login").getTextValue());
|
||||||
user.setName(profile.optString("name"));
|
user.setName(profile.has("name") ? profile.get("name").getTextValue() : null);
|
||||||
user.setEmail(profile.optString("email"));
|
user.setEmail(profile.has("email") ? profile.get("email").getTextValue() : null);
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
<description/>
|
<description/>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.keycloak</groupId>
|
<groupId>org.keycloak</groupId>
|
||||||
<artifactId>keycloak-social-core</artifactId>
|
<artifactId>keycloak-social-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-mapper-asl</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -21,11 +21,11 @@
|
||||||
*/
|
*/
|
||||||
package org.keycloak.social.google;
|
package org.keycloak.social.google;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.codehaus.jackson.JsonNode;
|
||||||
import org.keycloak.social.AbstractOAuth2Provider;
|
import org.keycloak.social.AbstractOAuth2Provider;
|
||||||
import org.keycloak.social.utils.SimpleHttp;
|
|
||||||
import org.keycloak.social.SocialProviderException;
|
import org.keycloak.social.SocialProviderException;
|
||||||
import org.keycloak.social.SocialUser;
|
import org.keycloak.social.SocialUser;
|
||||||
|
import org.keycloak.social.utils.SimpleHttp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||||
|
@ -69,11 +69,12 @@ public class GoogleProvider extends AbstractOAuth2Provider {
|
||||||
@Override
|
@Override
|
||||||
protected SocialUser getProfile(String accessToken) throws SocialProviderException {
|
protected SocialUser getProfile(String accessToken) throws SocialProviderException {
|
||||||
try {
|
try {
|
||||||
JSONObject profile = SimpleHttp.doGet(PROFILE_URL).header("Authorization", "Bearer " + accessToken).asJson();
|
JsonNode profile = SimpleHttp.doGet(PROFILE_URL).header("Authorization", "Bearer " + accessToken).asJson();
|
||||||
|
|
||||||
SocialUser user = new SocialUser(profile.getString("sub"), profile.getString("email"));
|
SocialUser user = new SocialUser(profile.get("sub").getTextValue(), profile.get("email").getTextValue());
|
||||||
user.setName(profile.optString("given_name"), profile.optString("family_name"));
|
user.setName(profile.has("given_name") ? profile.get("given_name").getTextValue() : null,
|
||||||
user.setEmail(profile.optString("email"));
|
profile.has("family_name") ? profile.get("family_name").getTextValue() : null);
|
||||||
|
user.setEmail(profile.has("email") ? profile.get("email").getTextValue() : null);
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -20,12 +20,6 @@
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.twitter4j</groupId>
|
<groupId>org.twitter4j</groupId>
|
||||||
<artifactId>twitter4j-core</artifactId>
|
<artifactId>twitter4j-core</artifactId>
|
||||||
|
|
Loading…
Reference in a new issue