Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

USERGRID-77 can't login for newly created user due to NPE #48

Merged
merged 1 commit into from

2 participants

@stliu

No description provided.

@tnine tnine merged commit f564f0d into usergrid:master
@tnine
Owner

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 stack/services/src/main/java/org/usergrid/management/AccountCreationProps.java
@@ -116,4 +116,11 @@
public void setProperty( String name, String value );
public Properties getMailProperties();
+ public SuperUser getSuperUser();
+ public static interface SuperUser{
+ boolean isEnabled();
+ String getUsername();
+ String getEmail();
+ String getPassword();
+ }
}
View
50 stack/services/src/main/java/org/usergrid/management/cassandra/AccountCreationPropsImpl.java
@@ -26,16 +26,18 @@
import static java.lang.Boolean.parseBoolean;
import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.usergrid.utils.ListUtils.anyNull;
public class AccountCreationPropsImpl implements AccountCreationProps {
private static final Logger logger = LoggerFactory.getLogger( AccountCreationPropsImpl.class );
- protected Properties properties;
-
+ protected final Properties properties;
+ private final SuperUser superUser;
public AccountCreationPropsImpl( Properties properties ) {
this.properties = properties;
+ this.superUser = new SuperUserImpl(properties);
}
@@ -109,4 +111,48 @@ public Properties getMailProperties() {
}
return p;
}
+
+ @Override
+ public SuperUser getSuperUser() {
+ return superUser;
+ }
+
+ protected static class SuperUserImpl implements SuperUser {
+ private final boolean enabled;
+ private final String username;
+ private final String email;
+ private final String password;
+
+ public SuperUserImpl(Properties properties) {
+ enabled = parseBoolean(properties.getProperty(PROPERTIES_SYSADMIN_LOGIN_ALLOWED));
+ username = properties.getProperty(PROPERTIES_SYSADMIN_LOGIN_NAME);
+ email = properties.getProperty(PROPERTIES_SYSADMIN_LOGIN_EMAIL);
+ password = properties.getProperty(PROPERTIES_SYSADMIN_LOGIN_PASSWORD);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return superuserEnabled();
+ }
+
+ @Override
+ public String getUsername() {
+ return username;
+ }
+
+ @Override
+ public String getEmail() {
+ return email;
+ }
+
+ @Override
+ public String getPassword() {
+ return password;
+ }
+
+ private boolean superuserEnabled() {
+ return enabled && !anyNull(username, email, password);
+ }
+ }
+
}
View
40 stack/services/src/main/java/org/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -129,10 +129,7 @@
import static org.usergrid.management.AccountCreationProps.PROPERTIES_ORGANIZATION_ACTIVATION_URL;
import static org.usergrid.management.AccountCreationProps.PROPERTIES_SETUP_TEST_ACCOUNT;
import static org.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_EMAIL;
-import static org.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_ALLOWED;
import static org.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_EMAIL;
-import static org.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_NAME;
-import static org.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_PASSWORD;
import static org.usergrid.management.AccountCreationProps.PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL;
import static org.usergrid.management.AccountCreationProps.PROPERTIES_TEST_ACCOUNT_ADMIN_USER_NAME;
import static org.usergrid.management.AccountCreationProps.PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD;
@@ -321,37 +318,25 @@ public void setup() throws Exception {
logger.warn( "Test app creation disabled" );
}
- if ( superuserEnabled() ) {
+ if ( properties.getSuperUser().isEnabled() ) {
provisionSuperuser();
}
}
- public boolean superuserEnabled() {
- boolean superuser_enabled = parseBoolean( properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_ALLOWED ) );
- String superuser_username = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_NAME );
- String superuser_email = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL );
- String superuser_password = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_PASSWORD );
-
- return superuser_enabled && !anyNull( superuser_username, superuser_email, superuser_password );
- }
@Override
public void provisionSuperuser() throws Exception {
- boolean superuser_enabled = parseBoolean( properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_ALLOWED ) );
- String superuser_username = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_NAME );
- String superuser_email = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL );
- String superuser_password = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_PASSWORD );
-
- if ( !anyNull( superuser_username, superuser_email, superuser_password ) ) {
- UserInfo user = this.getAdminUserByUsername( superuser_username );
+ final AccountCreationProps.SuperUser superUser = properties.getSuperUser();
+ if ( superUser.isEnabled() ) {
+ UserInfo user = this.getAdminUserByUsername( superUser.getUsername() );
if ( user == null ) {
- createAdminUser( superuser_username, "Super User", superuser_email, superuser_password,
- superuser_enabled, !superuser_enabled );
+ createAdminUser( superUser.getUsername(), "Super User", superUser.getEmail(), superUser.getPassword(),
+ superUser.isEnabled(), !superUser.isEnabled() );
}
else {
- this.setAdminUserPassword( user.getUuid(), superuser_password );
+ this.setAdminUserPassword( user.getUuid(), superUser.getPassword() );
}
}
else {
@@ -1246,13 +1231,12 @@ public UserInfo verifyAdminUserPasswordCredentials( String name, String password
if ( verify( MANAGEMENT_APPLICATION_ID, user.getUuid(), password ) ) {
userInfo = getUserInfo( MANAGEMENT_APPLICATION_ID, user );
- boolean userIsSuperAdmin =
- properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL ).equals( userInfo.getEmail() );
+ boolean userIsSuperAdmin = properties.getSuperUser().isEnabled() && properties.getSuperUser().getEmail().equals(userInfo.getEmail());
boolean testUserEnabled = parseBoolean( properties.getProperty( PROPERTIES_SETUP_TEST_ACCOUNT ) );
boolean userIsTestUser = !testUserEnabled ? false :
- properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL )
+ properties.getProperty( PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL )
.equals( userInfo.getEmail() );
if ( !userIsSuperAdmin && !userIsTestUser ) {
@@ -1488,10 +1472,8 @@ public Long getLastAdminPasswordChange( UUID userId ) throws Exception {
json.put( "organizations", jsonOrganizations );
Map<UUID, String> organizations;
-
- boolean superuser_enabled = parseBoolean( properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_ALLOWED ) );
- String superuser_username = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_NAME );
- if ( superuser_enabled && ( superuser_username != null ) && superuser_username.equals( user.getUsername() ) ) {
+ AccountCreationProps.SuperUser superUser = properties.getSuperUser();
+ if ( superUser.isEnabled() && superUser.getUsername().equals( user.getUsername() ) ) {
organizations = buildOrgBiMap( getOrganizations( null, 10 ) );
}
else {
Something went wrong with that request. Please try again.