Skip to content

Instantly share code, notes, and snippets.

@jbunting
Created October 2, 2014 16:12
Show Gist options
  • Save jbunting/f12588db598740fc2e2c to your computer and use it in GitHub Desktop.
Save jbunting/f12588db598740fc2e2c to your computer and use it in GitHub Desktop.
stormpath-shiro customdata proposal
diff --git a/core/src/main/java/com/stormpath/shiro/realm/ApplicationRealm.java b/core/src/main/java/com/stormpath/shiro/realm/ApplicationRealm.java
index 24d9744..9d0f61f 100644
--- a/core/src/main/java/com/stormpath/shiro/realm/ApplicationRealm.java
+++ b/core/src/main/java/com/stormpath/shiro/realm/ApplicationRealm.java
@@ -20,9 +20,13 @@ import com.stormpath.sdk.application.Application;
import com.stormpath.sdk.authc.AuthenticationRequest;
import com.stormpath.sdk.authc.UsernamePasswordRequest;
import com.stormpath.sdk.client.Client;
+import com.stormpath.sdk.directory.CustomData;
import com.stormpath.sdk.group.Group;
import com.stormpath.sdk.group.GroupList;
import com.stormpath.sdk.resource.ResourceException;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.PropertyUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
@@ -141,6 +145,7 @@ public class ApplicationRealm extends AuthorizingRealm {
private GroupPermissionResolver groupPermissionResolver;
private AccountPermissionResolver accountPermissionResolver;
private AccountRoleResolver accountRoleResolver;
+ private Map<String, String> customDataMappings;
private Application application; //acquired via the client at runtime, not configurable by the Realm user
@@ -305,6 +310,14 @@ public class ApplicationRealm extends AuthorizingRealm {
this.accountRoleResolver = accountRoleResolver;
}
+ public Map<String, String> getCustomDataMappings() {
+ return customDataMappings;
+ }
+
+ public void setCustomDataMappings(final Map<String, String> customDataMappings) {
+ this.customDataMappings = customDataMappings;
+ }
+
@Override
protected void onInit() {
super.onInit();
@@ -389,6 +402,11 @@ public class ApplicationRealm extends AuthorizingRealm {
nullSafePut(props, "givenName", account.getGivenName());
nullSafePut(props, "middleName", account.getMiddleName());
nullSafePut(props, "surname", account.getSurname());
+ final CustomData customData = account.getCustomData();
+
+ for (String key : customDataMappings.keySet()) {
+ nullSafePut(props, customDataMappings.get(key), customData.get(key).toString());
+ }
Collection<Object> principals = new ArrayList<Object>(2);
principals.add(account.getHref());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment