usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [4/5] git commit: Enhance performance in 3rd party auth module (Connection pooling)
Date Tue, 18 Mar 2014 15:20:48 GMT
Enhance performance in 3rd party auth module (Connection pooling)


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c0d8fed0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c0d8fed0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c0d8fed0

Branch: refs/pull/75/head
Commit: c0d8fed0ff81c03606d2c4450a3261825234af12
Parents: 76bbedf
Author: Sungju Jin <sungju@softwaregeeks.org>
Authored: Tue Mar 18 23:19:33 2014 +0900
Committer: Sungju Jin <sungju@softwaregeeks.org>
Committed: Tue Mar 18 23:23:17 2014 +0900

----------------------------------------------------------------------
 .../security/providers/AbstractProvider.java    |  14 +--
 .../security/providers/FacebookProvider.java    |  96 ++++++++++----
 .../security/providers/FoursquareProvider.java  |  58 +++++----
 .../providers/PingIdentityProvider.java         |  13 +-
 .../providers/SignInProviderFactory.java        |  12 +-
 .../resources/usergrid-services-context.xml     | 125 +++++++++++--------
 6 files changed, 195 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d8fed0/stack/services/src/main/java/org/apache/usergrid/security/providers/AbstractProvider.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/providers/AbstractProvider.java
b/stack/services/src/main/java/org/apache/usergrid/security/providers/AbstractProvider.java
index 05e12a8..d4654fb 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/providers/AbstractProvider.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/providers/AbstractProvider.java
@@ -21,11 +21,7 @@ import java.util.Map;
 
 import org.apache.usergrid.management.ManagementService;
 import org.apache.usergrid.persistence.EntityManager;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.json.JSONConfiguration;
+import org.springframework.web.client.RestTemplate;
 
 
 /** @author zznate */
