Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Gabriel Cardoso 2013-11-26 12:27:28 -02:00
commit e3cee387e8
12 changed files with 97 additions and 46 deletions

View file

@ -431,8 +431,8 @@ module.directive('onoffswitch', function() {
offText: '@offText' offText: '@offText'
}, },
compile: function(element, attrs) { compile: function(element, attrs) {
if (!attrs.onText) { attrs.onText = "ON"; } if (!attrs.onText) { attrs.onText = "YES"; }
if (!attrs.offText) { attrs.offText = "OFF"; } if (!attrs.offText) { attrs.offText = "NO"; }
var html = "<div class=\"onoffswitch\">" + var html = "<div class=\"onoffswitch\">" +
"<input type=\"checkbox\" data-ng-model=\"ngModel\" class=\"onoffswitch-checkbox\" name=\"" + attrs.name + "\" id=\"" + attrs.id + "\">" + "<input type=\"checkbox\" data-ng-model=\"ngModel\" class=\"onoffswitch-checkbox\" name=\"" + attrs.name + "\" id=\"" + attrs.id + "\">" +

View file

@ -484,16 +484,29 @@ module.controller('RealmSocialCtrl', function($scope, realm, Realm, $location, N
}); });
module.controller('RealmTokenDetailCtrl', function($scope, Realm, realm, $http, $location, Dialog, Notifications) { module.controller('RealmTokenDetailCtrl', function($scope, Realm, realm, $http, $location, Dialog, Notifications, TimeUnit) {
console.log('RealmTokenDetailCtrl'); console.log('RealmTokenDetailCtrl');
$scope.realm = { id : realm.id, realm : realm.realm, social : realm.social, registrationAllowed : realm.registrationAllowed, $scope.realm = { id : realm.id, realm : realm.realm, social : realm.social, registrationAllowed : realm.registrationAllowed };
tokenLifespan : realm.tokenLifespan, accessCodeLifespan : realm.accessCodeLifespan,
accessCodeLifespanUserAction : realm.accessCodeLifespanUserAction }; $scope.realm.tokenLifespanUnit = TimeUnit.autoUnit(realm.tokenLifespan);
$scope.realm.tokenLifespan = TimeUnit.toUnit(realm.tokenLifespan, $scope.realm.tokenLifespanUnit);
$scope.$watch('realm.tokenLifespanUnit', function(to, from) {
$scope.realm.tokenLifespan = TimeUnit.convert($scope.realm.tokenLifespan, from, to);
});
$scope.realm.accessCodeLifespanUnit = TimeUnit.autoUnit(realm.accessCodeLifespan);
$scope.realm.accessCodeLifespan = TimeUnit.toUnit(realm.accessCodeLifespan, $scope.realm.accessCodeLifespanUnit);
$scope.$watch('realm.accessCodeLifespanUnit', function(to, from) {
$scope.realm.accessCodeLifespan = TimeUnit.convert($scope.realm.accessCodeLifespan, from, to);
});
$scope.realm.accessCodeLifespanUserActionUnit = TimeUnit.autoUnit(realm.accessCodeLifespanUserAction);
$scope.realm.accessCodeLifespanUserAction = TimeUnit.toUnit(realm.accessCodeLifespanUserAction, $scope.realm.accessCodeLifespanUserActionUnit);
$scope.$watch('realm.accessCodeLifespanUserActionUnit', function(to, from) {
$scope.realm.accessCodeLifespanUserAction = TimeUnit.convert($scope.realm.accessCodeLifespanUserAction, from, to);
});
$scope.realm.tokenLifespanUnit = 'Seconds';
$scope.realm.accessCodeLifespanUnit = 'Seconds';
$scope.realm.accessCodeLifespanUserActionUnit = 'Seconds';
var oldCopy = angular.copy($scope.realm); var oldCopy = angular.copy($scope.realm);
$scope.changed = false; $scope.changed = false;
@ -509,27 +522,11 @@ module.controller('RealmTokenDetailCtrl', function($scope, Realm, realm, $http,
delete realmCopy["tokenLifespanUnit"]; delete realmCopy["tokenLifespanUnit"];
delete realmCopy["accessCodeLifespanUnit"]; delete realmCopy["accessCodeLifespanUnit"];
delete realmCopy["accessCodeLifespanUserActionUnit"]; delete realmCopy["accessCodeLifespanUserActionUnit"];
if ($scope.realm.tokenLifespanUnit == 'Minutes') {
realmCopy.tokenLifespan = $scope.realm.tokenLifespan * 60; realmCopy.tokenLifespan = TimeUnit.toSeconds($scope.realm.tokenLifespan, $scope.realm.tokenLifespanUnit)
} else if ($scope.realm.tokenLifespanUnit == 'Hours') { realmCopy.accessCodeLifespan = TimeUnit.toSeconds($scope.realm.accessCodeLifespan, $scope.realm.accessCodeLifespanUnit)
realmCopy.tokenLifespan = $scope.realm.tokenLifespan * 60 * 60; realmCopy.accessCodeLifespanUserAction = TimeUnit.toSeconds($scope.realm.accessCodeLifespanUserAction, $scope.realm.accessCodeLifespanUserActionUnit)
} else if ($scope.realm.tokenLifespanUnit == 'Days') {
realmCopy.tokenLifespan = $scope.realm.tokenLifespan * 60 * 60 * 24;
}
if ($scope.realm.accessCodeLifespanUnit == 'Minutes') {
realmCopy.accessCodeLifespan = $scope.realm.accessCodeLifespan * 60;
} else if ($scope.realm.accessCodeLifespanUnit == 'Hours') {
realmCopy.accessCodeLifespan = $scope.realm.accessCodeLifespan * 60 * 60;
} else if ($scope.realm.accessCodeLifespanUnit == 'Days') {
realmCopy.accessCodeLifespan = $scope.realm.accessCodeLifespan * 60 * 60 * 24;
}
if ($scope.realm.accessCodeLifespanUserActionUnit == 'Minutes') {
realmCopy.accessCodeLifespanUserAction = $scope.realm.accessCodeLifespanUserAction * 60;
} else if ($scope.realm.accessCodeLifespanUserActionUnit == 'Hours') {
realmCopy.accessCodeLifespanUserAction = $scope.realm.accessCodeLifespanUserAction * 60 * 60;
} else if ($scope.realm.accessCodeLifespanUserActionUnit == 'Days') {
realmCopy.accessCodeLifespanUserAction = $scope.realm.accessCodeLifespanUserAction * 60 * 60 * 24;
}
$scope.changed = false; $scope.changed = false;
Realm.update(realmCopy, function () { Realm.update(realmCopy, function () {
$location.url("/realms/" + realm.id + "/token-settings"); $location.url("/realms/" + realm.id + "/token-settings");

View file

@ -120,9 +120,15 @@ module.controller('UserListCtrl', function($scope, realm, User) {
$scope.realm = realm; $scope.realm = realm;
$scope.searchQuery = function() { $scope.searchQuery = function() {
$scope.searchLoaded = false; $scope.searchLoaded = false;
if ($scope.search) {
$scope.currentSearch = $scope.search;
$scope.users = User.query({ realm: realm.id, search : $scope.search }, function() { $scope.users = User.query({ realm: realm.id, search : $scope.search }, function() {
$scope.searchLoaded = true; $scope.searchLoaded = true;
}); });
} else {
$scope.currentSearch = null;
$scope.users = null;
}
}; };
}); });

View file

@ -226,9 +226,6 @@ module.factory('ApplicationOrigins', function($resource) {
}); });
}); });
module.factory('Current', function(Realm, $route) { module.factory('Current', function(Realm, $route) {
var current = {}; var current = {};
@ -254,3 +251,51 @@ module.factory('Current', function(Realm, $route) {
return current; return current;
}); });
module.factory('TimeUnit', function() {
var t = {};
t.autoUnit = function(time) {
var unit = 'Seconds';
if (time % 60 == 0) {
unit = 'Minutes';
time = time / 60;
}
if (time % 60 == 0) {
unit = 'Hours';
time = time / 60;
}
if (time % 24 == 0) {
unit = 'Days'
time = time / 24;
}
return unit;
}
t.toSeconds = function(time, unit) {
switch (unit) {
case 'Seconds': return time;
case 'Minutes': return time * 60;
case 'Hours': return time * 360;
case 'Days': return time * 86400;
default: throw 'invalid unit ' + unit;
}
}
t.toUnit = function(time, unit) {
switch (unit) {
case 'Seconds': return time;
case 'Minutes': return Math.ceil(time / 60);
case 'Hours': return Math.ceil(time / 360);
case 'Days': return Math.ceil(time / 86400);
default: throw 'invalid unit ' + unit;
}
}
t.convert = function(time, from, to) {
var seconds = t.toSeconds(time, from);
return t.toUnit(seconds, to);
}
return t;
});

View file

@ -28,7 +28,7 @@
<div class="input-group"> <div class="input-group">
<input type="text" data-ng-model="realm.tokenLifespan" id="tokenLifespan" name="tokenLifespan" class="tiny"> <input type="text" data-ng-model="realm.tokenLifespan" id="tokenLifespan" name="tokenLifespan" class="tiny">
<div class="select-rcue"> <div class="select-rcue">
<select name="tokenLifespanUnit" data-ng-model="realm.tokenLifespanUnit"> <select name="tokenLifespanUnit" data-ng-model="realm.tokenLifespanUnit" >
<option data-ng-selected="!realm.tokenLifespanUnit">Seconds</option> <option data-ng-selected="!realm.tokenLifespanUnit">Seconds</option>
<option>Minutes</option> <option>Minutes</option>
<option>Hours</option> <option>Hours</option>

View file

@ -33,7 +33,7 @@
</th> </th>
</tr> </tr>
<tr> <tr>
<tr data-ng-show="users.length > 0"> <tr data-ng-show="searchLoaded && users.length > 0">
<th>Username</th> <th>Username</th>
<th>Last Name</th> <th>Last Name</th>
<th>First Name</th> <th>First Name</th>
@ -66,7 +66,7 @@
<div class="feedback warning inline" data-ng-show="searchLoaded && users.length == 0"> <div class="feedback warning inline" data-ng-show="searchLoaded && users.length == 0">
<p><strong>Your search returned no results.</strong><br>Try modifying the query and try again.</p> <p><strong>Your search returned no results.</strong><br>Try modifying the query and try again.</p>
</div> </div>
<div class="feedback info inline" data-ng-show="!search"> <div class="feedback info inline" data-ng-show="!currentSearch">
<br/> <br/>
<p><strong>Search for users.</strong><br>Please enter a search to display users.</p> <p><strong>Search for users.</strong><br>Please enter a search to display users.</p>
</div> </div>

View file

@ -14,7 +14,7 @@
<xsl:copy> <xsl:copy>
<xsl:apply-templates select="node()|@*"/> <xsl:apply-templates select="node()|@*"/>
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true"> <datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:${jboss.server.data.dir}/keycloak;DB_CLOSE_DELAY=-1</connection-url> <connection-url>jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE</connection-url>
<driver>h2</driver> <driver>h2</driver>
<security> <security>
<user-name>sa</user-name> <user-name>sa</user-name>

View file

@ -14,7 +14,7 @@
<xsl:copy> <xsl:copy>
<xsl:apply-templates select="node()|@*"/> <xsl:apply-templates select="node()|@*"/>
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true"> <datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:${jboss.server.data.dir}/keycloak;DB_CLOSE_DELAY=-1</connection-url> <connection-url>jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE</connection-url>
<driver>h2</driver> <driver>h2</driver>
<security> <security>
<user-name>sa</user-name> <user-name>sa</user-name>

View file

@ -38,6 +38,7 @@
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId> <artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.entitymanager.version}</version> <version>${hibernate.entitymanager.version}</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jboss.resteasy</groupId> <groupId>org.jboss.resteasy</groupId>

View file

@ -666,7 +666,8 @@ public class RealmAdapter implements RealmModel {
@Override @Override
public List<UserModel> searchForUser(String search) { public List<UserModel> searchForUser(String search) {
TypedQuery<UserEntity> query = em.createQuery("select u from UserEntity u where lower(u.loginName) like :search or lower(concat(u.firstName, ' ', u.lastName)) like :search or u.email like :search", UserEntity.class); TypedQuery<UserEntity> query = em.createQuery("select u from UserEntity u where u.realm = :realm and lower(u.loginName) like :search or lower(concat(u.firstName, ' ', u.lastName)) like :search or u.email like :search", UserEntity.class);
query.setParameter("realm", realm);
query.setParameter("search", "%" + search.toLowerCase() + "%"); query.setParameter("search", "%" + search.toLowerCase() + "%");
List<UserEntity> results = query.getResultList(); List<UserEntity> results = query.getResultList();
List<UserModel> users = new ArrayList<UserModel>(); List<UserModel> users = new ArrayList<UserModel>();

View file

@ -15,7 +15,7 @@
<mongo.driver.version>2.11.2</mongo.driver.version> <mongo.driver.version>2.11.2</mongo.driver.version>
<jboss.logging.version>3.1.1.GA</jboss.logging.version> <jboss.logging.version>3.1.1.GA</jboss.logging.version>
<hibernate.javax.persistence.version>1.0.1.Final</hibernate.javax.persistence.version> <hibernate.javax.persistence.version>1.0.1.Final</hibernate.javax.persistence.version>
<hibernate.entitymanager.version>3.6.6.Final</hibernate.entitymanager.version> <hibernate.entitymanager.version>4.0.1.Final</hibernate.entitymanager.version>
<h2.version>1.3.161</h2.version> <h2.version>1.3.161</h2.version>
<dom4j.version>1.6.1</dom4j.version> <dom4j.version>1.6.1</dom4j.version>
<mysql.version>5.1.25</mysql.version> <mysql.version>5.1.25</mysql.version>

View file

@ -303,6 +303,7 @@ public class AdapterTest extends AbstractKeycloakTest {
} }
RealmManager adapter = getRealmManager(); RealmManager adapter = getRealmManager();
adapter.createRealm("other").addUser("bburke");
{ {
List<UserModel> userModels = adapter.searchUsers("total junk query", realmModel); List<UserModel> userModels = adapter.searchUsers("total junk query", realmModel);