Search in sources :

Example 1 with UserStoreProvider

use of com.tremolosecurity.provisioning.core.UserStoreProvider in project OpenUnison by TremoloSecurity.

the class Drupal7GetSequence method doTask.

@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Searching for users.id");
            logger.debug("Looking for user : '" + user.getUserID() + "'");
        }
        User looking = task.getConfigManager().getProvisioningEngine().getTarget(this.targetName).findUser(user.getUserID(), new HashMap<String, Object>());
        if (logger.isDebugEnabled()) {
            logger.debug("User object : '" + looking + "'");
        }
        if (looking == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("User not found");
            }
        }
        if (looking != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("User found, setting to user id : '" + looking.getAttribs().get("uid").getValues().get(0) + "'");
            }
            user.getAttribs().put("drupalid", new Attribute("drupalid", looking.getAttribs().get("uid").getValues().get(0)));
            return true;
        }
    } catch (ProvisioningException pe) {
        // do nothing
        pe.printStackTrace();
    }
    UserStoreProvider provider = task.getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
    BasicDBInterface dbprovider = (BasicDBInterface) provider;
    Connection con = null;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Getting Connection");
        }
        con = dbprovider.getDS().getConnection();
        if (logger.isDebugEnabled()) {
            logger.debug("Preparing Statement");
        }
        PreparedStatement ps = con.prepareStatement("INSERT INTO sequences () VALUES ()", Statement.RETURN_GENERATED_KEYS);
        if (logger.isDebugEnabled()) {
            logger.debug("Executing Statement");
        }
        ps.executeUpdate();
        if (logger.isDebugEnabled()) {
            logger.debug("Getting key");
        }
        ResultSet rs = ps.getGeneratedKeys();
        rs.next();
        int id = rs.getInt(1);
        if (logger.isDebugEnabled()) {
            logger.debug("ID: '" + id + "'");
        }
        rs.close();
        ps.close();
        user.getAttribs().put("drupalid", new Attribute("drupalid", Integer.toString(id)));
        return true;
    } catch (SQLException e) {
        throw new ProvisioningException("Could not generate userid", e);
    } finally {
        if (con != null) {
            try {
                logger.info("Closing connection");
                con.close();
            } catch (Exception e1) {
            // do nothing
            }
        }
    }
}
Also used : User(com.tremolosecurity.provisioning.core.User) Attribute(com.tremolosecurity.saml.Attribute) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) BasicDBInterface(com.tremolosecurity.provisioning.core.providers.BasicDBInterface) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) SQLException(java.sql.SQLException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ResultSet(java.sql.ResultSet) UserStoreProvider(com.tremolosecurity.provisioning.core.UserStoreProvider)

Example 2 with UserStoreProvider

use of com.tremolosecurity.provisioning.core.UserStoreProvider in project OpenUnison by TremoloSecurity.

the class AddGroupToStore method doTask.

@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
    UserStoreProvider target = task.getConfigManager().getProvisioningEngine().getTarget(this.target).getProvider();
    if (target instanceof UserStoreProviderWithAddGroup) {
        request.put("WORKFLOW", this.task.getWorkflow());
        Map<String, String> localAttrs = new HashMap<String, String>();
        localAttrs.putAll(attributes);
        for (String key : localAttrs.keySet()) {
            localAttrs.put(key, task.renderTemplate(localAttrs.get(key), request));
        }
        for (String name : names) {
            if (!((UserStoreProviderWithAddGroup) target).isGroupExists(task.renderTemplate(name, request), user, request)) {
                ((UserStoreProviderWithAddGroup) target).addGroup(task.renderTemplate(name, request), localAttrs, user, request);
            }
        }
    } else {
        logger.warn("Target '" + this.target + "' can not add groups");
    }
    return true;
}
Also used : HashMap(java.util.HashMap) UserStoreProviderWithAddGroup(com.tremolosecurity.provisioning.core.UserStoreProviderWithAddGroup) UserStoreProvider(com.tremolosecurity.provisioning.core.UserStoreProvider)

Aggregations

UserStoreProvider (com.tremolosecurity.provisioning.core.UserStoreProvider)2 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 User (com.tremolosecurity.provisioning.core.User)1 UserStoreProviderWithAddGroup (com.tremolosecurity.provisioning.core.UserStoreProviderWithAddGroup)1 BasicDBInterface (com.tremolosecurity.provisioning.core.providers.BasicDBInterface)1 Attribute (com.tremolosecurity.saml.Attribute)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1