Skip to content

Commit

Permalink
component model
Browse files Browse the repository at this point in the history
  • Loading branch information
patriot1burke committed Aug 1, 2016
1 parent bd499e1 commit 91a267a
Show file tree
Hide file tree
Showing 92 changed files with 2,080 additions and 1,027 deletions.
@@ -0,0 +1,101 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.keycloak.representations.idm;

import org.keycloak.common.util.MultivaluedHashMap;

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

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
public class ComponentRepresentation {

private String id;
private String name;
private String providerId;
private String providerType;
private String parentId;
private MultivaluedHashMap<String, String> config;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getProviderId() {
return providerId;
}

public void setProviderId(String providerId) {
this.providerId = providerId;
}

public String getProviderType() {
return providerType;
}

public void setProviderType(String providerType) {
this.providerType = providerType;
}

public String getParentId() {
return parentId;
}

public void setParentId(String parentId) {
this.parentId = parentId;
}

public MultivaluedHashMap<String, String> getConfig() {
return config;
}

public void setConfig(MultivaluedHashMap<String, String> config) {
this.config = config;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

ComponentRepresentation that = (ComponentRepresentation) o;

if (!id.equals(that.id)) return false;

return true;
}

@Override
public int hashCode() {
return id.hashCode();
}
}
@@ -0,0 +1,57 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.keycloak.representations.idm;

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

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
public class ComponentTypeRepresentation {
protected String id;
protected String helpText;
protected List<ConfigPropertyRepresentation> properties;


public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getHelpText() {
return helpText;
}

public void setHelpText(String helpText) {
this.helpText = helpText;
}

public List<ConfigPropertyRepresentation> getProperties() {
return properties;
}

public void setProperties(List<ConfigPropertyRepresentation> properties) {
this.properties = properties;
}
}
Expand Up @@ -15,20 +15,36 @@
* limitations under the License. * limitations under the License.
*/ */


package org.keycloak.models.entities; package org.keycloak.representations.idm;


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


/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
* @version $Revision: 1 $
*/ */
public class StorageProviderEntity extends AbstractIdentifiableEntity { public class StorageProviderRepresentation {
protected String providerName;
protected Map<String, String> config;
protected int priority;
protected String displayName;


private String id;
private String displayName;
private String providerName;
private Map<String, String> config;
private int priority;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getDisplayName() {
return displayName;
}

public void setDisplayName(String displayName) {
this.displayName = displayName;
}


public String getProviderName() { public String getProviderName() {
return providerName; return providerName;
Expand All @@ -38,6 +54,7 @@ public void setProviderName(String providerName) {
this.providerName = providerName; this.providerName = providerName;
} }



public Map<String, String> getConfig() { public Map<String, String> getConfig() {
return config; return config;
} }
Expand All @@ -54,12 +71,20 @@ public void setPriority(int priority) {
this.priority = priority; this.priority = priority;
} }


public String getDisplayName() { @Override
return displayName; public boolean equals(Object o) {
} if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;


public void setDisplayName(String displayName) { StorageProviderRepresentation that = (StorageProviderRepresentation) o;
this.displayName = displayName;
if (!id.equals(that.id)) return false;

return true;
} }


@Override
public int hashCode() {
return id.hashCode();
}
} }
Expand Up @@ -17,6 +17,7 @@


package org.keycloak.representations.info; package org.keycloak.representations.info;