@@ -33,15 +29,13 @@ public abstract class AbstractProvider implements SignInAsProvider {
 
     protected EntityManager entityManager;
     protected ManagementService managementService;
-    protected Client client;
+    protected RestTemplate restTemplate;
 
 
-    AbstractProvider( EntityManager entityManager, ManagementService managementService )
{
+    AbstractProvider( EntityManager entityManager, ManagementService managementService, RestTemplate
restTemplate) {
         this.entityManager = entityManager;
         this.managementService = managementService;
-        ClientConfig clientConfig = new DefaultClientConfig();
-        clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE
);
-        client = Client.create( clientConfig );
+        this.restTemplate = restTemplate;
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d8fed0/stack/services/src/main/java/org/apache/usergrid/security/providers/FacebookProvider.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/providers/FacebookProvider.java
b/stack/services/src/main/java/org/apache/usergrid/security/providers/FacebookProvider.java
index fdc8dc2..f1a582c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/providers/FacebookProvider.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/providers/FacebookProvider.java
@@ -17,11 +17,13 @@
 package org.apache.usergrid.security.providers;
 
 
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
-import javax.ws.rs.core.MediaType;
-
+import com.google.common.base.Preconditions;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonProperty;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.usergrid.management.ManagementService;
@@ -32,6 +34,7 @@ import org.apache.usergrid.persistence.Results;
 import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.security.tokens.exceptions.BadTokenException;
 import org.apache.usergrid.utils.JsonUtils;
+import org.springframework.web.client.RestTemplate;
 
 import static org.apache.usergrid.persistence.Schema.PROPERTY_MODIFIED;
 import static org.apache.usergrid.utils.ListUtils.anyNull;
@@ -51,9 +54,8 @@ public class FacebookProvider extends AbstractProvider {
     private String apiUrl = DEF_API_URL;
     private String pictureUrl = DEF_PICTURE_URL;
 
-
-    FacebookProvider( EntityManager entityManager, ManagementService managementService )
{
-        super( entityManager, managementService );
+    FacebookProvider( EntityManager entityManager, ManagementService managementService, RestTemplate
restTemplate) {
+        super( entityManager, managementService, restTemplate );
     }
 
 
@@ -93,38 +95,44 @@ public class FacebookProvider extends AbstractProvider {
 
     @Override
     Map<String, Object> userFromResource( String externalToken ) {
-        return client.resource( apiUrl ).queryParam( "access_token", externalToken )
-                     .accept( MediaType.APPLICATION_JSON ).get( Map.class );
+        return null;
     }
 
+    private FacebookUser getUser( String access_token ) {
+        FacebookUser fb_user = null;
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("access_token", access_token);
+        try {
+            fb_user = restTemplate.getForObject(apiUrl+"?access_token={access_token}", FacebookUser.class,
params);
+        } catch (Exception e) {
+        }
+        return fb_user;
+    }
 
     @Override
     public User createOrAuthenticate( String externalToken ) throws BadTokenException {
 
-        Map<String, Object> fb_user = userFromResource( externalToken );
+        FacebookUser fb_user = getUser( externalToken );
+        Preconditions.checkNotNull(fb_user, "Invalid facebook user");
 
-        String fb_user_id = ( String ) fb_user.get( "id" );
-        String fb_user_name = ( String ) fb_user.get( "name" );
-        String fb_user_username = ( String ) fb_user.get( "username" );
-        String fb_user_email = ( String ) fb_user.get( "email" );
         if ( logger.isDebugEnabled() ) {
             logger.debug( JsonUtils.mapToFormattedJsonString( fb_user ) );
         }
 
         User user = null;
 
-        if ( ( fb_user != null ) && !anyNull( fb_user_id, fb_user_name ) ) {
+        if ( ( fb_user != null ) && !anyNull( fb_user.id, fb_user.name ) ) {
 
             Results r = null;
             try {
                 r = entityManager.searchCollection( entityManager.getApplicationRef(), "users",
-                        Query.findForProperty( "facebook.id", fb_user_id ) );
+                        Query.findForProperty( "facebook.id", fb_user.id ) );
             }
             catch ( Exception ex ) {
                 throw new BadTokenException( "Could not lookup user for that Facebook ID",
ex );
             }
             if ( r.size() > 1 ) {
-                logger.error( "Multiple users for FB ID: " + fb_user_id );
+                logger.error( "Multiple users for FB ID: " + fb_user.id );
                 throw new BadTokenException( "multiple users with same Facebook ID" );
             }
 
@@ -132,18 +140,18 @@ public class FacebookProvider extends AbstractProvider {
                 Map<String, Object> properties = new LinkedHashMap<String, Object>();
 
                 properties.put( "facebook", fb_user );
-                properties.put( "username", "fb_" + fb_user_id );
-                properties.put( "name", fb_user_name );
-                properties.put( "picture", String.format( pictureUrl, fb_user_id ) );
+                properties.put( "username", "fb_" + fb_user.id );
+                properties.put( "name", fb_user.name );
+                properties.put( "picture", String.format( pictureUrl, fb_user.id ) );
 
-                if ( fb_user_email != null ) {
+                if ( fb_user.email != null ) {
                     try {
                         user = managementService.getAppUserByIdentifier( entityManager.getApplication().getUuid(),
-                                Identifier.fromEmail( fb_user_email ) );
+                                Identifier.fromEmail( fb_user.email ) );
                     }
                     catch ( Exception ex ) {
                         throw new BadTokenException(
-                                "Could not find existing user for this applicaiton for email:
" + fb_user_email, ex );
+                                "Could not find existing user for this applicaiton for email:
" + fb_user.email, ex );
                     }
                     // if we found the user by email, unbind the properties from above
                     // that will conflict
@@ -160,7 +168,7 @@ public class FacebookProvider extends AbstractProvider {
                         user.setProperty( PROPERTY_MODIFIED, properties.get( PROPERTY_MODIFIED
) );
                     }
                     else {
-                        properties.put( "email", fb_user_email );
+                        properties.put( "email", fb_user.email );
                     }
                 }
                 if ( user == null ) {
@@ -178,12 +186,12 @@ public class FacebookProvider extends AbstractProvider {
                 Map<String, Object> properties = new LinkedHashMap<String, Object>();
 
                 properties.put( "facebook", fb_user );
-                properties.put( "picture", String.format( pictureUrl, fb_user_id ) );
+                properties.put( "picture", String.format( pictureUrl, fb_user.id ) );
                 try {
                     entityManager.updateProperties( user, properties );
                     user.setProperty( PROPERTY_MODIFIED, properties.get( PROPERTY_MODIFIED
) );
                     user.setProperty( "facebook", fb_user );
-                    user.setProperty( "picture", String.format( pictureUrl, fb_user_id )
);
+                    user.setProperty( "picture", String.format( pictureUrl, fb_user.id )
);
                 }
                 catch ( Exception ex ) {
                     throw new BadTokenException( "Could not update user properties", ex );
@@ -196,4 +204,44 @@ public class FacebookProvider extends AbstractProvider {
 
         return user;
     }
+
+    @JsonIgnoreProperties(ignoreUnknown=true)
+    static class FacebookUser {
+        @JsonProperty("id") String id;
+        @JsonProperty("name") String name;
+        @JsonProperty("username") String username;
+        @JsonProperty("email") String email;
+
+        public String getId() {
+            return id;
+        }
+
+        public void setId(String id) {
+            this.id = id;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getUsername() {
+            return username;
+        }
+
+        public void setUsername(String username) {
+            this.username = username;
+        }
+
+        public String getEmail() {
+            return email;
+        }
+
+        public void setEmail(String email) {
+            this.email = email;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d8fed0/stack/services/src/main/java/org/apache/usergrid/security/providers/FoursquareProvider.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/providers/FoursquareProvider.java
b/stack/services/src/main/java/org/apache/usergrid/security/providers/FoursquareProvider.java
index 9c3372f..719c541 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/providers/FoursquareProvider.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/providers/FoursquareProvider.java
@@ -18,11 +18,10 @@ package org.apache.usergrid.security.providers;
 
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
-import javax.ws.rs.core.MediaType;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.usergrid.management.ManagementService;
@@ -33,11 +32,7 @@ import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.security.tokens.exceptions.BadTokenException;
 import org.apache.usergrid.utils.JsonUtils;
 
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.json.JSONConfiguration;
+import org.springframework.web.client.RestTemplate;
 
 import static org.apache.usergrid.utils.ListUtils.anyNull;
 
@@ -52,8 +47,8 @@ public class FoursquareProvider extends AbstractProvider {
     private Logger logger = LoggerFactory.getLogger( FoursquareProvider.class );
 
 
-    FoursquareProvider( EntityManager entityManager, ManagementService managementService
) {
-        super( entityManager, managementService );
+    FoursquareProvider( EntityManager entityManager, ManagementService managementService,
RestTemplate restTemplate ) {
+        super( entityManager, managementService, restTemplate );
     }
 
 
@@ -66,8 +61,18 @@ public class FoursquareProvider extends AbstractProvider {
 
     @Override
     Map<String, Object> userFromResource( String externalToken ) {
-        // TODO user extraction
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("oauth_token", externalToken);
+        params.put("v", "20140318");
+        try {
+            String json = restTemplate.getForObject("https://api.foursquare.com/v2/users/self?oauth_token={oauth_token}&v={v}",
String.class, params);
+            Map<String, Object> data = (Map<String, Object>) JsonUtils.parse(json);
+            Map<String, Object> response = (Map<String, Object>) data.get("response");
+            Map<String, Object> user = (Map<String, Object>) response.get("user");
+            return user;
+        } catch (Exception e) {
+        }
+        return null;
     }
 
 
@@ -82,17 +87,9 @@ public class FoursquareProvider extends AbstractProvider {
         saveToConfiguration( "foursquareProvider", config );
     }
 
-
     @Override
     public User createOrAuthenticate( String externalToken ) throws BadTokenException {
-        ClientConfig clientConfig = new DefaultClientConfig();
-        clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE
);
-        Client client = Client.create( clientConfig );
-        WebResource web_resource = client.resource( "https://api.foursquare.com/v2/users/self"
);
-        Map<String, Object> body = web_resource.queryParam( "oauth_token", externalToken
).queryParam( "v", "20120623" )
-                                               .accept( MediaType.APPLICATION_JSON ).get(
Map.class );
-
-        Map<String, Object> fq_user = ( Map<String, Object> ) ( ( Map<?, ?>
) body.get( "response" ) ).get( "user" );
+        Map<String, Object> fq_user = userFromResource(externalToken);
 
         String fq_user_id = ( String ) fq_user.get( "id" );
         String fq_user_username = ( String ) fq_user.get( "id" );
@@ -101,17 +98,18 @@ public class FoursquareProvider extends AbstractProvider {
         String fq_user_name = new String( "" );
 
         // Grab the last check-in so we can store that as the user location
-        Map<String, Object> fq_location =
-                ( Map<String, Object> ) ( ( Map<?, ?> ) ( ( Map<?, ?> )
( ( ArrayList<?> ) ( ( Map<?, ?> ) fq_user
-                        .get( "checkins" ) ).get( "items" ) ).get( 0 ) ).get( "venue" ) ).get(
"location" );
-
         Map<String, Double> location = new LinkedHashMap<String, Double>();
-        location.put( "latitude", ( Double ) fq_location.get( "lat" ) );
-        location.put( "longitude", ( Double ) fq_location.get( "lng" ) );
-
-        if ( logger.isDebugEnabled() ) {
-            logger.debug( JsonUtils.mapToFormattedJsonString( location ) );
-        }
+        try {
+            Map<String, Object> fq_location =
+                    ( Map<String, Object> ) ( ( Map<?, ?> ) ( ( Map<?, ?>
) ( ( ArrayList<?> ) ( ( Map<?, ?> ) fq_user
+                            .get("checkins") ).get( "items" ) ).get( 0 ) ).get( "venue" )
).get( "location" );
+            location.put( "latitude", ( Double ) fq_location.get( "lat" ) );
+            location.put( "longitude", ( Double ) fq_location.get( "lng" ) );
+
+            if ( logger.isDebugEnabled() ) {
+                logger.debug( JsonUtils.mapToFormattedJsonString( location ) );
+            }
+        } catch (Exception e) { }
 
         // Only the first name is guaranteed to be here
         try {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d8fed0/stack/services/src/main/java/org/apache/usergrid/security/providers/PingIdentityProvider.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/providers/PingIdentityProvider.java
b/stack/services/src/main/java/org/apache/usergrid/security/providers/PingIdentityProvider.java
index e7ea2b1..bffea26 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/providers/PingIdentityProvider.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/providers/PingIdentityProvider.java
@@ -23,6 +23,10 @@ import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
 
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.json.JSONConfiguration;
 import org.codehaus.jackson.JsonNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,6 +35,7 @@ import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.Identifier;
 import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.security.tokens.exceptions.BadTokenException;
+import org.springframework.web.client.RestTemplate;
 
 
 /**
@@ -47,8 +52,8 @@ public class PingIdentityProvider extends AbstractProvider {
     private String clientSecret;
 
 
-    PingIdentityProvider( EntityManager entityManager, ManagementService managementService
) {
-        super( entityManager, managementService );
+    PingIdentityProvider( EntityManager entityManager, ManagementService managementService,
RestTemplate restTemplate ) {
+        super( entityManager, managementService, restTemplate );
     }
 
 
@@ -121,7 +126,9 @@ public class PingIdentityProvider extends AbstractProvider {
 
     @Override
     Map<String, Object> userFromResource( String externalToken ) {
-
+        ClientConfig clientConfig = new DefaultClientConfig();
+        clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE
);
+        Client client = Client.create(clientConfig);
         JsonNode node = client.resource( apiUrl )
                               .queryParam( "grant_type", "urn:pingidentity.com:oauth2:grant_type:validate_bearer"
)
                               .queryParam( "client_secret", clientSecret ).queryParam( "client_id",
clientId )

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d8fed0/stack/services/src/main/java/org/apache/usergrid/security/providers/SignInProviderFactory.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/providers/SignInProviderFactory.java
b/stack/services/src/main/java/org/apache/usergrid/security/providers/SignInProviderFactory.java
index 56c5f7e..1224433 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/providers/SignInProviderFactory.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/providers/SignInProviderFactory.java
@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.apache.usergrid.management.ManagementService;
 import org.apache.usergrid.persistence.EntityManagerFactory;
 import org.apache.usergrid.persistence.entities.Application;
+import org.springframework.web.client.RestTemplate;
 
 
 /** @author zznate */
@@ -28,23 +29,24 @@ public class SignInProviderFactory {
 
     private EntityManagerFactory emf;
     private ManagementService managementService;
-
+    private RestTemplate restTemplate;
 
     @Autowired
     public void setEntityManagerFactory( EntityManagerFactory emf ) {
         this.emf = emf;
     }
 
-
     @Autowired
     public void setManagementService( ManagementService managementService ) {
         this.managementService = managementService;
     }
 
+    @Autowired
+    public void setRestTemplate(RestTemplate restTemplate) { this.restTemplate = restTemplate;
}
 
     public SignInAsProvider facebook( Application application ) {
         FacebookProvider facebookProvider =
-                new FacebookProvider( emf.getEntityManager( application.getUuid() ), managementService
);
+                new FacebookProvider( emf.getEntityManager( application.getUuid() ), managementService,
restTemplate );
         facebookProvider.configure();
         return facebookProvider;
     }
@@ -52,7 +54,7 @@ public class SignInProviderFactory {
 
     public SignInAsProvider foursquare( Application application ) {
         FoursquareProvider foursquareProvider =
-                new FoursquareProvider( emf.getEntityManager( application.getUuid() ), managementService
);
+                new FoursquareProvider( emf.getEntityManager( application.getUuid() ), managementService,
restTemplate );
         foursquareProvider.configure();
         return foursquareProvider;
     }
@@ -60,7 +62,7 @@ public class SignInProviderFactory {
 
     public SignInAsProvider pingident( Application application ) {
         PingIdentityProvider pingIdentityProvider =
-                new PingIdentityProvider( emf.getEntityManager( application.getUuid() ),
managementService );
+                new PingIdentityProvider( emf.getEntityManager( application.getUuid() ),
managementService, restTemplate );
         pingIdentityProvider.configure();
         return pingIdentityProvider;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d8fed0/stack/services/src/main/resources/usergrid-services-context.xml
----------------------------------------------------------------------
diff --git a/stack/services/src/main/resources/usergrid-services-context.xml b/stack/services/src/main/resources/usergrid-services-context.xml
index e7e2281..dbed1e1 100644
--- a/stack/services/src/main/resources/usergrid-services-context.xml
+++ b/stack/services/src/main/resources/usergrid-services-context.xml
@@ -16,79 +16,102 @@
     limitations under the License.
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
-	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
-	xsi:schemaLocation="
-	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
-	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
-	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
+       xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
+       xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
 
-	<context:component-scan base-package="org.apache.usergrid.services"  />
-	
-	
-	<import resource="classpath:/usergrid-core-context.xml" />
+    <context:component-scan base-package="org.apache.usergrid.services"  />
 
-	<!--  scan for security -->
-	<context:component-scan base-package="org.apache.usergrid.security.crypto"  />
 
-	<bean id="realm" class="org.apache.usergrid.security.shiro.Realm">
-		<property name="name" value="realm" />
-	</bean>
+    <import resource="classpath:/usergrid-core-context.xml" />
 
-	<bean id="securityManager" class="org.apache.shiro.mgt.DefaultSecurityManager">
-		<property name="realm" ref="realm" />
-	</bean>
+    <!--  scan for security -->
+    <context:component-scan base-package="org.apache.usergrid.security.crypto"  />
 
-	<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"
/>
+    <bean id="realm" class="org.apache.usergrid.security.shiro.Realm">
+        <property name="name" value="realm" />
+    </bean>
+
+    <bean id="securityManager" class="org.apache.shiro.mgt.DefaultSecurityManager">
+        <property name="realm" ref="realm" />
+    </bean>
 
-	<bean
-		class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
-		<property name="staticMethod"
-			value="org.apache.shiro.SecurityUtils.setSecurityManager" />
-		<property name="arguments" ref="securityManager" />
-	</bean>
+    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"
/>
+
+    <bean
+            class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+        <property name="staticMethod"
+                  value="org.apache.shiro.SecurityUtils.setSecurityManager" />
+        <property name="arguments" ref="securityManager" />
+    </bean>
 
 
-	<bean id="taskExecutor" class="org.springframework.core.task.SyncTaskExecutor"/>
+    <bean id="taskExecutor" class="org.springframework.core.task.SyncTaskExecutor"/>
 
-	<bean id="tokenService" class="org.apache.usergrid.security.tokens.cassandra.TokenServiceImpl">
+    <bean id="tokenService" class="org.apache.usergrid.security.tokens.cassandra.TokenServiceImpl">
         <property name="cassandraService" ref="cassandraService"/>
         <property name="entityManagerFactory" ref="entityManagerFactory"/>
-            </bean>
+    </bean>
+
+    <bean id="managementService" class="org.apache.usergrid.management.cassandra.ManagementServiceImpl"
>
+        <property name="saltProvider" ref="saltProvider"/>
+    </bean>
 
-	<bean id="managementService" class="org.apache.usergrid.management.cassandra.ManagementServiceImpl"
>
-		<property name="saltProvider" ref="saltProvider"/>
-	</bean>
-	
-	<bean id="saltProvider" class="org.apache.usergrid.security.salt.NoOpSaltProvider" />
+    <bean id="saltProvider" class="org.apache.usergrid.security.salt.NoOpSaltProvider"
/>
 
-	<bean id="serviceManagerFactory" class="org.apache.usergrid.services.ServiceManagerFactory">
-		<constructor-arg ref="entityManagerFactory" />
-		<constructor-arg ref="properties" />
-		<constructor-arg ref="schedulerService"/>
+    <bean id="serviceManagerFactory" class="org.apache.usergrid.services.ServiceManagerFactory">
+        <constructor-arg ref="entityManagerFactory" />
+        <constructor-arg ref="properties" />
+        <constructor-arg ref="schedulerService"/>
         <constructor-arg ref="lockManager"/>
         <constructor-arg ref="queueManagerFactory"/>
-	</bean>
+    </bean>
+
+    <bean id="applicationCreator"
+          class="org.apache.usergrid.management.cassandra.ApplicationCreatorImpl">
+        <constructor-arg ref="entityManagerFactory" />
+        <constructor-arg ref="managementService" />
+    </bean>
+
+    <bean id="requestConfigBuilder" class="org.apache.http.client.config.RequestConfig"
factory-method="custom">
+        <property name="socketTimeout" value="3000" />
+        <property name="connectTimeout" value="3000" />
+    </bean>
+
+    <bean id="requestConfig" factory-bean="requestConfigBuilder" factory-method="build"
/>
+
+    <bean id="httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder"
factory-method="create">
+        <property name="defaultRequestConfig" ref="requestConfig" />
+        <property name="maxConnTotal" value="100" />
+        <property name="maxConnPerRoute" value="100" />
+    </bean>
 
-	<bean id="applicationCreator"
-		class="org.apache.usergrid.management.cassandra.ApplicationCreatorImpl">
-		<constructor-arg ref="entityManagerFactory" />
-		<constructor-arg ref="managementService" />
-	</bean>
+    <bean id="httpClient" factory-bean="httpClientBuilder" factory-method="build" />
+
+    <bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
+        <constructor-arg>
+            <bean class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
+                <property name="httpClient" ref="httpClient"/>
+            </bean>
+        </constructor-arg>
+    </bean>
 
     <bean id="signInProviderFactory" class="org.apache.usergrid.security.providers.SignInProviderFactory">
         <property name="entityManagerFactory" ref="entityManagerFactory"/>
         <property name="managementService" ref="managementService"/>
+        <property name="restTemplate" ref="restTemplate"/>
     </bean>
 
-  <bean id="exportService" class="org.apache.usergrid.management.export.ExportServiceImpl"
>
-    <property name="managementService" ref="managementService"/>
-    <property name="emf" ref="entityManagerFactory"/>
-    <property name="sch" ref="schedulerService"/>
-  </bean>
+    <bean id="exportService" class="org.apache.usergrid.management.export.ExportServiceImpl"
>
+        <property name="managementService" ref="managementService"/>
+        <property name="emf" ref="entityManagerFactory"/>
+        <property name="sch" ref="schedulerService"/>
+    </bean>
 
-  <bean id="exportJob" class="org.apache.usergrid.management.export.ExportJob" />
+    <bean id="exportJob" class="org.apache.usergrid.management.export.ExportJob" />
 
-  <bean id="s3Export" class="org.apache.usergrid.management.export.S3ExportImpl" />
+    <bean id="s3Export" class="org.apache.usergrid.management.export.S3ExportImpl" />
 
-</beans>
+</beans>
\ No newline at end of file


Mime
View raw message