Author: [email protected]
Date: Fri Sep 23 11:44:25 2011
New Revision: 1411

Log:
[AMDATUAUTH-92] Fixed proper tenant awareness of the token provider, improved 
log messages and property constants in integration test

Modified:
   
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/auth/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
   
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/service/OAuthTokenProviderImpl.java
   
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthAccessTokenServletImpl.java
   
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthAuthorizeTokenServletImpl.java
   
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthRequestTokenServletImpl.java
   
trunk/amdatu-auth/oauth-stores/consumer-store-fs/src/main/java/org/amdatu/auth/oauth/consumerregistry/fs/service/FSConsumerRegistryImpl.java
   
trunk/amdatu-auth/oauth-stores/nonce-store-mem/src/main/java/org/amdatu/auth/oauth/store/nonce/mem/service/InMemNonceStorageProviderImpl.java
   
trunk/amdatu-auth/test-integration/base/src/main/java/org/amdatu/auth/test/integration/base/AuthFixture.java
   
trunk/amdatu-auth/tokenprovider/src/main/java/org/amdatu/auth/tokenprovider/osgi/Activator.java
   
trunk/amdatu-auth/tokenprovider/src/main/java/org/amdatu/auth/tokenprovider/service/TokenProviderImpl.java
   
trunk/amdatu-auth/tokenstore-mem/src/main/java/org/amdatu/auth/tokenstore/mem/service/InMemTokenStorageProviderImpl.java

Modified: 
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/auth/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/auth/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
     (original)
+++ 
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/auth/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
     Fri Sep 23 11:44:25 2011
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2010, 2011 The Amdatu Foundation
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -64,19 +64,19 @@
  * This class provides a REST interface on top of the oAuth service consumer 
registry
  * TODO: This REST API needs to be finalized by adding HTTP caching headers, 
authorization checks and
  * possibly additional methods.
- * 
+ *
  * @author ivol
  */
 @Path("oauth/consumers")
 public class OAuthServiceConsumerRegistryRESTImpl implements 
