mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-04-12 18:28:49 +00:00
Minor refactoring of GAE code to use specific GrantedAuthority type.
This commit is contained in:
parent
60970dd9c4
commit
51a53ddbaa
@ -1,15 +1,17 @@
|
|||||||
package samples.gae.users;
|
package samples.gae.users;
|
||||||
|
|
||||||
import java.util.Collection;
|
import com.google.appengine.api.datastore.DatastoreService;
|
||||||
import java.util.EnumSet;
|
import com.google.appengine.api.datastore.DatastoreServiceFactory;
|
||||||
import java.util.Set;
|
import com.google.appengine.api.datastore.Entity;
|
||||||
|
import com.google.appengine.api.datastore.EntityNotFoundException;
|
||||||
import com.google.appengine.api.datastore.*;
|
import com.google.appengine.api.datastore.Key;
|
||||||
|
import com.google.appengine.api.datastore.KeyFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import samples.gae.security.AppRole;
|
import samples.gae.security.AppRole;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserRegistry implementation which uses GAE's low-level Datastore APIs.
|
* UserRegistry implementation which uses GAE's low-level Datastore APIs.
|
||||||
*
|
*
|
||||||
@ -70,12 +72,12 @@ public class GaeDatastoreUserRegistry implements UserRegistry {
|
|||||||
user.setProperty(USER_SURNAME, newUser.getSurname());
|
user.setProperty(USER_SURNAME, newUser.getSurname());
|
||||||
user.setUnindexedProperty(USER_ENABLED, newUser.isEnabled());
|
user.setUnindexedProperty(USER_ENABLED, newUser.isEnabled());
|
||||||
|
|
||||||
Collection<? extends GrantedAuthority> roles = newUser.getAuthorities();
|
Collection<AppRole> roles = newUser.getAuthorities();
|
||||||
|
|
||||||
long binaryAuthorities = 0;
|
long binaryAuthorities = 0;
|
||||||
|
|
||||||
for (GrantedAuthority r : roles) {
|
for (AppRole r : roles) {
|
||||||
binaryAuthorities |= 1 << ((AppRole)r).getBit();
|
binaryAuthorities |= 1 << r.getBit();
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setUnindexedProperty(USER_AUTHORITIES, binaryAuthorities);
|
user.setUnindexedProperty(USER_AUTHORITIES, binaryAuthorities);
|
||||||
|
@ -75,7 +75,7 @@ public class GaeUser implements Serializable {
|
|||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<AppRole> getAuthorities() {
|
||||||
return authorities;
|
return authorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user