Merge pull request #584 from patriot1burke/master

fix fed example
This commit is contained in:
Bill Burke 2014-08-03 11:04:21 -04:00
commit d96b660686
11 changed files with 53 additions and 19 deletions

View file

@ -36,21 +36,19 @@ public abstract class BasePropertiesFederationFactory implements UserFederationP
props = new Properties();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
if (is == null) {
throw new IllegalStateException("Path attribute not configured for provider");
}
InputStream is = getPropertiesFileStream(path);
try {
props.load(is);
is.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
props.put(path, props);
files.put(path, props);
return createProvider(session, model, props);
}
protected abstract InputStream getPropertiesFileStream(String path);
protected abstract BasePropertiesFederationProvider createProvider(KeycloakSession session, UserFederationProviderModel model, Properties props);

View file

@ -59,7 +59,8 @@ public abstract class BasePropertiesFederationProvider implements UserFederation
String password = properties.getProperty(username);
if (password != null) {
UserModel userModel = session.userStorage().addUser(realm, username);
userModel.updateCredential(UserCredentialModel.password(password));
userModel.setEnabled(true);
userModel.setFederationLink(model.getId());
return userModel;
}
return null;
@ -72,12 +73,16 @@ public abstract class BasePropertiesFederationProvider implements UserFederation
@Override
public List<UserModel> searchByAttributes(Map<String, String> attributes, RealmModel realm, int maxResults) {
if (attributes.containsKey(USERNAME)) {
UserModel user = getUserByUsername(realm, attributes.get(USERNAME));
if (user != null) {
List<UserModel> list = new ArrayList<UserModel>(1);
list.add(user);
return list;
String username = attributes.get(USERNAME);
if (username != null) {
// make sure user isn't already in storage
if (session.userStorage().getUserByUsername(username, realm) == null) {
UserModel user = getUserByUsername(realm, username);
if (user != null) {
List<UserModel> list = new ArrayList<UserModel>(1);
list.add(user);
return list;
}
}
}
return Collections.emptyList();

View file

@ -26,6 +26,16 @@ public class ClasspathPropertiesFederationFactory extends BasePropertiesFederati
return new ClasspathPropertiesFederationProvider(session, model, props);
}
protected InputStream getPropertiesFileStream(String path) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
if (is == null) {
throw new IllegalStateException("Path not found for properties file");
}
return is;
}
@Override
public String getId() {

View file

@ -3,6 +3,9 @@ package org.keycloak.examples.federation.properties;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.UserFederationProviderModel;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
/**
@ -15,6 +18,15 @@ public class FilePropertiesFederationFactory extends BasePropertiesFederationFac
protected BasePropertiesFederationProvider createProvider(KeycloakSession session, UserFederationProviderModel model, Properties props) {
return new FilePropertiesFederationProvider(session, props, model);
}
protected InputStream getPropertiesFileStream(String path) {
try {
return new FileInputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
@Override

View file

@ -51,16 +51,15 @@ public class WritableUserModelProxy extends UserModelDelegate {
@Override
public void updateCredential(UserCredentialModel cred) {
if (cred.getType().equals(UserCredentialModel.PASSWORD)) {
} else {
super.updateCredential(cred);
synchronized (provider.getProperties()) {
if (!provider.getProperties().containsKey(delegate.getUsername())) {
throw new IllegalStateException("no user of that in properties file");
}
provider.getProperties().put(delegate.getUsername(), cred.getValue());
provider.getProperties().setProperty(delegate.getUsername(), cred.getValue());
provider.save();
}
} else {
super.updateCredential(cred);
}
}
}

View file

@ -0,0 +1 @@
tbrady=superbowl

View file

@ -0,0 +1,3 @@
#
#Sun Aug 03 10:52:57 EDT 2014
belichick=superbowl

View file

@ -164,8 +164,8 @@ module.controller('UserListCtrl', function($scope, realm, User) {
}
$scope.searchQuery = function() {
console.log("query.search: " + $scope.query.search);
$scope.searchLoaded = false;
$scope.currentSearch = $scope.search;
$scope.users = User.query($scope.query, function() {
$scope.searchLoaded = true;

View file

@ -24,7 +24,7 @@
Icon: search
</button>
</div>
<span><span>or</span><button class="kc-link" ng-click="search = null; searchQuery()">View all users</button></span>
<span><span>or</span><button class="kc-link" ng-click="query.search = null; searchQuery()">View all users</button></span>
<div class="pull-right">
<a class="btn btn-primary" href="#/create/user/{{realm.realm}}">Add User</a>
</div>

View file

@ -473,6 +473,7 @@ public class AccountService {
try {
session.users().updateCredential(realm, user, UserCredentialModel.password(passwordNew));
} catch (Exception ape) {
logger.error("Failed to update password", ape);
return account.setError(ape.getMessage()).createResponse(AccountPages.PASSWORD);
}

View file

@ -124,6 +124,11 @@
<artifactId>keycloak-undertow-adapter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>federation-properties-example</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>