OAuthServiceConsumerRegistryREST {
     private final static String ALIAS = "/rest/oauth/consumers";
 
-    // FIXME: Temporary fix for AMDATUAUTH-49. Until a generic approach has 
been defined 
+    // FIXME: Temporary fix for AMDATUAUTH-49. Until a generic approach has 
been defined
     // to handle authorization of REST services, we verify that the current 
user is in the
     // role "Administrator"
     private static final String DEFAULT_ADMIN_GROUP = "Administrators";
 
-    // Tenant unaware service dependencies   
+    // Tenant unaware service dependencies
     private volatile LogService m_logService;
     private volatile Tenant m_tenant;
     private volatile Component m_component;
@@ -95,7 +95,7 @@
     }
 
     public void init(final Component component) {
-        // Add tenant specific service dependencies        
+        // Add tenant specific service dependencies
         m_component.add(m_dependencyManager.createServiceDependency()
             .setService(TokenProvider.class, 
getTenantFilter(TokenProvider.class))
             .setRequired(true)
@@ -118,13 +118,13 @@
     }
 
     public void start() {
-        m_logService.log(LogService.LOG_DEBUG,
+        m_logService.log(LogService.LOG_INFO,
             "Service '" + getClass().getName() + "' started for tenant '" + 
m_tenant.getId() + "'");
     }
 
     /**
      * This method can be used to check the availability of the OAuth Service 
Consumer.
-     * 
+     *
      * @return The text "OAuth Service Consumer registry online"
      */
     @GET
@@ -137,7 +137,7 @@
     /**
      * REST interface: GET /rest/oauth/consumers
      * Returns the requested consumer in application/xml or application/json 
format.
-     * 
+     *
      * @param consumerKey
      *        The key of the consumer to retrieve.
      * @return The consumer matching the key in xml or JSON format
@@ -183,7 +183,7 @@
     /**
      * REST interface: GET /rest/oauth/consumers/{consumerKey}
      * Returns the requested consumer in application/xml or application/json 
format.
-     * 
+     *
      * @param consumerKey
      *        The key of the consumer to retrieve.
      * @return The consumer matching the key in xml or JSON format
@@ -191,12 +191,12 @@
     @GET
     @Path("{consumerKey}")
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
-    public Response getConsumer(@Context final HttpServletRequest request, 
+    public Response getConsumer(@Context final HttpServletRequest request,
             @PathParam("consumerKey") final String consumerKey, @Context final 
UriInfo uriInfo) {
         try {
             if (!isAuthorized(request)) {
                 return 
Response.status(HttpStatus.SC_UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
-            }            
+            }
             OAuthServiceConsumer consumer = 
m_registry.getConsumer(consumerKey);
             if (consumer != null) {
                 ConsumerBean consumerBean = ConsumerBean.copy(consumer);
@@ -223,7 +223,7 @@
     /**
      * REST interface: PUT /rest/oauth/consumers
      * Adds a new consumer with the properties of the posted values in 
application/xml or application/json format.
-     * 
+     *
      * @return The HTTP response object
      */
     @PUT
@@ -232,13 +232,13 @@
         try {
             if (!isAuthorized(request)) {
                 return 
Response.status(HttpStatus.SC_UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
-            } 
+            }
             m_registry.addConsumer(consumer);
             return Response.ok().cacheControl(NO_CACHE_CONTROL).build();
         }
         catch (ConsumerAlreadyExistsException e) {
             throw new WebApplicationException(Response.Status.NOT_MODIFIED);
-        }      
+        }
         catch (ConsumerRegistryStorageException e) {
             throw new WebApplicationException(e, 
Response.Status.INTERNAL_SERVER_ERROR);
         }
@@ -246,9 +246,9 @@
 
     /**
      * REST interface: POST /rest/oauth/consumers
-     * Adds a new consumer with a generated consumer key and secret and the 
properties of the posted 
+     * Adds a new consumer with a generated consumer key and secret and the 
properties of the posted
      * values in application/xml or application/json format.
-     * 
+     *
      * @return The HTTP response object
      */
     @POST
@@ -283,7 +283,7 @@
             consumer.addProperty(OAuthServiceConsumer.OWNERID, 
getCurrentUser(request).getName());
             m_registry.addConsumer(consumer);
 
-            // Remove properties, as these are of type Map<String, Object> 
which cannot be marhsalled 
+            // Remove properties, as these are of type Map<String, Object> 
which cannot be marhsalled
             // from and to XML/JSON directly
             consumer.setProperties(null);
 
@@ -298,7 +298,7 @@
      * REST interface: PUT /rest/oauth/consumers/{consumerKey}
      * Updates an existing consumer with the properties of the posted values 
in application/xml
      * or application/json format.
-     * 
+     *
      * @param consumerKey
      *        The key of the consumer to update.
      * @return The HTTP response object
@@ -331,7 +331,7 @@
             throw new WebApplicationException(e, 
Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
-    
+
     @PUT
     @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     @Path("{consumerKey}")
@@ -355,7 +355,7 @@
     /**
      * REST interface: PUT /rest/oauth/consumers
      * Adds a new consumer with the properties of the posted values in 
application/xml or application/json format.
-     * 
+     *
      * @return The HTTP response object
      */
     @DELETE

Modified: 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/service/OAuthTokenProviderImpl.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/service/OAuthTokenProviderImpl.java
       (original)
+++ 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/service/OAuthTokenProviderImpl.java
       Fri Sep 23 11:44:25 2011
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2010, 2011 The Amdatu Foundation
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -53,13 +53,13 @@
     private volatile Tenant m_tenant;
     private volatile Component m_component;
     private volatile DependencyManager m_dependencyManager;
-    
+
     // Tenant aware service dependencies
     private volatile TokenStorageProvider m_tokenStore;
     private volatile OAuthNonceStorageProvider m_nonceStore;
     private volatile OAuthServiceConsumerRegistry m_consumerRegistry;
-    
-    
+
+
     // The simple oAuth validator.
     private PluggableOAuthValidator m_oAuthValidator;
 
@@ -80,18 +80,18 @@
         }
         m_oAuthValidator = new PluggableOAuthValidator(requestMaxAge, 
Double.parseDouble(OAuth.VERSION_1_0), m_nonceStore);
 
-        m_logService.log(LogService.LOG_DEBUG, "Service '" + 
getClass().getName() + "' started for tenant '" + m_tenant.getId() + "'");
+        m_logService.log(LogService.LOG_INFO, "Service '" + 
getClass().getName() + "' started for tenant '" + m_tenant.getId() + "'");
     }
 
     private ServiceDependency getTenantServiceDependency(Class<?> clazz) {
-        String tenantFilter =  "(&(" + Tenant.TENANT_ID_SERVICEPROPERTY + "=" 
+ m_tenant.getId() 
+        String tenantFilter =  "(&(" + Tenant.TENANT_ID_SERVICEPROPERTY + "=" 
+ m_tenant.getId()
             + ")(" + Constants.OBJECTCLASS + "=" + clazz.getName() + "))";
         return m_dependencyManager.createServiceDependency()
             .setService(clazz, tenantFilter)
             .setRequired(true)
             .setInstanceBound(true);
     }
