"El primer paso para llegar a cualquier parte es decidir que no te vas a quedar donde estás.... da tu primer paso hoy no importa que no veas el camino......"
domingo, 28 de julio de 2013
Recuperar Usuarios de Bonita
package ec.users;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.security.auth.login.LoginContext;
import org.ow2.bonita.facade.IdentityAPI;
import org.ow2.bonita.facade.ManagementAPI;
import org.ow2.bonita.facade.QueryRuntimeAPI;
import org.ow2.bonita.facade.RuntimeAPI;
import org.ow2.bonita.facade.identity.Group;
import org.ow2.bonita.facade.identity.Role;
import org.ow2.bonita.facade.identity.User;
import org.ow2.bonita.facade.runtime.ActivityState;
import org.ow2.bonita.facade.uuid.ActivityInstanceUUID;
import org.ow2.bonita.facade.uuid.ProcessDefinitionUUID;
import org.ow2.bonita.facade.uuid.ProcessInstanceUUID;
import org.ow2.bonita.util.AccessorUtil;
import org.ow2.bonita.util.BonitaConstants;
import org.ow2.bonita.util.SimpleCallbackHandler;
/**
* Method that get a simple list for users
*
* @author netdaemon
*
*/
public class ObtenerUsuario {
private static final String LOGIN = "admin";
private static final String PSSWD = "bpm";
private static final String jaasFile = "/home/netdaemon/BOS-SP-5.6.1-Tomcat-6.0.33/external/security/jaas-tomcat.cfg";
public static void main(String[] args) throws Exception {
// set system properties
System.setProperty(BonitaConstants.API_TYPE_PROPERTY, "REST");
System.setProperty(BonitaConstants.REST_SERVER_ADDRESS_PROPERTY,"http://localhost:9080/bonita-server-rest/");
System.setProperty(BonitaConstants.JAAS_PROPERTY, jaasFile);
// login
LoginContext loginContext = new LoginContext("BonitaAuth",new SimpleCallbackHandler(LOGIN, PSSWD));
loginContext.login();
loginContext.logout();
// propagate the user credentials
loginContext = new LoginContext("BonitaStore",new SimpleCallbackHandler(LOGIN, PSSWD));
loginContext.login();
// get he APIs
final IdentityAPI identityAPI = AccessorUtil.getIdentityAPI();
try {
//Recuperar usuarios por role
Role role = identityAPI.findRoleByName("secretario");
List<User> users = identityAPI.getAllUsersInRole(role.getUUID());
for (User usr : users) {
System.out.println("" + usr.getFirstName() + " " + usr.getLastName());
System.out.println("" + usr.getTitle());
}
//Recuperar usuarios por Grupo
Group group = identityAPI.getGroupByUUID("e8194c31-42d6-4a3b-83b2-b1456b63d74a");
List <User> usuarios = identityAPI.getAllUsersInGroup(group.getUUID());
for (User usr : usuarios) {
System.out.println("" + usr.getFirstName() + " " + usr.getLastName());
System.out.println("" + usr.getJobTitle());
}
List <String> firmantes1 = new ArrayList<String>();
//Recuperar lista de delegados y directores
Role role1 = identityAPI.findRoleByName("delegadoDN");
List<User> users1 = identityAPI.getAllUsersInRole(role1.getUUID());
for (User usr : users1) {
// System.out.println("" + usr.getFirstName() + " " + usr.getLastName());
// System.out.println("" + usr.getJobTitle());
firmantes1.add(usr.getLastName() + " " + usr.getFirstName());
}
Role role2 = identityAPI.findRoleByName("directorNacional");
List<User> users2 = identityAPI.getAllUsersInRole(role2.getUUID());
for (User usr : users2) {
// System.out.println("" + usr.getFirstName() + " " + usr.getLastName());
// System.out.println("" + usr.getJobTitle());
firmantes1.add(usr.getLastName() + " " + usr.getFirstName());
}
for ( String nombre : firmantes1 ){
System.out.println(nombre);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
loginContext.logout();
}
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.security.auth.login.LoginContext;
import org.ow2.bonita.facade.IdentityAPI;
import org.ow2.bonita.facade.ManagementAPI;
import org.ow2.bonita.facade.QueryRuntimeAPI;
import org.ow2.bonita.facade.RuntimeAPI;
import org.ow2.bonita.facade.identity.Group;
import org.ow2.bonita.facade.identity.Role;
import org.ow2.bonita.facade.identity.User;
import org.ow2.bonita.facade.runtime.ActivityState;
import org.ow2.bonita.facade.uuid.ActivityInstanceUUID;
import org.ow2.bonita.facade.uuid.ProcessDefinitionUUID;
import org.ow2.bonita.facade.uuid.ProcessInstanceUUID;
import org.ow2.bonita.util.AccessorUtil;
import org.ow2.bonita.util.BonitaConstants;
import org.ow2.bonita.util.SimpleCallbackHandler;
/**
* Method that get a simple list for users
*
* @author netdaemon
*
*/
public class ObtenerUsuario {
private static final String LOGIN = "admin";
private static final String PSSWD = "bpm";
private static final String jaasFile = "/home/netdaemon/BOS-SP-5.6.1-Tomcat-6.0.33/external/security/jaas-tomcat.cfg";
public static void main(String[] args) throws Exception {
// set system properties
System.setProperty(BonitaConstants.API_TYPE_PROPERTY, "REST");
System.setProperty(BonitaConstants.REST_SERVER_ADDRESS_PROPERTY,"http://localhost:9080/bonita-server-rest/");
System.setProperty(BonitaConstants.JAAS_PROPERTY, jaasFile);
// login
LoginContext loginContext = new LoginContext("BonitaAuth",new SimpleCallbackHandler(LOGIN, PSSWD));
loginContext.login();
loginContext.logout();
// propagate the user credentials
loginContext = new LoginContext("BonitaStore",new SimpleCallbackHandler(LOGIN, PSSWD));
loginContext.login();
// get he APIs
final IdentityAPI identityAPI = AccessorUtil.getIdentityAPI();
try {
//Recuperar usuarios por role
Role role = identityAPI.findRoleByName("secretario");
List<User> users = identityAPI.getAllUsersInRole(role.getUUID());
for (User usr : users) {
System.out.println("" + usr.getFirstName() + " " + usr.getLastName());
System.out.println("" + usr.getTitle());
}
//Recuperar usuarios por Grupo
Group group = identityAPI.getGroupByUUID("e8194c31-42d6-4a3b-83b2-b1456b63d74a");
List <User> usuarios = identityAPI.getAllUsersInGroup(group.getUUID());
for (User usr : usuarios) {
System.out.println("" + usr.getFirstName() + " " + usr.getLastName());
System.out.println("" + usr.getJobTitle());
}
List <String> firmantes1 = new ArrayList<String>();
//Recuperar lista de delegados y directores
Role role1 = identityAPI.findRoleByName("delegadoDN");
List<User> users1 = identityAPI.getAllUsersInRole(role1.getUUID());
for (User usr : users1) {
// System.out.println("" + usr.getFirstName() + " " + usr.getLastName());
// System.out.println("" + usr.getJobTitle());
firmantes1.add(usr.getLastName() + " " + usr.getFirstName());
}
Role role2 = identityAPI.findRoleByName("directorNacional");
List<User> users2 = identityAPI.getAllUsersInRole(role2.getUUID());
for (User usr : users2) {
// System.out.println("" + usr.getFirstName() + " " + usr.getLastName());
// System.out.println("" + usr.getJobTitle());
firmantes1.add(usr.getLastName() + " " + usr.getFirstName());
}
for ( String nombre : firmantes1 ){
System.out.println(nombre);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
loginContext.logout();
}
}
}
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario