You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/09/08 16:31:11 UTC

[1/5] usergrid git commit: Use URLs (like admin reset password URL) from properties if they are provided.

Repository: usergrid
Updated Branches:
  refs/heads/master efb5bfbfd -> d915f557b


Use URLs (like admin reset password URL) from properties if they are
provided.


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

Branch: refs/heads/master
Commit: ef51f3d7b15be1000dc03e614afba57d46f17fe0
Parents: b567014
Author: Mike Dunker <md...@apigee.com>
Authored: Wed Sep 7 16:59:22 2016 -0700
Committer: Mike Dunker <md...@apigee.com>
Committed: Wed Sep 7 16:59:22 2016 -0700

----------------------------------------------------------------------
 .../management/AccountCreationProps.java        |  8 +++++
 .../cassandra/OrganizationConfigPropsImpl.java  | 38 +++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/ef51f3d7/stack/services/src/main/java/org/apache/usergrid/management/AccountCreationProps.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/AccountCreationProps.java b/stack/services/src/main/java/org/apache/usergrid/management/AccountCreationProps.java
index 17f2c6a..b1c1148 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/AccountCreationProps.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/AccountCreationProps.java
@@ -54,6 +54,14 @@ public interface AccountCreationProps {
     String PROPERTIES_EMAIL_USER_PIN_REQUEST = "usergrid.management.email.user-pin";
     String PROPERTIES_EMAIL_FOOTER = "usergrid.management.email.footer";
 
+    String PROPERTIES_USER_ACTIVATION_URL = "usergrid.user.activation.url";
+    String PROPERTIES_USER_CONFIRMATION_URL = "usergrid.user.confirmation.url";
+    String PROPERTIES_USER_RESETPW_URL = "usergrid.user.resetpw.url";
+    String PROPERTIES_ADMIN_ACTIVATION_URL = "usergrid.admin.activation.url";
+    String PROPERTIES_ADMIN_CONFIRMATION_URL = "usergrid.admin.confirmation.url";
+    String PROPERTIES_ORGANIZATION_ACTIVATION_URL = "usergrid.organization.activation.url";
+    String PROPERTIES_ADMIN_RESETPW_URL = "usergrid.admin.resetpw.url";
+
     String PROPERTIES_USERGRID_SYSADMIN_LOGIN_FETCH_ORGS = "usergrid.sysadmin.login.fetch_orgs";
 
     String PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION =

http://git-wip-us.apache.org/repos/asf/usergrid/blob/ef51f3d7/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
index 5d2c256..adfadf2 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.management.cassandra;
 
 
+import org.apache.usergrid.management.AccountCreationProps;
 import org.apache.usergrid.management.OrganizationConfigProps;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -206,10 +207,45 @@ public class OrganizationConfigPropsImpl implements OrganizationConfigProps {
         orgProperties.put(name,value);
     }
 
+    protected String getWorkflowUrlOverrideProperty(WorkflowUrl urlType) {
+        String propertyName = null;
+        switch (urlType) {
+            case ORGANIZATION_ACTIVATION_URL:
+                propertyName = AccountCreationProps.PROPERTIES_ORGANIZATION_ACTIVATION_URL;
+                break;
+            case ADMIN_ACTIVATION_URL:
+                propertyName = AccountCreationProps.PROPERTIES_ADMIN_ACTIVATION_URL;
+                break;
+            case ADMIN_CONFIRMATION_URL:
+                propertyName = AccountCreationProps.PROPERTIES_ADMIN_CONFIRMATION_URL;
+                break;
+            case ADMIN_RESETPW_URL:
+                propertyName = AccountCreationProps.PROPERTIES_ADMIN_RESETPW_URL;
+                break;
+            case USER_ACTIVATION_URL:
+                propertyName = AccountCreationProps.PROPERTIES_USER_ACTIVATION_URL;
+                break;
+            case USER_CONFIRMATION_URL:
+                propertyName = AccountCreationProps.PROPERTIES_USER_CONFIRMATION_URL;
+                break;
+            case USER_RESETPW_URL:
+                propertyName = AccountCreationProps.PROPERTIES_USER_RESETPW_URL;
+                break;
+            default:
+                return null;
+        }
+
+        return getProperty(propertyName);
+    }
+
     @Override
     public String getFullUrlTemplate(WorkflowUrl urlType) {
         String urlTemplate = null;
-        if (urlPaths.containsKey(urlType)) {
+        String propertyValue = getWorkflowUrlOverrideProperty(urlType);
+        if (propertyValue != null) {
+            urlTemplate = propertyValue;
+        }
+        else if (urlPaths.containsKey(urlType)) {
             urlTemplate = getProperty(ORGPROPERTIES_API_URL_BASE) + urlPaths.get(urlType);
         }
         return urlTemplate;


[4/5] usergrid git commit: Add unique value index update option to UniqueValueManager tool.

Posted by mr...@apache.org.
Add unique value index update option to UniqueValueManager tool.


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

Branch: refs/heads/master
Commit: 72dcd48891f8881d7321f10ff8a96eb46ee74a40
Parents: fbcdada
Author: Michael Russo <mr...@apigee.com>
Authored: Wed Sep 7 22:19:48 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Wed Sep 7 22:19:48 2016 -0700

----------------------------------------------------------------------
 .../usergrid/tools/UniqueValueManager.java      | 184 +++++++------------
 1 file changed, 68 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/72dcd488/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueManager.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueManager.java b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueManager.java
index 6131866..14991ef 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueManager.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueManager.java
@@ -23,16 +23,20 @@ import java.io.FileReader;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import com.google.common.base.*;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import com.netflix.astyanax.model.Column;
 import com.netflix.astyanax.model.ConsistencyLevel;
 import com.netflix.astyanax.util.RangeBuilder;
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.collection.MvccEntity;
 import org.apache.usergrid.persistence.collection.serialization.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
 import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
 import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
 import org.apache.usergrid.persistence.collection.serialization.impl.*;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.field.StringField;
@@ -59,6 +63,10 @@ public class UniqueValueManager extends ToolBase {
 
     private static final String CONFIRM_DELETE_ARG = "confirmDelete";
 
+    private static final String CONFIRM_UPDATE_ARG = "confirmUpdate";
+
+    private static final String SERIALIZATION_REPAIR_ARG = "useSerializationRepair";
+
     private static final String FILEPATH_ARG = "file";
 
 
@@ -100,6 +108,18 @@ public class UniqueValueManager extends ToolBase {
 
         options.addOption( confirmDeleteOption );
 
+        Option confirmUpdateOption =
+            OptionBuilder.withArgName(CONFIRM_UPDATE_ARG).isRequired( false ).withDescription( "confirm update" )
+                .create(CONFIRM_UPDATE_ARG);
+
+        options.addOption( confirmUpdateOption );
+
+        Option useSerializationRepair =
+            OptionBuilder.withArgName(SERIALIZATION_REPAIR_ARG).isRequired( false ).withDescription( "use unique value serialization repair to keep oldest index" )
+                .create(SERIALIZATION_REPAIR_ARG);
+
+        options.addOption( useSerializationRepair );
+
         Option filepathOption =
             OptionBuilder.withArgName(FILEPATH_ARG).hasArg().isRequired( true )
                 .withDescription( "path to file containing UV info" ).create(FILEPATH_ARG);
@@ -126,8 +146,11 @@ public class UniqueValueManager extends ToolBase {
 
         String operation = line.getOptionValue(OPERATION_ARG) != null ? line.getOptionValue(OPERATION_ARG) : "get";
         boolean deleteOp = operation.toLowerCase().equals("delete");
+        boolean updateOp = operation.toLowerCase().equals("update");
         if (deleteOp && !line.hasOption(CONFIRM_DELETE_ARG)) {
             throw new RuntimeException("Must add confirmDelete option to use delete.");
+        }else if( updateOp && !line.hasOption(CONFIRM_UPDATE_ARG) ){
+            throw new RuntimeException("Must add confirmUpdate option to use update.");
         }
         String filepath = line.getOptionValue(FILEPATH_ARG);
         if (filepath == null || filepath.isEmpty()) {
@@ -144,15 +167,21 @@ public class UniqueValueManager extends ToolBase {
 
         File listFile = new File(filepath);
 
+        boolean useSerializationRepair = false;
+        if(line.hasOption(SERIALIZATION_REPAIR_ARG)){
+            useSerializationRepair = true;
+        }
+
         try (BufferedReader br = new BufferedReader(new FileReader(listFile))) {
             String fileLine;
             while ((fileLine = br.readLine()) != null) {
                 String[] valuesArray = fileLine.trim().split("\\|");
-                if (valuesArray.length != 4) {
+                if (valuesArray.length != 4 && valuesArray.length != 5) {
                     logger.info("Line: >"+fileLine+"<");
                     throw new RuntimeException("Invalid file -- should contain one row per entity formatted like " +
-                            "'{uuid}|{entityType}|{fieldType}|{fieldValue}'.  " +
-                            "Example: 'b9398e88-ef7f-11e5-9e41-0a2cb9e6caa9|user|email|whatever@usergrid.com'");
+                            "'{uuid}|{entityType}|{fieldType}|{fieldValue}|{newEntityUUID}'.  " +
+                            "Example: 'b9398e88-ef7f-11e5-9e41-0a2cb9e6caa9|user|email|whatever@usergrid.com|newEntityUUID'.  " +
+                            "Param {newEntityUUID} is optional.");
                 }
                 UUID appUuid = UUID.fromString(valuesArray[0]);
                 String entityType = valuesArray[1];
@@ -160,9 +189,42 @@ public class UniqueValueManager extends ToolBase {
                 String fieldValue = valuesArray[3];
 
                 UniqueValueSet uniqueValueSet = uniqueValueSerializationStrategy.load(
-                        new ApplicationScopeImpl(new SimpleId(appUuid, "application")),
-                        ConsistencyLevel.valueOf(System.getProperty("usergrid.read.cl", "CL_LOCAL_QUORUM")), entityType,
-                        Collections.singletonList(new StringField(fieldType, fieldValue)), false);
+                    new ApplicationScopeImpl(new SimpleId(appUuid, "application")),
+                    ConsistencyLevel.valueOf(System.getProperty("usergrid.read.cl", "CL_LOCAL_QUORUM")), entityType,
+                    Collections.singletonList(new StringField(fieldType, fieldValue)), useSerializationRepair);
+
+                if( updateOp) {
+
+                    if(valuesArray.length!=5){
+                        throw new RuntimeException("Missing param {newEntityUUID}");
+                    }
+                    String updateUUID = valuesArray[4];
+
+                    ApplicationScope applicationScope = new ApplicationScopeImpl(new SimpleId(appUuid, "application"));
+                    com.google.common.base.Optional<MvccEntity> entity =
+                        mvccEntitySerializationStrategy.load(applicationScope, new SimpleId(UUID.fromString(updateUUID), entityType));
+
+                    if( !entity.isPresent()
+                        || !entity.get().getEntity().isPresent() ){
+                        throw new RuntimeException("Unable to update unique value index because supplied UUID "+updateUUID+" does not exist");
+                    }
+
+                    logger.info("Delete unique value: {}",  uniqueValueSet.getValue(fieldType));
+                    uniqueValueSerializationStrategy.delete(applicationScope, uniqueValueSet.getValue(fieldType)).execute();
+
+                    UniqueValue newUniqueValue =
+                        new UniqueValueImpl(new StringField(fieldType, fieldValue), entity.get().getId(), entity.get().getVersion());
+                    logger.info("Writing new unique value: {}", newUniqueValue);
+                    uniqueValueSerializationStrategy.write(applicationScope, newUniqueValue).execute();
+
+                    logger.info("Re-loading unique value set for field");
+
+                }
+
+                uniqueValueSet = uniqueValueSerializationStrategy.load(
+                    new ApplicationScopeImpl(new SimpleId(appUuid, "application")),
+                    ConsistencyLevel.valueOf(System.getProperty("usergrid.read.cl", "CL_LOCAL_QUORUM")), entityType,
+                    Collections.singletonList(new StringField(fieldType, fieldValue)), useSerializationRepair);
 
                 StringBuilder stringBuilder = new StringBuilder();
 
@@ -198,114 +260,4 @@ public class UniqueValueManager extends ToolBase {
             }
         }
     }
-
-        /*
-        } else {
-
-            logger.info("Running entity unique scanner only");
-
-
-            // scan through all unique values and log some info
-
-            Iterator<com.netflix.astyanax.model.Row<ScopedRowKey<TypeField>, EntityVersion>> rows = null;
-            try {
-
-                rows = keyspace.prepareQuery(CF_UNIQUE_VALUES)
-                    .setConsistencyLevel(ConsistencyLevel.valueOf(System.getProperty("usergrid.read.cl", "CL_LOCAL_QUORUM")))
-                    .getAllRows()
-                    .withColumnRange(new RangeBuilder().setLimit(1000).build())
-                    .execute().getResult().iterator();
-
-            } catch (ConnectionException e) {
-
-                logger.error("Error connecting to cassandra", e);
-            }
-
-
-            UUID finalAppToFilter = appToFilter;
-
-            if( rows != null) {
-                rows.forEachRemaining(row -> {
-
-                    count.incrementAndGet();
-
-                    if(count.get() % 1000 == 0 ){
-                        logger.info("Scanned {} rows in {}", count.get(), CF_UNIQUE_VALUES.getName());
-                    }
-
-                    final String fieldName = row.getKey().getKey().getField().getName();
-                    final String fieldValue = row.getKey().getKey().getField().getValue().toString();
-                    final String scopeType = row.getKey().getScope().getType();
-                    final UUID scopeUUID = row.getKey().getScope().getUuid();
-
-
-                    if (!fieldName.equalsIgnoreCase(fieldType) ||
-                        (finalAppToFilter != null && !finalAppToFilter.equals(scopeUUID))
-                        ) {
-                        // do nothing
-
-                    } else {
-
-
-                        // if we have more than 1 column, let's check for a duplicate
-                        if (row.getColumns() != null && row.getColumns().size() > 1) {
-
-                            final List<EntityVersion> values = new ArrayList<>(row.getColumns().size());
-
-                            Iterator<Column<EntityVersion>> columns = row.getColumns().iterator();
-                            columns.forEachRemaining(column -> {
-
-
-                                final EntityVersion entityVersion = column.getName();
-
-
-                                logger.trace(
-                                    scopeType + ": " + scopeUUID + ", " +
-                                        fieldName + ": " + fieldValue + ", " +
-                                        "entity type: " + entityVersion.getEntityId().getType() + ", " +
-                                        "entity uuid: " + entityVersion.getEntityId().getUuid()
-                                );
-
-
-                                if (entityType != null &&
-                                    entityVersion.getEntityId().getType().equalsIgnoreCase(entityType)
-                                    ) {
-
-                                    // add the first value into the list
-                                    if (values.size() == 0) {
-
-                                        values.add(entityVersion);
-
-
-                                    } else {
-
-                                        if (!values.get(0).getEntityId().getUuid().equals(entityVersion.getEntityId().getUuid())) {
-
-                                            values.add(entityVersion);
-
-                                            logger.error("Duplicate found for field [{}={}].  Entry 1: [{}], Entry 2: [{}]",
-                                                fieldName, fieldValue, values.get(0).getEntityId(), entityVersion.getEntityId());
-
-                                        }
-
-                                    }
-
-
-                                }
-
-                            });
-                        }
-                    }
-
-
-                });
-            }else{
-
-                logger.warn("No rows returned from table: {}", CF_UNIQUE_VALUES.getName());
-
-            }
-
-        }
-    }
-    */
 }


[2/5] usergrid git commit: Fix NPE when user doesn't exist after lookup from the unique value index.

Posted by mr...@apache.org.
Fix NPE when user doesn't exist after lookup from the unique value index.


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

Branch: refs/heads/master
Commit: 5fdce93b72481ec55d491150d52b1f5feed4fade
Parents: ef51f3d
Author: Michael Russo <mr...@apigee.com>
Authored: Wed Sep 7 17:23:10 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Wed Sep 7 17:23:10 2016 -0700

----------------------------------------------------------------------
 .../apache/usergrid/services/users/UsersService.java | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/5fdce93b/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java b/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java
index 0539695..7341743 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java
@@ -79,16 +79,12 @@ public class UsersService extends AbstractCollectionService {
 
     @Override
     public ServiceResults getItemByName( ServiceContext context, String name ) throws Exception {
-        String nameProperty = Schema.getDefaultSchema().aliasProperty( getEntityType() );
-
-        if ( nameProperty == null ) {
-            nameProperty = "name";
-        }
-
+        
         EntityRef entity = null;
         Identifier id = Identifier.from( name );
 
         if ( id != null ) {
+            // get the entityRef from the unique value index
             entity = em.getUserByIdentifier( id );
         }
 
@@ -97,7 +93,14 @@ public class UsersService extends AbstractCollectionService {
         }
 
         if ( !context.moreParameters() ) {
+
+            // full load the entity from the database based on the UUID from the unique value index
             entity = em.get( entity );
+
+            if ( entity == null ) {
+                throw new ServiceResourceNotFoundException( context );
+            }
+
             entity = importEntity( context, ( Entity ) entity );
         }
 


[3/5] usergrid git commit: Add support for application and organization client credentials to be passed in Authorization header.

Posted by mr...@apache.org.
Add support for application and organization client credentials to be passed in Authorization header.


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

Branch: refs/heads/master
Commit: fbcdada6e9c2aa704094857e7182c6a22627c711
Parents: 5fdce93
Author: Michael Russo <mr...@apigee.com>
Authored: Wed Sep 7 20:16:52 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Wed Sep 7 20:16:52 2016 -0700

----------------------------------------------------------------------
 .../usergrid/rest/exceptions/AuthErrorInfo.java |  1 +
 .../shiro/filters/BasicAuthSecurityFilter.java  | 22 ++++++++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/fbcdada6/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AuthErrorInfo.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AuthErrorInfo.java b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AuthErrorInfo.java
index c9149e5..4d1d138 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AuthErrorInfo.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AuthErrorInfo.java
@@ -35,6 +35,7 @@ public enum AuthErrorInfo {
     OAUTH2_UNSUPPORTED_GRANT_TYPE( "unsupported_grant_type", "Unable to authenticate (OAuth)" ), //
     OAUTH2_INVALID_SCOPE( "invalid_scope", "Unable to authenticate (OAuth" ), //
     INVALID_AUTH_ERROR( "auth_invalid", "Unable to authenticate" ), //
+    INVALID_CLIENT_CREDENTIALS_ERROR( "auth_invalid_credentials", "Unable to authenticate due to invalid client credentials" ),
     MISSING_CREDENTIALS_ERROR( "auth_missing_credentials", "Unable to authenticate due to missing credentials" ), //
     BAD_CREDENTIALS_SYNTAX_ERROR( "auth_bad_credentials_syntax",
             "Unable to authenticate due to improperly constructed credentials" ), //

http://git-wip-us.apache.org/repos/asf/usergrid/blob/fbcdada6/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/BasicAuthSecurityFilter.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/BasicAuthSecurityFilter.java b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/BasicAuthSecurityFilter.java
index 5594a1c..d4d2e60 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/BasicAuthSecurityFilter.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/BasicAuthSecurityFilter.java
@@ -18,6 +18,9 @@ package org.apache.usergrid.rest.security.shiro.filters;
 
 
 import org.apache.shiro.codec.Base64;
+import org.apache.shiro.subject.Subject;
+import org.apache.usergrid.security.shiro.PrincipalCredentialsToken;
+import org.apache.usergrid.security.shiro.utils.SubjectUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,6 +31,8 @@ import javax.ws.rs.ext.Provider;
 import java.security.Principal;
 import java.util.Map;
 
+import static org.apache.usergrid.rest.exceptions.AuthErrorInfo.INVALID_CLIENT_CREDENTIALS_ERROR;
+import static org.apache.usergrid.rest.exceptions.SecurityException.mappableSecurityException;
 import static org.apache.usergrid.security.shiro.Realm.ROLE_SERVICE_ADMIN;
 
 
@@ -61,19 +66,32 @@ public class BasicAuthSecurityFilter extends SecurityFilter {
         if ( values.length < 2 ) {
             return;
         }
-        String name = values[0].toLowerCase();
+        String name = values[0];
         String password = values[1];
 
         String sysadmin_login_name = properties.getProperty( "usergrid.sysadmin.login.name" );
         String sysadmin_login_password = properties.getProperty( "usergrid.sysadmin.login.password" );
         boolean sysadmin_login_allowed =
                 Boolean.parseBoolean( properties.getProperty( "usergrid.sysadmin.login.allowed" ) );
-        if ( name.equals( sysadmin_login_name ) && password.equals( sysadmin_login_password )
+        if ( name.equalsIgnoreCase( sysadmin_login_name ) && password.equals( sysadmin_login_password )
                 && sysadmin_login_allowed ) {
             request.setSecurityContext( new SysAdminRoleAuthenticator() );
             if (logger.isTraceEnabled()) {
                 logger.trace("System administrator access allowed");
             }
+        }else{
+
+            try {
+                PrincipalCredentialsToken token =
+                    management.getPrincipalCredentialsTokenForClientCredentials( name, password );
+                Subject subject = SubjectUtils.getSubject();
+                subject.login( token );
+            }
+            catch ( Exception e ) {
+                throw mappableSecurityException( INVALID_CLIENT_CREDENTIALS_ERROR );
+            }
+
+
         }
     }
 


[5/5] usergrid git commit: Merge branch 'hotfix-20160819'

Posted by mr...@apache.org.
Merge branch 'hotfix-20160819'


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

Branch: refs/heads/master
Commit: d915f557b46a5ba7d9d3d711f44a6a8ed89e3847
Parents: efb5bfb 72dcd48
Author: Michael Russo <mr...@apigee.com>
Authored: Thu Sep 8 09:30:59 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Thu Sep 8 09:30:59 2016 -0700

----------------------------------------------------------------------
 .../usergrid/rest/exceptions/AuthErrorInfo.java |   1 +
 .../shiro/filters/BasicAuthSecurityFilter.java  |  22 ++-
 .../management/AccountCreationProps.java        |   8 +
 .../cassandra/OrganizationConfigPropsImpl.java  |  38 +++-
 .../usergrid/services/users/UsersService.java   |  15 +-
 .../usergrid/tools/UniqueValueManager.java      | 183 +++++++------------
 6 files changed, 142 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/d915f557/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueManager.java
----------------------------------------------------------------------
diff --cc stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueManager.java
index 6209784,14991ef..755ad3f
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueManager.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueManager.java
@@@ -23,11 -23,16 +23,13 @@@ import java.io.FileReader
  import java.util.*;
  import java.util.concurrent.atomic.AtomicInteger;
  
 -import com.google.common.base.*;
 -import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 -import com.netflix.astyanax.model.Column;
 -import com.netflix.astyanax.model.ConsistencyLevel;
 -import com.netflix.astyanax.util.RangeBuilder;
 -import org.apache.usergrid.persistence.Entity;
 +import com.datastax.driver.core.BatchStatement;
 +import com.datastax.driver.core.ConsistencyLevel;
 +import com.datastax.driver.core.Session;
  import org.apache.usergrid.persistence.EntityManager;
+ import org.apache.usergrid.persistence.collection.MvccEntity;
  import org.apache.usergrid.persistence.collection.serialization.MvccEntitySerializationStrategy;
+ import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
  import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
  import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
  import org.apache.usergrid.persistence.collection.serialization.impl.*;
@@@ -158,9 -189,42 +186,42 @@@ public class UniqueValueManager extend
                  String fieldValue = valuesArray[3];
  
                  UniqueValueSet uniqueValueSet = uniqueValueSerializationStrategy.load(
-                         new ApplicationScopeImpl(new SimpleId(appUuid, "application")),
-                         ConsistencyLevel.valueOf(System.getProperty("usergrid.read.cl", "LOCAL_QUORUM")), entityType,
-                         Collections.singletonList(new StringField(fieldType, fieldValue)), false);
+                     new ApplicationScopeImpl(new SimpleId(appUuid, "application")),
+                     ConsistencyLevel.valueOf(System.getProperty("usergrid.read.cl", "CL_LOCAL_QUORUM")), entityType,
+                     Collections.singletonList(new StringField(fieldType, fieldValue)), useSerializationRepair);
+ 
+                 if( updateOp) {
+ 
+                     if(valuesArray.length!=5){
+                         throw new RuntimeException("Missing param {newEntityUUID}");
+                     }
+                     String updateUUID = valuesArray[4];
+ 
+                     ApplicationScope applicationScope = new ApplicationScopeImpl(new SimpleId(appUuid, "application"));
+                     com.google.common.base.Optional<MvccEntity> entity =
+                         mvccEntitySerializationStrategy.load(applicationScope, new SimpleId(UUID.fromString(updateUUID), entityType));
+ 
+                     if( !entity.isPresent()
+                         || !entity.get().getEntity().isPresent() ){
+                         throw new RuntimeException("Unable to update unique value index because supplied UUID "+updateUUID+" does not exist");
+                     }
+ 
+                     logger.info("Delete unique value: {}",  uniqueValueSet.getValue(fieldType));
 -                    uniqueValueSerializationStrategy.delete(applicationScope, uniqueValueSet.getValue(fieldType)).execute();
++                    session.execute(uniqueValueSerializationStrategy.deleteCQL(applicationScope, uniqueValueSet.getValue(fieldType)));
+ 
+                     UniqueValue newUniqueValue =
+                         new UniqueValueImpl(new StringField(fieldType, fieldValue), entity.get().getId(), entity.get().getVersion());
+                     logger.info("Writing new unique value: {}", newUniqueValue);
 -                    uniqueValueSerializationStrategy.write(applicationScope, newUniqueValue).execute();
++                    session.execute(uniqueValueSerializationStrategy.writeCQL(applicationScope, newUniqueValue, -1));
+ 
+                     logger.info("Re-loading unique value set for field");
+ 
+                 }
+ 
+                 uniqueValueSet = uniqueValueSerializationStrategy.load(
+                     new ApplicationScopeImpl(new SimpleId(appUuid, "application")),
+                     ConsistencyLevel.valueOf(System.getProperty("usergrid.read.cl", "CL_LOCAL_QUORUM")), entityType,
+                     Collections.singletonList(new StringField(fieldType, fieldValue)), useSerializationRepair);
  
                  StringBuilder stringBuilder = new StringBuilder();