-    
+
     public synchronized OAuthConsumer getConsumer(final OAuthMessage 
requestMessage) throws OAuthException {
         try {
             // try to load from local cache if not throw exception
@@ -251,7 +251,7 @@
         // is not part of the regular validateOAuthMessage process.
         if (verifier == null) {
             String msg =  "The OAuth server did not receive an oauth_verifier";
-            throw 
OAuthServerUtil.createException(OAuth.Problems.OAUTH_PARAMETERS_REJECTED, msg); 
              
+            throw 
OAuthServerUtil.createException(OAuth.Problems.OAUTH_PARAMETERS_REJECTED, msg);
         }
         if 
(!verifier.equals(requestToken.getProperty(OAuthTokenProvider.VERIFIER_PROPERTY)))
 {
             String msg = "The OAuth server received an invalid oauth_verifier";
@@ -284,7 +284,7 @@
      * Generates a nonce with default bytesize (32). A nonce is an 
abbreviation of number used once, and is a
      * unique randomly generated number. It is used by authentication 
protocols to ensure that old
      * requests cannot be used in replay attacks.
-     * 
+     *
      * @return A random generated nonce.
      */
     private BigInteger generateNonce() {
@@ -295,7 +295,7 @@
      * Generates a nonce with the specified bytesize. A nonce is an 
abbreviation of number used once, and is a
      * unique randomly generated number. It is used by authentication 
protocols to ensure that old
      * requests cannot be used in replay attacks.
-     * 
+     *
      * @param byteSize
      *        the number of bytes from which the nonce is generated
      * @return A random generated nonce.
@@ -310,7 +310,7 @@
     /**
      * Generates a unique random token. The token is generated from a 32-bits 
nonce and converted to a String
      * representation (with numbers 0-9 and letters a-z).
-     * 
+     *
      * @return A new randomly generated token.
      */
     private String generateToken() {

Modified: 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthAccessTokenServletImpl.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthAccessTokenServletImpl.java
  (original)
+++ 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthAccessTokenServletImpl.java
  Fri Sep 23 11:44:25 2011
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2010, 2011 The Amdatu Foundation
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -50,7 +50,7 @@
     }
 
     public void start() {
-        m_logService.log(LogService.LOG_DEBUG,
+        m_logService.log(LogService.LOG_INFO,
             "Service '" + getClass().getName() + "' started for tenant '" + 
m_tenantId + "'");
     }
 
@@ -70,17 +70,17 @@
         throws IOException, ServletException {
         try {
             OAuthMessage requestMessage = OAuthServlet.getMessage(request, 
null);
-            
+
             // Validate that this is a valid OAuth request
             Token requestToken = 
m_tokenProvider.validateOAuthMessage(requestMessage);
-            
+
             // Make sure a request token was send along with the request
             if (requestToken == null) {
                 String msg = "The OAuth server did not receive the request 
token in the request "
                     + "(the oauth_token parameter is missing)";
                 throw 
OAuthServerUtil.createException(OAuth.Problems.TOKEN_REJECTED, msg);
             }
-            
+
             // Validate that this is a request token that was marked as 
authorized
             if 
(!OAuthTokenProvider.REQUEST_TOKEN_TYPE.equals(requestToken.getProperty(OAuthTokenProvider.TOKEN_TYPE_PROPERTY)))
 {
                 String msg = "The token received is not a request token but an 
access token";
@@ -90,9 +90,9 @@
                 String msg = "The user did not authorize the service consumer";
                 throw 
OAuthServerUtil.createException(OAuth.Problems.PERMISSION_DENIED, msg);
             }
-            
+
             // Now exchange the request token for an access token and secret
-            String verifier = 
requestMessage.getParameter(OAuth.OAUTH_VERIFIER);  
+            String verifier = 
requestMessage.getParameter(OAuth.OAUTH_VERIFIER);
             Token accessToken = 
m_tokenProvider.exchangeForAccessToken(requestToken, verifier);
 
             response.setContentType("text/plain");

Modified: 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthAuthorizeTokenServletImpl.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthAuthorizeTokenServletImpl.java
       (original)
+++ 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthAuthorizeTokenServletImpl.java
       Fri Sep 23 11:44:25 2011
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2010, 2011 The Amdatu Foundation
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -69,7 +69,7 @@
     }
 
     public void start() {
-        m_logService.log(LogService.LOG_DEBUG,
+        m_logService.log(LogService.LOG_INFO,
             "Service '" + getClass().getName() + "' started for tenant '" + 
m_tenantId + "'");
     }
 
@@ -115,7 +115,7 @@
                 // User denies access, remove the request token immediately
                 m_oAuthTokenProvider.authorizeToken(token, null, false);
                 response.setStatus(HttpServletResponse.SC_OK);
-            } else {            
+            } else {
                 String userId = getUserId(request);
                 if (userId == null) {
                     // If there is no user id available now, we throw a 
permission denied as it won't happen

Modified: 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthRequestTokenServletImpl.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthRequestTokenServletImpl.java
 (original)
+++ 
trunk/amdatu-auth/oauth-server/src/main/java/org/amdatu/auth/oauth/server/servlet/OAuthRequestTokenServletImpl.java
 Fri Sep 23 11:44:25 2011
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2010, 2011 The Amdatu Foundation
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -38,7 +38,7 @@
 /**
  * This servlet is responsible for generating request tokens.
  * Endpoint: /oauth-server/requesttoken
- * 
+ *
  * @author ivol
  */
 public class OAuthRequestTokenServletImpl extends HttpServlet implements 
OAuthRequestTokenServlet {
@@ -58,7 +58,7 @@
     }
 
     public void start() {
-        m_logService.log(LogService.LOG_DEBUG,
+        m_logService.log(LogService.LOG_INFO,
             "Service '" + getClass().getName() + "' started for tenant '" + 
m_tenantId + "'");
     }
 

Modified: 
trunk/amdatu-auth/oauth-stores/consumer-store-fs/src/main/java/org/amdatu/auth/oauth/consumerregistry/fs/service/FSConsumerRegistryImpl.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-stores/consumer-store-fs/src/main/java/org/amdatu/auth/oauth/consumerregistry/fs/service/FSConsumerRegistryImpl.java
        (original)
+++ 
trunk/amdatu-auth/oauth-stores/consumer-store-fs/src/main/java/org/amdatu/auth/oauth/consumerregistry/fs/service/FSConsumerRegistryImpl.java
        Fri Sep 23 11:44:25 2011
@@ -60,13 +60,13 @@
     private FSConsumerStorage m_storage;
 
     public void start() {
-        m_logService.log(LogService.LOG_DEBUG,
+        m_logService.log(LogService.LOG_INFO,
             "Service '" + getClass().getName() + "' started for tenant '" + 
m_tenant.getId() + "'");
     }
 
     /**
      * Invoked since this is a managed service.
-     * 
+     *
      * @param dictionary
      *        Dictionary holding the configuration properties
      * @throws ConfigurationException

Modified: 
trunk/amdatu-auth/oauth-stores/nonce-store-mem/src/main/java/org/amdatu/auth/oauth/store/nonce/mem/service/InMemNonceStorageProviderImpl.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-stores/nonce-store-mem/src/main/java/org/amdatu/auth/oauth/store/nonce/mem/service/InMemNonceStorageProviderImpl.java
       (original)
+++ 
trunk/amdatu-auth/oauth-stores/nonce-store-mem/src/main/java/org/amdatu/auth/oauth/store/nonce/mem/service/InMemNonceStorageProviderImpl.java
       Fri Sep 23 11:44:25 2011
@@ -31,7 +31,7 @@
     private volatile LogService m_logService;
 
     public void start() {
-        m_logService.log(LogService.LOG_DEBUG,
+        m_logService.log(LogService.LOG_INFO,
             "Service '" + getClass().getName() + "' started for tenant '" + 
m_tenant.getId() + "'");
     }
 
@@ -68,7 +68,7 @@
      * Selected parameters from an OAuth request, in a form suitable for
      * detecting duplicate requests. The implementation is optimized for the
      * comparison operations (compareTo, equals and hashCode).
-     * 
+     *
      * @author John Kristian
      */
     private static class UsedNonce implements Comparable<UsedNonce> {

Modified: 
trunk/amdatu-auth/test-integration/base/src/main/java/org/amdatu/auth/test/integration/base/AuthFixture.java
==============================================================================
--- 
trunk/amdatu-auth/test-integration/base/src/main/java/org/amdatu/auth/test/integration/base/AuthFixture.java
        (original)
+++ 
trunk/amdatu-auth/test-integration/base/src/main/java/org/amdatu/auth/test/integration/base/AuthFixture.java
        Fri Sep 23 11:44:25 2011
@@ -101,13 +101,11 @@
 
     private Properties getHttpServiceCfg() {
         Properties properties = new Properties();
-        properties.put("org.osgi.service.http.hostname", "localhost"); // 
fixme private/missing constants
-        properties.put("org.osgi.service.http.port", "8080");
+        properties.put("org.osgi.service.http.hostname", HOSTNAME);
+        properties.put("org.osgi.service.http.port", PORTNR);
         properties.put("org.osgi.service.http.port.secure", "8090");
         properties.put("org.apache.felix.http.debug", "true");
         properties.put("org.apache.felix.log.storeDebug", "true");
         return properties;
     }
-
-
 }

Modified: 
trunk/amdatu-auth/tokenprovider/src/main/java/org/amdatu/auth/tokenprovider/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-auth/tokenprovider/src/main/java/org/amdatu/auth/tokenprovider/osgi/Activator.java
     (original)
+++ 
trunk/amdatu-auth/tokenprovider/src/main/java/org/amdatu/auth/tokenprovider/osgi/Activator.java
     Fri Sep 23 11:44:25 2011
@@ -16,7 +16,6 @@
 package org.amdatu.auth.tokenprovider.osgi;
 
 import org.amdatu.auth.tokenprovider.TokenProvider;
-import org.amdatu.auth.tokenprovider.TokenStorageProvider;
 import org.amdatu.auth.tokenprovider.service.TokenProviderImpl;
 import org.amdatu.core.tenant.Tenant;
 import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
@@ -44,8 +43,7 @@
             createAdapterService(Tenant.class, null)
                 .setInterface(TokenProvider.class.getName(), null)
                 .setImplementation(TokenProviderImpl.class)
-                
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-                
.add(createServiceDependency().setService(TokenStorageProvider.class).setRequired(true)));
+                
.add(createServiceDependency().setService(LogService.class).setRequired(true)));
 
         // Create and register the REST API for the token provider service 
component.
         // TODO: This REST interface is disabled for now for security reasons.

Modified: 
trunk/amdatu-auth/tokenprovider/src/main/java/org/amdatu/auth/tokenprovider/service/TokenProviderImpl.java
==============================================================================
--- 
trunk/amdatu-auth/tokenprovider/src/main/java/org/amdatu/auth/tokenprovider/service/TokenProviderImpl.java
  (original)
+++ 
trunk/amdatu-auth/tokenprovider/src/main/java/org/amdatu/auth/tokenprovider/service/TokenProviderImpl.java
  Fri Sep 23 11:44:25 2011
@@ -41,6 +41,10 @@
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.codec.binary.StringUtils;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.ServiceDependency;
+import org.osgi.framework.Constants;
 import org.osgi.service.log.LogService;
 
 /**
@@ -55,9 +59,13 @@
      */
     public static final String AUTHORIZATION_HEADER = "Amdatu";
 
-    // Service dependencies
+    // Tenant unaware service dependencies
     private volatile LogService m_logService;
     private volatile Tenant m_tenant;
+    private volatile Component m_component;
+    private volatile DependencyManager m_dependencyManager;
+    
+    // Tenant aware service dependencies
     private volatile TokenStorageProvider m_tokenStore;
 
     // Encryption and decryption key and ciphers
@@ -77,8 +85,11 @@
      * @throws NoSuchPaddingException
      * @throws UnsupportedEncodingException
      */
-    public void init() throws NoSuchAlgorithmException, InvalidKeyException, 
NoSuchPaddingException,
-        UnsupportedEncodingException {
+    public void init(final Component component) throws 
NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException,
+        UnsupportedEncodingException {
+        // Define tenant aware service dependencies
+        
m_component.add(getTenantServiceDependency(TokenStorageProvider.class));
+        
         if (m_secretKey == null) {
             KeyGenerator keyGen = KeyGenerator.getInstance(ENCRYPTION_METHOD);
             keyGen.init(PRIVATE_KEY_SIZE);
@@ -94,9 +105,18 @@
             DECRYPT_CIPHER.init(Cipher.DECRYPT_MODE, m_secretKey);
         }
     }
-
+
+    private ServiceDependency getTenantServiceDependency(Class<?> clazz) {
+        String tenantFilter =  "(&(" + Tenant.TENANT_ID_SERVICEPROPERTY + "=" 
+ m_tenant.getId() 
+            + ")(" + Constants.OBJECTCLASS + "=" + clazz.getName() + "))";
+        return m_dependencyManager.createServiceDependency()
+            .setService(clazz, tenantFilter)
+            .setRequired(true)
+            .setInstanceBound(true);
+    }
+    
     public void start() {
-        m_logService.log(LogService.LOG_DEBUG,
+        m_logService.log(LogService.LOG_INFO,
             "Service '" + getClass().getName() + "' started for tenant '" + 
m_tenant.getId() + "'");
     }
     

Modified: 
trunk/amdatu-auth/tokenstore-mem/src/main/java/org/amdatu/auth/tokenstore/mem/service/InMemTokenStorageProviderImpl.java
==============================================================================
--- 
trunk/amdatu-auth/tokenstore-mem/src/main/java/org/amdatu/auth/tokenstore/mem/service/InMemTokenStorageProviderImpl.java
    (original)
+++ 
trunk/amdatu-auth/tokenstore-mem/src/main/java/org/amdatu/auth/tokenstore/mem/service/InMemTokenStorageProviderImpl.java
    Fri Sep 23 11:44:25 2011
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2010, 2011 The Amdatu Foundation
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -25,7 +25,7 @@
 
 /**
  * This class implements a very simple in-memory token store.
- * 
+ *
  * @author ivol
  */
 public class InMemTokenStorageProviderImpl implements TokenStorageProvider {
@@ -37,7 +37,7 @@
     private Map<String, Token> m_tokens = new HashMap<String, Token>();
 
     public void start() {
-        m_logService.log(LogService.LOG_DEBUG, "Service '" + 
getClass().getName() + "' started for tenant '"
+        m_logService.log(LogService.LOG_INFO, "Service '" + 
getClass().getName() + "' started for tenant '"
                 + m_tenant.getId() + "'");
     }
 
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to