diff --git a/Frontend Angular 4/src/app/shared/config.ts b/Frontend Angular 4/src/app/shared/config.ts index e5b48168ac6ac14bb205b1a53d1043eec5ae2f16..08abda3ddc95cf41b1e10497af87f1253201310f 100644 --- a/Frontend Angular 4/src/app/shared/config.ts +++ b/Frontend Angular 4/src/app/shared/config.ts @@ -1,8 +1,8 @@ -//export const SERVER = 'https://matefun.mybluemix.net'; -//export const GHCI_URL = 'wss://matefun.mybluemix.net/endpoint'; +export const SERVER = 'https://matefun.mybluemix.net'; +export const GHCI_URL = 'wss://matefun.mybluemix.net/endpoint'; -export const SERVER = 'http://localhost:9090'; -export const GHCI_URL = 'ws://localhost:9090/endpoint'; +//export const SERVER = 'http://localhost:9090'; +//export const GHCI_URL = 'ws://localhost:9090/endpoint'; //Configuracion dinamica pensando en servidor con ip dinamica //export const SERVER = window.location.protocol + '//' + window.location.host;//'http://localhost:9090'; diff --git a/Servidor JEE/WebContent/WEB-INF/config.json b/Servidor JEE/WebContent/WEB-INF/config.json new file mode 100644 index 0000000000000000000000000000000000000000..18488faeeeaedaea7d791048d1543c72b06fc9e3 --- /dev/null +++ b/Servidor JEE/WebContent/WEB-INF/config.json @@ -0,0 +1,4 @@ +{ + "endpoint":"https://tics.moodlecloud.com", + "group":"Piloto" +} \ No newline at end of file diff --git a/Servidor JEE/WebContent/WEB-INF/lib/json-simple-1.1.1.jar b/Servidor JEE/WebContent/WEB-INF/lib/json-simple-1.1.1.jar new file mode 100644 index 0000000000000000000000000000000000000000..66347a6c86b7d6442358ca7643e4dc484fb01866 Binary files /dev/null and b/Servidor JEE/WebContent/WEB-INF/lib/json-simple-1.1.1.jar differ diff --git a/Servidor JEE/src/main/java/edu/proygrado/ejb/LoginEJB.java b/Servidor JEE/src/main/java/edu/proygrado/ejb/LoginEJB.java index 9e601420f861a44502a671a14e9ebd8c573a3a9e..102cc1387c53a097376500b252e54a3e64ba2321 100644 --- a/Servidor JEE/src/main/java/edu/proygrado/ejb/LoginEJB.java +++ b/Servidor JEE/src/main/java/edu/proygrado/ejb/LoginEJB.java @@ -48,7 +48,25 @@ import edu.proygrado.modelo.Usuario; */ @Stateless public class LoginEJB { - + public static String moodleApiEndpoint = null; + public static String moodleGroup = null; + public LoginEJB() { + super(); + //leo archivo de configuración. + JSONParser parser = new JSONParser(); + try { + String currentPath = System.getProperty("user.dir"); + String configFilePath = currentPath.substring(0,currentPath.length()-4); + configFilePath = configFilePath + "/standalone/deployments/matefun.war/WEB-INF/config.json"; + Object obj = parser.parse(new FileReader(configFilePath)); + JSONObject jsonObject = (JSONObject) obj; + LoginEJB.moodleApiEndpoint = (String) jsonObject.get("endpoint"); + LoginEJB.moodleGroup = (String) jsonObject.get("group"); + } catch (Exception e) { + e.printStackTrace(); + System.out.print("No se ha podido cargar el archivo: /standalone/deployments/matefun.war/WEB-INF/config.json"); + } + } @PersistenceContext(unitName = "matefunDS") private EntityManager em; @@ -98,7 +116,8 @@ public class LoginEJB { Long courseId = null; for (MoodleCourseDTO course : coursesInfo.getEnrolledcourses()) { System.out.println(course.getShortname()); - if (course.getShortname().toLowerCase().equals("piloto")) { + String groupName = LoginEJB.moodleGroup.toLowerCase(); + if (course.getShortname().toLowerCase().equals(groupName)) { courseId = course.getId(); System.out.println(courseId); } @@ -106,7 +125,7 @@ public class LoginEJB { if (courseId != null) { coursesInfo = getCursesInfo(token, userInfo.getUserid(), courseId); } else { - throw new MatefunForbiddenException("Usuario no asignado al curso \"Piloto\" en Moodle"); + throw new MatefunForbiddenException("Usuario no asignado al curso \"" +LoginEJB.moodleGroup +"\" en Moodle"); } String rol = null; @@ -121,7 +140,7 @@ public class LoginEJB { } if (rol == null) { - throw new MatefunForbiddenException("Rol incorrecto en curso \"Piloto\""); + throw new MatefunForbiddenException("Rol incorrecto en curso \"" +LoginEJB.moodleGroup +"\""); } Usuario nuevoDesdeMoodle; @@ -180,7 +199,7 @@ public class LoginEJB { javax.ws.rs.client.Client c = cb.build(); - String url = "https://tics.moodlecloud.com/login/token.php"; + String url = LoginEJB.moodleApiEndpoint + "/login/token.php"; MoodleTokensDTO tokens = null; try { // https://tics.moodlecloud.com/login/token.php @@ -206,8 +225,7 @@ public class LoginEJB { javax.ws.rs.client.ClientBuilder cb = ClientBuilder.newBuilder(); javax.ws.rs.client.Client c = cb.build(); - - String url = "https://tics.moodlecloud.com/webservice/rest/server.php"; + String url = LoginEJB.moodleApiEndpoint + "/webservice/rest/server.php"; MoodleUserInfoDTO userInfo = null; try { @@ -234,7 +252,7 @@ public class LoginEJB { private MoodleCoursesInfoDTO getCursesInfo(String token, Long userId, Long courseId) throws MatefunException { javax.ws.rs.client.ClientBuilder cb = ClientBuilder.newBuilder(); javax.ws.rs.client.Client c = cb.build(); - String url = "https://tics.moodlecloud.com/webservice/rest/server.php"; + String url = LoginEJB.moodleApiEndpoint+ "/webservice/rest/server.php"; List<MoodleCoursesInfoDTO> coursesInfo = null; try {