Hi, Andrea!
Thank you!

1) Connection
https://gyazo.com/d25aca2f48287371177d5c6213f7b9f1

>>please add a mapping for the USER password in the (flag the field as 
>>password attribute). 

2) Resource - User provision
https://gyazo.com/3e9edde7a20ac748964a0538c3d7af76

>>Moreover assign DBPasswordPropagationActions to the resource sued to 
>>propagate users. Then you should find "password" variable populated in 
>>the groovy scripts. 

3) Resource
https://gyazo.com/2a4f2df6abc89ffbddef49d1dcb075ec?token=7190100397f6510ddc166361f95eba43

4) ActivitiCreateScript.groovy:

log.info("Entering " + action + " Script");
def sql = new Sql(connection);

switch (objectClass) {
    case "__ACCOUNT__":
        def storeUsers = sql.rows("SELECT ID_ FROM act_id_user WHERE ID_=
?", [id])
        if (storeUsers.size() == 0) {
            log.info("Create new user. Attributes: " + attributes);

            def firstnameAttributes = attributes.get("FIRST_");
            def lastnameAttributes = attributes.get("LAST_");
            def emailAttributes = attributes.get("EMAIL_");
            //def passwordAttributes = attributes.get("PASSWORD");

            sql.execute("INSERT INTO act_id_user
(ID_,REV_,FIRST_,LAST_,EMAIL_,PWD_) values (?,?,?,?,?,?)",
                    [
                            id,
                            1,
                            firstnameAttributes.isEmpty() ? null :
firstnameAttributes.get(0),
                            lastnameAttributes.isEmpty() ? null :
lastnameAttributes.get(0),
                            emailAttributes.isEmpty() ? null :
emailAttributes.get(0),
                            //passwordAttributes.isEmpty() ? null :
passwordAttributes.get(0)
                            password
                    ]);
        } else {
            def logMessage = "Exists user. ID_: " + id;
            log.info(logMessage);
            throw new Exception(logMessage);
        }
        break

    case "__GROUP__":
        def storeGroups = sql.rows("SELECT ID_ FROM act_id_group WHERE ID_=
?", [id])
        if (storeGroups.size() == 0) {
            log.info("Create new group. Attributes: " + attributes);
            def nameAttributes = attributes.get("NAME_");
            def typeAttributes = attributes.get("TYPE_");

            sql.execute("INSERT INTO act_id_group (ID_,REV_,NAME_,TYPE_)
values (?,?,?,?)",
                    [
                            id,
                            1,
                            nameAttributes.isEmpty() ? null :
nameAttributes.get(0),
                            typeAttributes.isEmpty() ? null :
typeAttributes.get(0)
                    ]);
        } else {
            def logMessage = "Exists group. ID_: " + id;
            log.info(logMessage);
            throw new Exception(logMessage);
        }
        break

    default:
        id;
}
return id;

5) Result of push:

https://gyazo.com/8850d539a0111e3bff3f1eb329551eb8

PWD_ = null    :(


I created:

public class MyDBPasswordPropagationActions implements PropagationActions {

    private static final String PASSWORD_NAME = "PASSWORD";

    @Autowired
    private UserDAO userDAO;

    @Transactional(readOnly = true)
    @Override
    public void before(final PropagationTask task, final ConnectorObject
beforeObj) {
        if (AnyTypeKind.USER == task.getAnyTypeKind()) {
            User user = userDAO.find(task.getEntityKey());
            if (user != null && user.getPassword() != null &&
user.getCipherAlgorithm() != null) {
                Attribute passwordAttribute =
AttributeBuilder.build(PASSWORD_NAME, user.getPassword());
                Set<Attribute> attributes = new
HashSet<>(task.getAttributes());
                attributes.add(passwordAttribute);
                task.setAttributes(attributes);
            }
        }
    }
}

and get password:

def passwordAttributes = attributes.get("PASSWORD");

It works...  :)

Best regards,
Dmitry


--
Sent from: http://syncope-user.1051894.n5.nabble.com/

Reply via email to