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
}
}
}
}
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;
}
Aggregations