model module refactor

This commit is contained in:
Bill Burke committed 2013-10-02 09:54:26 -04:00
1 parent 2fb61f5a80
commit a4e3431445
96 files changed
+449 -276

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<project>
<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-api</artifactId>
<name>Keycloak Model API</name>
<description/>
<dependencies>
</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>
@@ -0,0 +1,54 @@
package org.keycloak.models;
import java.util.List;
import java.util.Set;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface ApplicationModel {
void updateResource();
UserModel getResourceUser();
String getId();
String getName();
void setName(String name);
boolean isEnabled();
void setEnabled(boolean enabled);
boolean isSurrogateAuthRequired();
void setSurrogateAuthRequired(boolean surrogateAuthRequired);
String getManagementUrl();
void setManagementUrl(String url);
RoleModel getRole(String name);
RoleModel addRole(String name);
List<RoleModel> getRoles();
Set<String> getRoleMappingValues(UserModel user);
void addScope(UserModel agent, String roleName);
void addScope(UserModel agent, RoleModel role);
Set<String> getScope(UserModel agent);
List<RoleModel> getRoleMappings(UserModel user);
void deleteRoleMapping(UserModel user, RoleModel role);
RoleModel getRoleById(String id);
void grantRole(UserModel user, RoleModel role);
}
@@ -0,0 +1,15 @@
package org.keycloak.models;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class IdGenerator {
private static AtomicLong counter = new AtomicLong(1);
public static String generateId() {
return counter.getAndIncrement() + "-" + System.currentTimeMillis();
}
}
@@ -0,0 +1,19 @@
package org.keycloak.models;
import java.util.List;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface KeycloakSession {
KeycloakTransaction getTransaction();
RealmModel createRealm(String name);
RealmModel createRealm(String id, String name);
RealmModel getRealm(String id);
List<RealmModel> getRealms(UserModel admin);
void deleteRealm(RealmModel realm);
void close();
}
@@ -0,0 +1,10 @@
package org.keycloak.models;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface KeycloakSessionFactory {
KeycloakSession createSession();
void close();
}
@@ -0,0 +1,13 @@
package org.keycloak.models;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface KeycloakTransaction {
void begin();
void commit();
void rollback();
void setRollbackOnly();
boolean getRollbackOnly();
boolean isActive();}
+163
View File
@@ -0,0 +1,163 @@
package org.keycloak.models;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface RealmModel {
String DEFAULT_REALM = "default";
String getId();
String getName();
void setName(String name);
boolean isEnabled();
void setEnabled(boolean enabled);
boolean isSslNotRequired();
void setSslNotRequired(boolean sslNotRequired);
boolean isCookieLoginAllowed();
void setCookieLoginAllowed(boolean cookieLoginAllowed);
boolean isRegistrationAllowed();
void setRegistrationAllowed(boolean registrationAllowed);
boolean isVerifyEmail();
void setVerifyEmail(boolean verifyEmail);
boolean isResetPasswordAllowed();
void setResetPasswordAllowed(boolean resetPasswordAllowed);
int getTokenLifespan();
void setTokenLifespan(int tokenLifespan);
int getAccessCodeLifespan();
void setAccessCodeLifespan(int accessCodeLifespan);
int getAccessCodeLifespanUserAction();
void setAccessCodeLifespanUserAction(int accessCodeLifespanUserAction);
String getPublicKeyPem();
void setPublicKeyPem(String publicKeyPem);
String getPrivateKeyPem();
void setPrivateKeyPem(String privateKeyPem);
PublicKey getPublicKey();
void setPublicKey(PublicKey publicKey);
PrivateKey getPrivateKey();
void setPrivateKey(PrivateKey privateKey);
List<RequiredCredentialModel> getRequiredCredentials();
void addRequiredCredential(String cred);
boolean validatePassword(UserModel user, String password);
boolean validateTOTP(UserModel user, String password, String token);
void updateCredential(UserModel user, UserCredentialModel cred);
UserModel getUser(String name);
UserModel addUser(String username);
RoleModel getRole(String name);
RoleModel addRole(String name);
List<RoleModel> getRoles();
List<RoleModel> getDefaultRoles();
void addDefaultRole(String name);
void updateDefaultRoles(String[] defaultRoles);
Map<String, ApplicationModel> getResourceNameMap();
List<ApplicationModel> getApplications();
ApplicationModel addApplication(String name);
boolean hasRole(UserModel user, RoleModel role);
void grantRole(UserModel user, RoleModel role);
Set<String> getRoleMappingValues(UserModel user);
void addScope(UserModel agent, String roleName);
Set<String> getScope(UserModel agent);
boolean isRealmAdmin(UserModel agent);
void addRealmAdmin(UserModel agent);
RoleModel getRoleById(String id);
List<RequiredCredentialModel> getRequiredApplicationCredentials();
List<RequiredCredentialModel> getRequiredOAuthClientCredentials();
boolean hasRole(UserModel user, String role);
ApplicationModel getApplicationById(String id);
void addRequiredOAuthClientCredential(String type);
void addRequiredResourceCredential(String type);
void updateRequiredCredentials(Set<String> creds);
void updateRequiredOAuthClientCredentials(Set<String> creds);
void updateRequiredApplicationCredentials(Set<String> creds);
UserModel getUserBySocialLink(SocialLinkModel socialLink);
Set<SocialLinkModel> getSocialLinks(UserModel user);
void addSocialLink(UserModel user, SocialLinkModel socialLink);
void removeSocialLink(UserModel user, SocialLinkModel socialLink);
boolean isSocial();
void setSocial(boolean social);
public boolean isAutomaticRegistrationAfterSocialLogin();
public void setAutomaticRegistrationAfterSocialLogin(boolean automaticRegistrationAfterSocialLogin);
List<UserModel> searchForUserByAttributes(Map<String, String> attributes);
List<RoleModel> getRoleMappings(UserModel user);
void deleteRoleMapping(UserModel user, RoleModel role);
}
@@ -0,0 +1,79 @@
package org.keycloak.models;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RequiredCredentialModel {
protected String type;
protected boolean input;
protected boolean secret;
protected String formLabel;
public RequiredCredentialModel() {
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean isInput() {
return input;
}
public void setInput(boolean input) {
this.input = input;
}
public boolean isSecret() {
return secret;
}
public void setSecret(boolean secret) {
this.secret = secret;
}
public String getFormLabel() {
return formLabel;
}
public void setFormLabel(String formLabel) {
this.formLabel = formLabel;
}
public static final Map<String, RequiredCredentialModel> BUILT_IN;
public static final RequiredCredentialModel PASSWORD;
public static final RequiredCredentialModel TOTP;
public static final RequiredCredentialModel CLIENT_CERT;
static {
Map<String, RequiredCredentialModel> map = new HashMap<String, RequiredCredentialModel>();
PASSWORD = new RequiredCredentialModel();
PASSWORD.setType(UserCredentialModel.PASSWORD);
PASSWORD.setInput(true);
PASSWORD.setSecret(true);
PASSWORD.setFormLabel("password");
map.put(PASSWORD.getType(), PASSWORD);
TOTP = new RequiredCredentialModel();
TOTP.setType(UserCredentialModel.TOTP);
TOTP.setInput(true);
TOTP.setSecret(false);
TOTP.setFormLabel("authenticatorCode");
map.put(TOTP.getType(), TOTP);
CLIENT_CERT = new RequiredCredentialModel();
CLIENT_CERT.setType(UserCredentialModel.CLIENT_CERT);
CLIENT_CERT.setInput(false);
CLIENT_CERT.setSecret(false);
CLIENT_CERT.setFormLabel("clientCertificate");
map.put(CLIENT_CERT.getType(), CLIENT_CERT);
BUILT_IN = Collections.unmodifiableMap(map);
}
}
+17
View File
@@ -0,0 +1,17 @@
package org.keycloak.models;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface RoleModel {
String getName();
String getDescription();
void setDescription(String description);
String getId();
void setName(String name);
}
@@ -0,0 +1,31 @@
package org.keycloak.models;
/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
public class SocialLinkModel {
private String socialUsername;
private String socialProvider;
public SocialLinkModel(String socialProvider, String socialUsername) {
this.socialUsername = socialUsername;
this.socialProvider = socialProvider;
}
public String getSocialUsername() {
return socialUsername;
}
public void setSocialUsername(String socialUsername) {
this.socialUsername = socialUsername;
}
public String getSocialProvider() {
return socialProvider;
}
public void setSocialProvider(String socialProvider) {
this.socialProvider = socialProvider;
}
}
@@ -0,0 +1,39 @@
package org.keycloak.models;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class UserCredentialModel {
public static final String PASSWORD = "password";
public static final String TOTP = "totp";
public static final String CLIENT_CERT = "cert";
protected String type;
protected String value;
protected String device;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getDevice() {
return device;
}
public void setDevice(String device) {
this.device = device;
}
}
+59
View File
@@ -0,0 +1,59 @@
package org.keycloak.models;
import java.util.Map;
import java.util.Set;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface UserModel {
public static final String LOGIN_NAME = "username";
public static final String LAST_NAME = "lastName";
public static final String FIRST_NAME = "firstName";
public static final String EMAIL = "email";
String getLoginName();
boolean isEnabled();
boolean isTotp();
void setEnabled(boolean enabled);
void setAttribute(String name, String value);
void removeAttribute(String name);
String getAttribute(String name);
Map<String, String> getAttributes();
Set<RequiredAction> getRequiredActions();
void addRequiredAction(RequiredAction action);
void removeRequiredAction(RequiredAction action);
String getFirstName();
void setFirstName(String firstName);
String getLastName();
void setLastName(String lastName);
String getEmail();
void setEmail(String email);
boolean isEmailVerified();
void setEmailVerified(boolean verified);
void setTotp(boolean totp);
public static enum RequiredAction {
VERIFY_EMAIL, UPDATE_PROFILE, CONFIGURE_TOTP, UPDATE_PASSWORD
}
}
@@ -0,0 +1,31 @@
package org.keycloak.models.utils;
import java.lang.reflect.Array;
import java.util.Arrays;
public class ArrayUtils {
public static <T> T[] add(T[] src, T o) {
T[] dst = Arrays.copyOf(src, src.length + 1);
dst[src.length] = o;
return dst;
}
public static <T> T[] remove(T[] src, T o) {
int l = Arrays.binarySearch(src, o);
if (l < 0) {
return src;
}
T[] dst = newInstance(o, src.length - 1);
System.arraycopy(src, 0, dst, 0, l);
System.arraycopy(src, l + 1, dst, l, dst.length - l);
return dst;
}
@SuppressWarnings("unchecked")
private static <T extends Object> T[] newInstance(T type, int length) {
return (T[]) Array.newInstance(type.getClass(), length);
}
}