a Spring Security - CustomUserDetailServiceImpl access to a resource bundle in hippoCMS

9 views
Skip to first unread message

moens...@gmail.com

unread,
Aug 24, 2016, 1:41:46 PM8/24/16
to Hippo Community, thu...@moen.com
I've written a CustomUserDetailServiceImpl.java Spring Security class that handles logging a person into our website.  

I've created a custom loadUserbyUsername(String username) function and have it working to a certain extent.  

I need to modify this function to retrieve a value stored in a ResourceBundle within the Hippo Repository.  I need to figure out how i can obtain the "session" object that i can then use within the snippet of code below: function [  loadUserByUsername(String) ]

 try {
      Node node = session.getRootNode().getNode("content/documents/administration/crm/crm");
      NodeIterator nit = node.getNodes();
      while (nit.hasNext()) {
        Node nod = nit.nextNode();
        if (nod.isNode()
            && nod.getProperty("jcr:primaryType").getValue().getString()
                .equals("resourcebundle:resourcebundle")
            && nod.getProperty("resourcebundle:id").getValue().getString().equals("crm.registration.service")
            && nod.getProperty("hippostd:state").getValue().getString().equals("published")
            && nod.getProperty("hippostd:stateSummary").getValue().getString().equals("live")) {
          Property property = nod.getProperty("resourcebundle:keys");
          Value[] keys = property.getValues();
          property = nod.getProperty("resourcebundle:messages");
          Value[] messages = property.getValues();
          for (int x = 0; x < keys.length; x++) {
            map.put(keys[x].getString(), messages[x].getString());
          }
        }
      }
    } catch (RepositoryException e) {
      System.out.println("ERROR: " + e.getMessage());
    } 



Any Ideas would help greatly,

Thanks,
Theresa

Woonsan Ko

unread,
Aug 24, 2016, 2:00:32 PM8/24/16
to hippo-c...@googlegroups.com
Hi Theresa,

You don't need to get a JCR session to get hippo resource bundles.
Please try this instead:

private ResourceBundle getHstResourceBundle(String basename, Locale locale) {
    ResourceBundle bundle = null;
    ResourceBundleRegistry resourceBundleRegistry = HstServices.getComponentManager().getComponent(ResourceBundleRegistry.class.getName());

    if (resourceBundleRegistry != null) {
        if (locale == null) {
            bundle = resourceBundleRegistry.getBundle(basename));
        } else {
            bundle = resourceBundleRegistry.getBundle(basename, locale));
        }
    }

    return bundle;
}

HTH,

Woonsan


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--
w....@onehippo.com     www.onehippo.com
Boston - 745 Atlantic Ave, 8th Floor, Boston MA 02111
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
Reply all
Reply to author
Forward
0 new messages