Author: [email protected]
Date: Tue Dec 20 12:20:47 2011
New Revision: 1861
Log:
[AMDATUOPENSOCIAL-150] Fixed proepr handling of the case in which a gadgetspec
contains a locale element without a 'messages' attribute
Modified:
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigOpenSocialContainerImpl.java
Modified:
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigOpenSocialContainerImpl.java
==============================================================================
---
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigOpenSocialContainerImpl.java
(original)
+++
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigOpenSocialContainerImpl.java
Tue Dec 20 12:20:47 2011
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.amdatu.opensocial.shindig.service;
-
+package org.amdatu.opensocial.shindig.service;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -62,123 +62,131 @@
import org.osgi.framework.Constants;
import org.osgi.service.log.LogService;
import org.osgi.service.useradmin.UserAdmin;
-
-/**
- * Shindig implementation of the OpenSocialContainer interface.
- *
- * @author ivol
- */
-public class ShindigOpenSocialContainerImpl implements OpenSocialContainer {
- // Timeout for retrieving gadget specs
- private static final int GADGETSPEC_READ_TIMEOUT = 5000;
-
- // Timeout of the gadgetspec cache in milliseconds; when the gadgetspec in
the cache is older then this it will
- // be removed from the cache. Default is 15 minutes.
- private static final int GADGETSPEC_CACHE_TIMEOUT = 15 * 60 * 1000;
-
- // Thread safe implementation of gadget spec cache
- private ConcurrentMap<String, FutureTask<Object[]>> m_gadgetSpecCache =
- new ConcurrentHashMap<String, FutureTask<Object[]>>();
-
- // Service dependencies injected by the dependency manager
- private volatile Tenant m_tenant;
- private volatile LogService m_logService;
- private volatile TokenProvider m_tokenProvider;
- private volatile Component m_component;
+
+/**
+ * Shindig implementation of the OpenSocialContainer interface.
+ *
+ * @author ivol
+ */
+public class ShindigOpenSocialContainerImpl implements OpenSocialContainer {
+ // Timeout for retrieving gadget specs
+ private static final int GADGETSPEC_READ_TIMEOUT = 5000;
+
+ // Timeout of the gadgetspec cache in milliseconds; when the gadgetspec in
the cache is older then this it will
+ // be removed from the cache. Default is 15 minutes.
+ private static final int GADGETSPEC_CACHE_TIMEOUT = 15 * 60 * 1000;
+
+ // Thread safe implementation of gadget spec cache
+ private ConcurrentMap<String, FutureTask<Object[]>> m_gadgetSpecCache =
+ new ConcurrentHashMap<String, FutureTask<Object[]>>();
+
+ // Service dependencies injected by the dependency manager
+ private volatile Tenant m_tenant;
+ private volatile LogService m_logService;
+ private volatile TokenProvider m_tokenProvider;
+ private volatile Component m_component;
private volatile DependencyManager m_dependencyManager;
- private volatile UserAdmin m_userAdmin;
-
- /**
- * The init() method is invoked by the Felix dependency manager.
- */
+ private volatile UserAdmin m_userAdmin;
+
+ /**
+ * The init() method is invoked by the Felix dependency manager.
+ */
public void init() {
List<ServiceDependency> dependencies = new
ArrayList<ServiceDependency>();
-
- // Create a service dependency on the token provider for 'our' tenant
- String tenantFilter =
- "(&(" + Tenant.TENANT_ID_SERVICEPROPERTY + "=" + m_tenant.getId()
+ ")(" + Constants.OBJECTCLASS
- + "=" + TokenProvider.class.getName() + "))";
- dependencies.add(m_dependencyManager.createServiceDependency()
+
+ // Create a service dependency on the token provider for 'our' tenant
+ String tenantFilter =
+ "(&(" + Tenant.TENANT_ID_SERVICEPROPERTY + "=" + m_tenant.getId()
+ ")(" + Constants.OBJECTCLASS
+ + "=" + TokenProvider.class.getName() + "))";
+ dependencies.add(m_dependencyManager.createServiceDependency()
.setService(TokenProvider.class,
tenantFilter).setRequired(true).setInstanceBound(true));
String tenantFilter2 =
"(&(" + Tenant.TENANT_ID_SERVICEPROPERTY + "=" + m_tenant.getId()
+ ")(" + Constants.OBJECTCLASS
- + "=" + UserAdmin.class.getName() + "))";
+ + "=" + UserAdmin.class.getName() + "))";
dependencies.add(m_dependencyManager.createServiceDependency()
- .setService(UserAdmin.class,
tenantFilter2).setRequired(true).setInstanceBound(true));
-
+ .setService(UserAdmin.class,
tenantFilter2).setRequired(true).setInstanceBound(true));
+
m_component.add(dependencies);
-
- m_logService.log(LogService.LOG_INFO, getClass().getName() + " service
initialized");
- }
-
- public void start() {
- m_logService.log(LogService.LOG_INFO,
- this.getClass().getName() + " service started for tenant '" +
m_tenant.getId() + "'");
- }
-
- public String getSecurityToken(final String gadgetUrl, final
HttpServletRequest request) {
- // TODO: This is the same key as in securitytokenkey.txt file of the
shindig application bundle
- // But we are too lazy to load that key from the file
- String key = "Tr9W5GNmfCb7eexNi0m+/HVgAlvsHmCuMEofHs6+LoU=";
- String hostName = request.getServerName();
- BasicBlobCrypter blobCrypter = new BasicBlobCrypter(key.getBytes());
- BlobCrypterSecurityToken st = new
BlobCrypterSecurityToken(blobCrypter, "default", hostName);
- st.setAppUrl(gadgetUrl);
-
- String viewerId = "anonymous";
- String ownerId = "anonymous";
-
- // Verify if we have a valid authentication token holding a user name,
if so add the authenticated user as viewer
- String userName = getViewer(request);
- if (userName != null && !"".equals(userName)) {
- viewerId = userName;
- ownerId = userName;
- }
- st.setViewerId(viewerId);
- st.setOwnerId(ownerId);
-
- String securityToken;
- try {
- securityToken = Utf8UrlCoder.encode(st.encrypt());
- return securityToken;
- }
- catch (BlobCrypterException e) {
- m_logService.log(LogService.LOG_ERROR,
- "Could not create security token for gadget url '" + gadgetUrl
+ "'", e);
- }
- return null;
- }
-
- public Map<String, String> getGadgetSpec(final HttpServletRequest request,
final String gadgetUrl, Map<String, String> userPrefs) {
- Map<String, String> gadgetSpec = new HashMap<String, String>();
- try {
- m_logService.log(LogService.LOG_DEBUG, "Retrieving gadgetspec for
'" + gadgetUrl + "'");
+
+ m_logService.log(LogService.LOG_INFO, getClass().getName() + " service
initialized");
+ }
+
+ public void start() {
+ m_logService.log(LogService.LOG_INFO,
+ this.getClass().getName() + " service started for tenant '" +
m_tenant.getId() + "'");
+ }
+
+ public String getSecurityToken(final String gadgetUrl, final
HttpServletRequest request) {
+ // TODO: This is the same key as in securitytokenkey.txt file of the
shindig application bundle
+ // But we are too lazy to load that key from the file
+ String key = "Tr9W5GNmfCb7eexNi0m+/HVgAlvsHmCuMEofHs6+LoU=";
+ String hostName = request.getServerName();
+ BasicBlobCrypter blobCrypter = new BasicBlobCrypter(key.getBytes());
+ BlobCrypterSecurityToken st = new
BlobCrypterSecurityToken(blobCrypter, "default", hostName);
+ st.setAppUrl(gadgetUrl);
+
+ String viewerId = "anonymous";
+ String ownerId = "anonymous";
+
+ // Verify if we have a valid authentication token holding a user name,
if so add the authenticated user as viewer
+ String userName = getViewer(request);
+ if (userName != null && !"".equals(userName)) {
+ viewerId = userName;
+ ownerId = userName;
+ }
+ st.setViewerId(viewerId);
+ st.setOwnerId(ownerId);
+
+ String securityToken;
+ try {
+ securityToken = Utf8UrlCoder.encode(st.encrypt());
+ return securityToken;
+ }
+ catch (BlobCrypterException e) {
+ m_logService.log(LogService.LOG_ERROR,
+ "Could not create security token for gadget url '" + gadgetUrl
+ "'", e);
+ }
+ return null;
+ }
+
+ public Map<String, String> getGadgetSpec(final HttpServletRequest request,
final String gadgetUrl,
+ Map<String, String> userPrefs) {
+ Map<String, String> gadgetSpec = new HashMap<String, String>();
+ try {
+ m_logService.log(LogService.LOG_DEBUG, "Retrieving gadgetspec for
'" + gadgetUrl + "'");
String xml = loadXMLFromCache(gadgetUrl);
- if (xml != null) {
- GadgetSpec spec = new GadgetSpec(Uri.parse(gadgetUrl), xml);
-
- // Perform message substitution if locales are available
- Map<Locale, LocaleSpec> locales =
spec.getModulePrefs().getLocales();
- if (locales != null && locales.size() > 0) {
- // TODO: replace this with users locale
- Locale defaultLocale = Locale.getDefault();
- Locale locale = getPreferredLocale(defaultLocale, locales);
-
- // First replace messages with the preferred language
labels
- String messageXML =
cleanMessageXML(loadContentFromURL(locales.get(locale).getMessages().toString()));
- MessageBundle bundle = new
MessageBundle(locales.get(locale), messageXML);
- Substitutions substituter = new Substitutions();
- substituter.addSubstitutions(Substitutions.Type.MESSAGE,
bundle.getMessages());
- spec = spec.substitute(substituter);
-
- // Replace the remaining messages with 'all' messages
- locale = getPreferredLocale(new Locale("all", "all"),
locales);
- messageXML =
cleanMessageXML(loadContentFromURL(locales.get(locale).getMessages().toString()));
- bundle = new MessageBundle(locales.get(locale),
messageXML);
- substituter = new Substitutions();
- substituter.addSubstitutions(Substitutions.Type.MESSAGE,
bundle.getMessages());
- spec = spec.substitute(substituter);
+ if (xml != null) {
+ GadgetSpec spec = new GadgetSpec(Uri.parse(gadgetUrl), xml);
+
+ // Perform message substitution if locales are available
+ Map<Locale, LocaleSpec> locales =
spec.getModulePrefs().getLocales();
+ if (locales != null && locales.size() > 0) {
+ // TODO: replace this with users locale
+ Locale defaultLocale = Locale.getDefault();
+ Locale locale = getPreferredLocale(defaultLocale, locales);
+
+ // First replace messages with the preferred language
labels
+ String localeUrl =
locales.get(locale).getMessages().toString();
+ if (!localeUrl.isEmpty()) {
+ String messageXML =
cleanMessageXML(loadContentFromURL(localeUrl));
+ MessageBundle bundle = new
MessageBundle(locales.get(locale), messageXML);
+ Substitutions substituter = new Substitutions();
+
substituter.addSubstitutions(Substitutions.Type.MESSAGE, bundle.getMessages());
+ spec = spec.substitute(substituter);
+ }
+
+ // Replace the remaining messages with 'all' messages
+ locale = getPreferredLocale(new Locale("all", "all"),
locales);
+ localeUrl = locales.get(locale).getMessages().toString();
+ if (!localeUrl.isEmpty()) {
+ String messageXML =
+
cleanMessageXML(loadContentFromURL(locales.get(locale).getMessages().toString()));
+ MessageBundle bundle = new
MessageBundle(locales.get(locale), messageXML);
+ Substitutions substituter = new Substitutions();
+
substituter.addSubstitutions(Substitutions.Type.MESSAGE, bundle.getMessages());
+ spec = spec.substitute(substituter);
+ }
}
// Replace user preferences (syntax: __UP_<pref>__)
@@ -189,39 +197,44 @@
}
};
Substitutions substituter = new Substitutions();
- UserPrefSubstituter userPrefSubs = new UserPrefSubstituter();
+ UserPrefSubstituter userPrefSubs = new UserPrefSubstituter();
userPrefSubs.addSubstitutions(substituter, context, spec);
spec = spec.substitute(substituter);
-
- // Copy attributes
- gadgetSpec.put("title", spec.getModulePrefs().getTitle());
- gadgetSpec.put("description",
spec.getModulePrefs().getDescription());
- gadgetSpec.put("author", spec.getModulePrefs().getAuthor());
- gadgetSpec.put("title_url",
spec.getModulePrefs().getTitleUrl().toString());
-
- if (spec.getModulePrefs().getScreenshot() != null
- &&
!spec.getModulePrefs().getScreenshot().toString().isEmpty()) {
- gadgetSpec.put("screenshot",
spec.getModulePrefs().getScreenshot().toString());
- }
- else {
+
+ // Copy attributes
+ gadgetSpec.put("title", spec.getModulePrefs().getTitle());
+ gadgetSpec.put("description",
spec.getModulePrefs().getDescription());
+ gadgetSpec.put("author", spec.getModulePrefs().getAuthor());
+ gadgetSpec.put("title_url",
spec.getModulePrefs().getTitleUrl().toString());
+
+ if (spec.getModulePrefs().getScreenshot() != null
+ &&
!spec.getModulePrefs().getScreenshot().toString().isEmpty()) {
+ gadgetSpec.put("screenshot",
spec.getModulePrefs().getScreenshot().toString());
+ }
+ else {
gadgetSpec.put("screenshot", request.getContextPath() +
Activator.ALIAS +
- "/static/images/defaultgadget.png");
- }
-
+ "/static/images/defaultgadget.png");
+ }
+
return gadgetSpec;
}
else {
- m_logService.log(LogService.LOG_WARNING, "Could not retrieve
gadget spec for url '" + gadgetUrl + "', ignoring gadget");
- }
- }
- catch (Exception e) {
- // Catch all exceptions since even an improper URL can cause a
NullPointerException here
- m_logService.log(LogService.LOG_ERROR, "Could not retrieve gadget
spec for url '" + gadgetUrl + "'", e);
- }
- return null;
+ m_logService.log(LogService.LOG_WARNING, "Could not retrieve
gadget spec for url '" + gadgetUrl
+ + "', ignoring gadget");
+ }
+ }
+ catch (Exception e) {
+ // Catch all exceptions since even an improper URL can cause a
NullPointerException here
+ m_logService.log(LogService.LOG_ERROR, "Could not retrieve gadget
spec for url '" + gadgetUrl + "'", e);
+ }
+ return null;
}
-
+
private String loadContentFromURL(String url) throws
ClientProtocolException, IOException {
+ if (url == null || url.isEmpty()) {
+ return "";
+ }
+
// Use the Apache HTTPClient as this will respect the returned
encoding type of the content
// (i.e. charset=... in Content-Type header). Without Apache
httpclient we should read the encoding type
// header from the response headers, read the content into a byte
array and convert the byte array to
@@ -230,23 +243,28 @@
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),
GADGETSPEC_READ_TIMEOUT);
-
+
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpClient.execute(httpGet, responseHandler);
return responseBody;
}
-
+
/**
* This method omits any content prior to <messagebundle>. It appears that
some gadgets,
- * see http://jira.amdatu.org/jira/browse/AMDATUOPENSOCIAL-97, return XML
that is not
+ * see http://jira.amdatu.org/jira/browse/AMDATUOPENSOCIAL-97, return XML
that is not
* completely correct.
+ *
* @param messages The message XML to clean
* @return The cleaned XML
*/
private String cleanMessageXML(String xml) {
- if (xml.startsWith("<messagebundle>")) {
+ if (xml == null || xml.isEmpty()) {
+ return "";
+ }
+ else if (xml.startsWith("<messagebundle>")) {
return xml;
- } else {
+ }
+ else {
return xml.substring(xml.indexOf("<messagebundle>"));
}
}
@@ -268,117 +286,117 @@
userPrefMap.put(name, value.toString());
}
}
- return new UserPrefs(userPrefMap);
+ return new UserPrefs(userPrefMap);
+ }
+
+ // Returns the preferred locale in this order:
+ // 1 Locale that matches country & language of preferred locale
+ // 2 Locale that matches language of preferred locale
+ // 3 Locale that matches country of preferred locale
+ // 4 Locale that matches language "en"
+ // 5 Locale that matches language "en-us"
+ // 6 Locale that matches language "en-gb"
+ // 7 Locale that matches language "all" and country "all"
+ // 8 Locale that matches language "*" and country "*"
+ private synchronized Locale getPreferredLocale(final Locale
preferredLocale, final Map<Locale,
+ LocaleSpec> locales) {
+ Map<Integer, String[]> localeOrder = new HashMap<Integer, String[]>();
+ localeOrder.put(1, new String[] { preferredLocale.getLanguage(),
preferredLocale.getCountry() });
+ localeOrder.put(2, new String[] { preferredLocale.getLanguage(), null
});
+ localeOrder.put(3, new String[] { null, preferredLocale.getCountry()
});
+ localeOrder.put(4, new String[] { "en", null });
+ localeOrder.put(5, new String[] { "en-us", null });
+ localeOrder.put(6, new String[] { "en-gb", null });
+ localeOrder.put(7, new String[] { "all", "all" });
+ localeOrder.put(8, new String[] { "*", "*" });
+
+ int currentLocaleOrder = 0;
+ Locale resultLocale = null;
+ for (Locale locale : locales.keySet()) {
+ String country = locale.getCountry();
+ String language = locale.getLanguage();
+
+ for (int order : localeOrder.keySet()) {
+ if (currentLocaleOrder == 0 || order < currentLocaleOrder) {
+ String l = localeOrder.get(order)[0];
+ String c = localeOrder.get(order)[1];
+ if ((c == null || c.equalsIgnoreCase(country)) && (l ==
null || l.equalsIgnoreCase(language))) {
+ resultLocale = locale;
+ currentLocaleOrder = order;
+ }
+ }
+ }
+ }
+ if (resultLocale == null) {
+ // Fallback for the case that none of the locales provides a best
match
+ return locales.keySet().iterator().next();
+ }
+ return resultLocale;
+ }
+
+ // Return XML from cache or retrieve it
+ private String loadXMLFromCache(final String url) {
+ FutureTask<Object[]> futureTask = m_gadgetSpecCache.get(url);
+ try {
+ if (futureTask != null) {
+ // Check if the timestamp is out-of-date
+ long timestamp = (Long) futureTask.get()[0];
+ if (System.currentTimeMillis() - timestamp >
GADGETSPEC_CACHE_TIMEOUT) {
+ m_gadgetSpecCache.remove(url);
+ futureTask = null;
+ m_logService.log(LogService.LOG_DEBUG, "Removed gadgetspec
'" + url
+ + "' from cache, it is out of date. Gadgetspec will be
re-retrieved.");
+ }
+ }
+ if (futureTask == null) {
+ Callable<Object[]> callable = new Callable<Object[]>() {
+ public Object[] call() throws Exception {
+ return new Object[] { System.currentTimeMillis(),
loadContentFromURL(url) };
+ }
+ };
+ FutureTask<Object[]> ft = new FutureTask<Object[]>(callable);
+ futureTask = m_gadgetSpecCache.putIfAbsent(url, ft);
+ if (futureTask == null) {
+ futureTask = ft;
+ ft.run();
+ }
+ }
+ return (String) futureTask.get()[1];
+ }
+ catch (CancellationException e) {
+ if (futureTask != null) {
+ m_gadgetSpecCache.remove(url, futureTask);
+ }
+ }
+ catch (InterruptedException e) {
+ m_logService.log(LogService.LOG_ERROR, "Retrieving gadgetspec for
'" + url + "' interrupted", e);
+ }
+ catch (ExecutionException e) {
+ m_logService.log(LogService.LOG_ERROR, "Execution failed
retrieving gadgetspec for '" + url + "'", e);
+ }
+ return null;
+ }
+
+ public String getViewer(final HttpServletRequest request) {
+ String token = m_tokenProvider.getTokenFromRequest(request);
+ if (token != null) {
+ try {
+ Map<String, String> attributes =
m_tokenProvider.verifyToken(token);
+ if (attributes.containsKey(TokenProvider.USERNAME)) {
+ return attributes.get(TokenProvider.USERNAME);
+ }
+ }
+ catch (TokenProviderException e) {
+ // Ignore invalid tokens
+ }
+ catch (InvalidTokenException e) {
+ // Ignore invalid tokens
+ }
+ }
+ return null;
+ }
+
+ public String getOwner(final HttpServletRequest request) {
+ return getViewer(request);
}
-
- // Returns the preferred locale in this order:
- // 1 Locale that matches country & language of preferred locale
- // 2 Locale that matches language of preferred locale
- // 3 Locale that matches country of preferred locale
- // 4 Locale that matches language "en"
- // 5 Locale that matches language "en-us"
- // 6 Locale that matches language "en-gb"
- // 7 Locale that matches language "all" and country "all"
- // 8 Locale that matches language "*" and country "*"
- private synchronized Locale getPreferredLocale(final Locale
preferredLocale, final Map<Locale,
- LocaleSpec> locales) {
- Map<Integer, String[]> localeOrder = new HashMap<Integer, String[]>();
- localeOrder.put(1, new String[] {preferredLocale.getLanguage(),
preferredLocale.getCountry()});
- localeOrder.put(2, new String[] {preferredLocale.getLanguage(), null});
- localeOrder.put(3, new String[] {null, preferredLocale.getCountry()});
- localeOrder.put(4, new String[] {"en", null});
- localeOrder.put(5, new String[] {"en-us", null});
- localeOrder.put(6, new String[] {"en-gb", null});
- localeOrder.put(7, new String[] {"all", "all"});
- localeOrder.put(8, new String[] {"*", "*"});
-
- int currentLocaleOrder = 0;
- Locale resultLocale = null;
- for (Locale locale : locales.keySet()) {
- String country = locale.getCountry();
- String language = locale.getLanguage();
-
- for (int order : localeOrder.keySet()) {
- if (currentLocaleOrder == 0 || order < currentLocaleOrder) {
- String l = localeOrder.get(order)[0];
- String c = localeOrder.get(order)[1];
- if ((c == null || c.equalsIgnoreCase(country)) && (l ==
null || l.equalsIgnoreCase(language))) {
- resultLocale = locale;
- currentLocaleOrder = order;
- }
- }
- }
- }
- if (resultLocale == null) {
- // Fallback for the case that none of the locales provides a best
match
- return locales.keySet().iterator().next();
- }
- return resultLocale;
- }
-
- // Return XML from cache or retrieve it
- private String loadXMLFromCache(final String url) {
- FutureTask<Object[]> futureTask = m_gadgetSpecCache.get(url);
- try {
- if (futureTask != null) {
- // Check if the timestamp is out-of-date
- long timestamp = (Long) futureTask.get()[0];
- if (System.currentTimeMillis() - timestamp >
GADGETSPEC_CACHE_TIMEOUT) {
- m_gadgetSpecCache.remove(url);
- futureTask = null;
- m_logService.log(LogService.LOG_DEBUG, "Removed gadgetspec
'" + url
- + "' from cache, it is out of date. Gadgetspec will be
re-retrieved.");
- }
- }
- if (futureTask == null) {
- Callable<Object[]> callable = new Callable<Object[]>() {
- public Object[] call() throws Exception {
- return new Object[] {System.currentTimeMillis(),
loadContentFromURL(url)};
- }
- };
- FutureTask<Object[]> ft = new FutureTask<Object[]>(callable);
- futureTask = m_gadgetSpecCache.putIfAbsent(url, ft);
- if (futureTask == null) {
- futureTask = ft;
- ft.run();
- }
- }
- return (String) futureTask.get()[1];
- }
- catch (CancellationException e) {
- if (futureTask != null) {
- m_gadgetSpecCache.remove(url, futureTask);
- }
- }
- catch (InterruptedException e) {
- m_logService.log(LogService.LOG_ERROR, "Retrieving gadgetspec for
'" + url + "' interrupted", e);
- }
- catch (ExecutionException e) {
- m_logService.log(LogService.LOG_ERROR, "Execution failed
retrieving gadgetspec for '" + url + "'", e);
- }
- return null;
- }
-
- public String getViewer(final HttpServletRequest request) {
- String token = m_tokenProvider.getTokenFromRequest(request);
- if (token != null) {
- try {
- Map<String, String> attributes =
m_tokenProvider.verifyToken(token);
- if (attributes.containsKey(TokenProvider.USERNAME)) {
- return attributes.get(TokenProvider.USERNAME);
- }
- }
- catch (TokenProviderException e) {
- // Ignore invalid tokens
- }
- catch (InvalidTokenException e) {
- // Ignore invalid tokens
- }
- }
- return null;
- }
-
- public String getOwner(final HttpServletRequest request) {
- return getViewer(request);
- }
-}
+}
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits