Search in sources :

Example 1 with Passwords

use of org.platformlayer.ops.crypto.Passwords in project platformlayer by platformlayer.

the class ServiceProviderBase method autoPopulate.

public void autoPopulate(Object item) throws OpsException {
    Class<? extends Object> itemClass = item.getClass();
    for (Field field : itemClass.getFields()) {
        Generate defaultAnnotation = field.getAnnotation(Generate.class);
        if (defaultAnnotation != null) {
            Class<?> fieldType = field.getType();
            Object value;
            try {
                value = field.get(item);
            } catch (IllegalAccessException e) {
                throw new IllegalStateException("Error getting field: " + field, e);
            }
            if (value == null) {
                String defaultValue = defaultAnnotation.value();
                if (!Strings.isNullOrEmpty(defaultValue)) {
                    value = defaultValue;
                } else {
                    if (fieldType == Secret.class) {
                        Passwords passwords = new Passwords();
                        Secret secret = passwords.generateRandomPassword(12);
                        value = secret;
                    }
                }
                if (value != null) {
                    try {
                        field.set(item, value);
                    } catch (IllegalAccessException e) {
                        throw new IllegalStateException("Error setting field: " + field, e);
                    }
                }
            }
        }
    }
}
Also used : Secret(org.platformlayer.core.model.Secret) Field(java.lang.reflect.Field) Generate(org.platformlayer.core.model.Generate) Passwords(org.platformlayer.ops.crypto.Passwords)

Example 2 with Passwords

use of org.platformlayer.ops.crypto.Passwords in project platformlayer by platformlayer.

the class WordpressProvider method beforeCreateItem.

@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
    super.beforeCreateItem(item);
    // TODO: This doesn't feel like the right place for this
    if (item instanceof WordpressService) {
        WordpressService wordpressService = (WordpressService) item;
        Passwords passwords = new Passwords();
        if (Secret.isNullOrEmpty(wordpressService.adminPassword)) {
            wordpressService.adminPassword = passwords.generateRandomPassword(10);
        }
        if (Secret.isNullOrEmpty(wordpressService.databasePassword)) {
            wordpressService.databasePassword = passwords.generateRandomPassword(20);
        }
        if (Secret.isNullOrEmpty(wordpressService.wordpressSecretKey)) {
            wordpressService.wordpressSecretKey = passwords.generateRandomPassword(50);
        }
    }
}
Also used : Passwords(org.platformlayer.ops.crypto.Passwords) WordpressService(org.platformlayer.service.wordpress.model.WordpressService)

Example 3 with Passwords

use of org.platformlayer.ops.crypto.Passwords in project platformlayer by platformlayer.

the class OpenLdapProvider method beforeCreateItem.

@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
    super.beforeCreateItem(item);
    // TODO: This doesn't feel like the right place for this
    if (item instanceof LdapService) {
        LdapService ldapService = (LdapService) item;
        Passwords passwords = new Passwords();
        if (Secret.isNullOrEmpty(ldapService.ldapServerPassword)) {
            ldapService.ldapServerPassword = passwords.generateRandomPassword(12);
        }
    }
    if (item instanceof LdapDomain) {
        LdapDomain ldapService = (LdapDomain) item;
        Passwords passwords = new Passwords();
        if (Secret.isNullOrEmpty(ldapService.adminPassword)) {
            ldapService.adminPassword = passwords.generateRandomPassword(12);
        }
    }
}
Also used : LdapDomain(org.platformlayer.service.openldap.model.LdapDomain) Passwords(org.platformlayer.ops.crypto.Passwords) LdapService(org.platformlayer.service.openldap.model.LdapService)

Example 4 with Passwords

use of org.platformlayer.ops.crypto.Passwords in project platformlayer by platformlayer.

the class MysqlProvider method beforeCreateItem.

@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
    super.beforeCreateItem(item);
    // TODO: This doesn't feel like the right place for this
    if (item instanceof MysqlServer) {
        MysqlServer mysqlServer = (MysqlServer) item;
        Passwords passwords = new Passwords();
        if (Secret.isNullOrEmpty(mysqlServer.rootPassword)) {
            mysqlServer.rootPassword = passwords.generateRandomPassword(12);
        }
    }
}
Also used : Passwords(org.platformlayer.ops.crypto.Passwords) MysqlServer(org.platformlayer.service.mysql.model.MysqlServer)

Aggregations

Passwords (org.platformlayer.ops.crypto.Passwords)4 Field (java.lang.reflect.Field)1 Generate (org.platformlayer.core.model.Generate)1 Secret (org.platformlayer.core.model.Secret)1 MysqlServer (org.platformlayer.service.mysql.model.MysqlServer)1 LdapDomain (org.platformlayer.service.openldap.model.LdapDomain)1 LdapService (org.platformlayer.service.openldap.model.LdapService)1 WordpressService (org.platformlayer.service.wordpress.model.WordpressService)1