Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion examples/as7-eap-demo/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.161</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
4 changes: 4 additions & 0 deletions examples/as7-eap-demo/server/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<async-supported>true</async-supported>
</servlet>

<listener>
<listener-class>org.keycloak.services.listeners.MongoRunnerListener</listener-class>
</listener>

<filter>
<filter-name>Keycloak Session Management</filter-name>
<filter-class>org.keycloak.services.filters.KeycloakSessionServletFilter</filter-class>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.keycloak.models.utils;

import java.util.concurrent.atomic.AtomicLong;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public class KeycloakSessionUtils {

private static AtomicLong counter = new AtomicLong(1);

public static String generateId() {
return counter.getAndIncrement() + "-" + System.currentTimeMillis();
}
}
2 changes: 1 addition & 1 deletion model/jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<artifactId>keycloak-parent</artifactId>
<groupId>org.keycloak</groupId>
<version>1.0-alpha-1</version>
<relativePath>../pom.xml</relativePath>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
77 changes: 77 additions & 0 deletions model/mongo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>keycloak-parent</artifactId>
<groupId>org.keycloak</groupId>
<version>1.0-alpha-1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>keycloak-model-mongo</artifactId>
<name>Keycloak Model Mongo</name>
<description/>

<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-model-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-idm-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.keycloak.models.mongo.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public abstract class AbstractAttributedNoSQLObject extends AbstractNoSQLObject implements AttributedNoSQLObject {

// Simple hashMap for now (no thread-safe)
private Map<String, String> attributes = new HashMap<String, String>();

@Override
public void setAttribute(String name, String value) {
attributes.put(name, value);
}

@Override
public void removeAttribute(String name) {
// attributes.remove(name);

// ensure that particular attribute has null value, so it will be deleted in DB. TODO: needs to be improved
attributes.put(name, null);
}

@Override
public String getAttribute(String name) {
return attributes.get(name);
}

@Override
public Map<String, String> getAttributes() {
return Collections.unmodifiableMap(attributes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.keycloak.models.mongo.api;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public abstract class AbstractNoSQLObject implements NoSQLObject {

@Override
public void afterRemove(NoSQL noSQL) {
// Empty by default
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.keycloak.models.mongo.api;

import java.util.Map;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public interface AttributedNoSQLObject extends NoSQLObject {

void setAttribute(String name, String value);

void removeAttribute(String name);

String getAttribute(String name);

Map<String, String> getAttributes();
}
37 changes: 37 additions & 0 deletions model/mongo/src/main/java/org/keycloak/models/mongo/api/NoSQL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.keycloak.models.mongo.api;

import java.util.List;

import org.keycloak.models.mongo.api.query.NoSQLQuery;
import org.keycloak.models.mongo.api.query.NoSQLQueryBuilder;
import org.picketlink.common.properties.Property;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public interface NoSQL {

/**
* Insert object if it's oid is null. Otherwise update
*/
void saveObject(NoSQLObject object);

<T extends NoSQLObject> T loadObject(Class<T> type, String oid);

<T extends NoSQLObject> T loadSingleObject(Class<T> type, NoSQLQuery query);

<T extends NoSQLObject> List<T> loadObjects(Class<T> type, NoSQLQuery query);

// Object must have filled oid
void removeObject(NoSQLObject object);

void removeObject(Class<? extends NoSQLObject> type, String oid);

void removeObjects(Class<? extends NoSQLObject> type, NoSQLQuery query);

NoSQLQueryBuilder createQueryBuilder();

<S> void pushItemToList(NoSQLObject object, String listPropertyName, S itemToPush);

<S> void pullItemFromList(NoSQLObject object, String listPropertyName, S itemToPull);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.keycloak.models.mongo.api;

import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
@Target({TYPE})
@Documented
@Retention(RUNTIME)
@Inherited
public @interface NoSQLCollection {

String collectionName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.keycloak.models.mongo.api;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
@Target({METHOD, FIELD})
@Documented
@Retention(RUNTIME)
public @interface NoSQLField {

// TODO: fieldName add lazy loading?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.keycloak.models.mongo.api;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
@Target({METHOD, FIELD})
@Documented
@Retention(RUNTIME)
public @interface NoSQLId {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.keycloak.models.mongo.api;

/**
* Base interface for object, which is persisted in NoSQL database
*
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public interface NoSQLObject {

/**
* Lifecycle callback, which is called after removal of this object from NoSQL database.
* It may be useful for triggering removal of wired objects.
*/
void afterRemove(NoSQL noSQL);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.keycloak.models.mongo.api.query;

import java.util.Collections;
import java.util.Map;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public class NoSQLQuery {

private final Map<String, Object> queryAttributes;

NoSQLQuery(Map<String, Object> queryAttributes) {
this.queryAttributes = queryAttributes;
};

public Map<String, Object> getQueryAttributes() {
return Collections.unmodifiableMap(queryAttributes);
}

@Override
public String toString() {
return "NoSQLQuery [" + queryAttributes + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.keycloak.models.mongo.api.query;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public abstract class NoSQLQueryBuilder {

private Map<String, Object> queryAttributes = new HashMap<String, Object>();

protected NoSQLQueryBuilder() {};

public NoSQLQuery build() {
return new NoSQLQuery(queryAttributes);
}

public NoSQLQueryBuilder andCondition(String name, Object value) {
this.put(name, value);
return this;
}

public abstract NoSQLQueryBuilder inCondition(String name, List<?> values);

protected void put(String name, Object value) {
queryAttributes.put(name, value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.keycloak.models.mongo.api.types;

/**
* SPI object to convert object from application type to database type and vice versa. Shouldn't be directly used by application.
* Various converters should be registered in TypeConverter, which is main entry point to be used by application
*
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public interface Converter<T, S> {

S convertObject(T objectToConvert);

Class<? extends T> getConverterObjectType();

Class<S> getExpectedReturnType();
}
Loading