use of com.tremolosecurity.provisioning.util.EncryptedMessage in project OpenUnison by TremoloSecurity.
the class SetRandomPassword method doTask.
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
String password = new BigInteger(130, random).toString(32);
try {
// remove {myvd}
password = PBKDF2.generateHash(password).substring(7);
} catch (InvalidKeyException | NoSuchAlgorithmException | UnsupportedEncodingException e) {
throw new ProvisioningException("Could not generate password", e);
}
SecretKey key = this.cfgMgr.getSecretKey(this.encryptionKey);
if (key == null) {
throw new ProvisioningException("Encryption key not found");
}
EncryptedMessage msg = new EncryptedMessage();
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key);
msg.setMsg(cipher.doFinal(password.getBytes("UTF-8")));
msg.setIv(cipher.getIV());
Gson gson = new Gson();
String json = gson.toJson(msg);
user.setPassword(password);
user.getAttribs().put(this.attributeName, new Attribute(this.attributeName, json));
} catch (Throwable t) {
throw new ProvisioningException("Could not generate random password", t);
}
return true;
}
use of com.tremolosecurity.provisioning.util.EncryptedMessage in project OpenUnison by TremoloSecurity.
the class AutoFail method execute.
@Override
public void execute(ConfigManager configManager, JobExecutionContext context) throws ProvisioningException {
if (configManager == null || configManager.getProvisioningEngine() == null) {
logger.warn("System not fully initialized");
return;
}
String queueName = context.getJobDetail().getJobDataMap().getString("queueName");
String approver = context.getJobDetail().getJobDataMap().getString("approver");
String msg = context.getJobDetail().getJobDataMap().getString("message");
ApprovalSummaries summaries = ServiceActions.listOpenApprovals(approver, "", configManager);
try {
this.createConnections(configManager, queueName);
Gson gson = new Gson();
for (ApprovalSummary sum : summaries.getApprovals()) {
FailApproval fa = new FailApproval();
fa.setApprovalID(sum.getApproval());
fa.setApprover(approver);
fa.setMsg(msg);
EncryptedMessage em = configManager.getProvisioningEngine().encryptObject(fa);
synchronized (sessionHolder) {
TextMessage tmsg = sessionHolder.getSession().createTextMessage(gson.toJson(em));
tmsg.setStringProperty("JMSXGroupID", "unison-autofail");
sessionHolder.getMessageProduceer().send(tmsg);
}
}
} catch (Throwable t) {
throw new ProvisioningException("Could not process open approvals", t);
}
}
use of com.tremolosecurity.provisioning.util.EncryptedMessage in project OpenUnison by TremoloSecurity.
the class UpdateApprovalAz method execute.
@Override
public void execute(ConfigManager configManager, JobExecutionContext context) throws ProvisioningException {
String queueName = context.getJobDetail().getJobDataMap().getString("queueName");
if (configManager == null || configManager.getProvisioningEngine() == null) {
return;
}
org.hibernate.Session hsession = configManager.getProvisioningEngine().getHibernateSessionFactory().openSession();
try {
this.createConnections(configManager, queueName);
HashMap<Integer, String> approvals = new HashMap<Integer, String>();
// PreparedStatement findOpenApprovals = con.prepareStatement("SELECT id,workflowObj FROM approvals WHERE approved IS NULL");
Query query = hsession.createQuery("FROM Approvals WHERE approved IS NULL");
List<com.tremolosecurity.provisioning.objects.Approvals> approvalObjs = query.list();
for (Approvals aprv : approvalObjs) {
approvals.put(aprv.getId(), aprv.getWorkflowObj());
}
Gson gson = new Gson();
for (int approvalID : approvals.keySet()) {
HashMap<Integer, String> wf = new HashMap<Integer, String>();
wf.put(approvalID, approvals.get(approvalID));
EncryptedMessage em = configManager.getProvisioningEngine().encryptObject(wf);
synchronized (session) {
TextMessage tmsg = session.getSession().createTextMessage(gson.toJson(em));
tmsg.setStringProperty("JMSXGroupID", "unison-updateaz");
session.getMessageProduceer().send(tmsg);
}
}
} catch (Throwable t) {
throw new ProvisioningException("Could not process open approvals", t);
} finally {
if (hsession != null) {
hsession.close();
}
}
}
use of com.tremolosecurity.provisioning.util.EncryptedMessage in project OpenUnison by TremoloSecurity.
the class SendMessageThread method enqueue.
public void enqueue(WorkflowHolder wfHolder) throws ProvisioningException {
TextMessage bm;
try {
JMSSessionHolder session;
String originalQueue;
session = this.getTaskMessageProducer();
bm = session.getSession().createTextMessage();
originalQueue = session.getQueueName();
synchronized (session) {
bm.setStringProperty("OriginalQueue", originalQueue);
bm.setStringProperty("WorkflowName", wfHolder.getWorkflow().getName());
bm.setStringProperty("WorkflowSubject", wfHolder.getUser().getUserID());
bm.setStringProperty("JMSXGroupID", "unison");
bm.setStringProperty("nonce", UUID.randomUUID().toString());
TaskHolder holder = wfHolder.getWfStack().peek();
WorkflowTask task = holder.getParent().get(holder.getPosition());
bm.setStringProperty("WorkflowCurrentTask", task.getLabel());
EncryptedMessage encMsg = this.encryptObject(wfHolder);
String json = JsonWriter.objectToJson(encMsg);
bm.setText(json);
session.getMessageProduceer().send(bm);
}
} catch (Exception e) {
throw new ProvisioningException("Could not enqueue message", e);
}
}
use of com.tremolosecurity.provisioning.util.EncryptedMessage in project OpenUnison by TremoloSecurity.
the class TaskConsumer method onMessage.
@Override
public void onMessage(Message msg) {
try {
TextMessage bmsg = (TextMessage) msg;
if (bmsg.getBooleanProperty("unisonignore")) {
if (logger.isDebugEnabled()) {
logger.debug("ignoring message");
}
bmsg.acknowledge();
return;
}
EncryptedMessage encMsg = (EncryptedMessage) JsonReader.jsonToJava(bmsg.getText());
WorkflowHolder wfHolder = (WorkflowHolder) this.prov.decryptObject(encMsg);
// Re-initialize the workflow
wfHolder.getWorkflow().reInit(cfgMgr);
TaskHolder th = wfHolder.getWfStack().peek();
WorkflowTask task = th.getParent().get(th.getPosition());
th.setPosition(th.getPosition() + 1);
User user = th.getCurrentUser();
if (user == null) {
user = wfHolder.getUser();
}
if (task.doTask(user, wfHolder.getRequest())) {
if (isDone(wfHolder, null)) {
wfHolder.getWorkflow().completeWorkflow();
} else {
((ProvisioningEngineImpl) this.prov).enqueue(wfHolder);
}
} else {
if (isDone(wfHolder, task)) {
wfHolder.getWorkflow().completeWorkflow();
} else {
// do nothing
}
}
msg.acknowledge();
} catch (Throwable t) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter baout = new PrintWriter(baos);
t.printStackTrace(baout);
baout.flush();
baout.close();
StringBuffer b = new StringBuffer();
b.append("Could not execute task\n").append(new String(baos.toByteArray()));
throw new RuntimeException(b.toString(), t);
}
}
Aggregations