import org.keycloak.representations.idm.ComponentTypeRepresentation;
import org.keycloak.representations.idm.PasswordPolicyTypeRepresentation; import org.keycloak.representations.idm.PasswordPolicyTypeRepresentation;
import org.keycloak.representations.idm.ProtocolMapperRepresentation; import org.keycloak.representations.idm.ProtocolMapperRepresentation;
import org.keycloak.representations.idm.ProtocolMapperTypeRepresentation; import org.keycloak.representations.idm.ProtocolMapperTypeRepresentation;
Expand All @@ -43,6 +44,7 @@ public class ServerInfoRepresentation {
private Map<String, List<ProtocolMapperTypeRepresentation>> protocolMapperTypes; private Map<String, List<ProtocolMapperTypeRepresentation>> protocolMapperTypes;
private Map<String, List<ProtocolMapperRepresentation>> builtinProtocolMappers; private Map<String, List<ProtocolMapperRepresentation>> builtinProtocolMappers;
private Map<String, List<ClientInstallationRepresentation>> clientInstallations; private Map<String, List<ClientInstallationRepresentation>> clientInstallations;
private Map<String, List<ComponentTypeRepresentation>> componentTypes;


private List<PasswordPolicyTypeRepresentation> passwordPolicies; private List<PasswordPolicyTypeRepresentation> passwordPolicies;


Expand Down Expand Up @@ -144,4 +146,11 @@ public void setPasswordPolicies(List<PasswordPolicyTypeRepresentation> passwordP
this.passwordPolicies = passwordPolicies; this.passwordPolicies = passwordPolicies;
} }


public Map<String, List<ComponentTypeRepresentation>> getComponentTypes() {
return componentTypes;
}

public void setComponentTypes(Map<String, List<ComponentTypeRepresentation>> componentTypes) {
this.componentTypes = componentTypes;
}
} }
1 change: 1 addition & 0 deletions examples/providers/pom.xml
Expand Up @@ -37,5 +37,6 @@
<module>authenticator</module> <module>authenticator</module>
<module>rest</module> <module>rest</module>
<module>domain-extension</module> <module>domain-extension</module>
<module>user-storage-jpa</module>
</modules> </modules>
</project> </project>
@@ -0,0 +1,118 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.examples.storage.user;

import org.keycloak.component.ComponentModel;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.storage.StorageId;
import org.keycloak.storage.UserStorageProvider;
import org.keycloak.storage.user.UserLookupProvider;
import org.keycloak.storage.user.UserRegistrationProvider;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import java.util.List;

/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class ExampleUserStorageProvider implements UserStorageProvider, UserLookupProvider, UserRegistrationProvider {
protected EntityManager em;
protected ComponentModel model;
protected KeycloakSession session;

public ExampleUserStorageProvider(EntityManager em, ComponentModel model, KeycloakSession session) {
this.em = em;
this.model = model;
this.session = session;
}

@Override
public void preRemove(RealmModel realm) {

}

@Override
public void preRemove(RealmModel realm, GroupModel group) {

}

@Override
public void preRemove(RealmModel realm, RoleModel role) {

}

@Override
public void close() {
em.close();
}

@Override
public UserModel getUserById(String id, RealmModel realm) {
String persistenceId = StorageId.externalId(id);
UserEntity entity = em.find(UserEntity.class, persistenceId);
if (entity == null) return null;
return new UserAdapter(session, realm, model, entity);
}

@Override
public UserModel getUserByUsername(String username, RealmModel realm) {
TypedQuery<UserEntity> query = em.createNamedQuery("getUserByUsername", UserEntity.class);
query.setParameter("username", username);
List<UserEntity> result = query.getResultList();
if (result.isEmpty()) return null;
return new UserAdapter(session, realm, model, result.get(0));
}

@Override
public UserModel getUserByEmail(String email, RealmModel realm) {
TypedQuery<UserEntity> query = em.createNamedQuery("getUserByEmail", UserEntity.class);
query.setParameter("email", email);
List<UserEntity> result = query.getResultList();
if (result.isEmpty()) return null;
return new UserAdapter(session, realm, model, result.get(0));
}

@Override
public UserModel addUser(RealmModel realm, String username) {
UserEntity entity = new UserEntity();
entity.setId(KeycloakModelUtils.generateId());
entity.setUsername(username);
em.persist(entity);
return new UserAdapter(session, realm, model, entity);
}

@Override
public boolean removeUser(RealmModel realm, UserModel user) {
String persistenceId = StorageId.externalId(user.getId());
UserEntity entity = em.find(UserEntity.class, persistenceId);
if (entity == null) return false;
em.remove(entity);
return true;
}

@Override
public void grantToAllUsers(RealmModel realm, RoleModel role) {

}
}

0 comments on commit 91a267a

Please sign in to comment.