Skip to content

Commit

Permalink
Merge pull request #220 from InseeFr/acceptance
Browse files Browse the repository at this point in the history
Acceptance
  • Loading branch information
alicela authored Apr 1, 2022
2 parents 0ef2e3f + 3b37a54 commit 04d2000
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 171 deletions.
4 changes: 4 additions & 0 deletions bauhaus-back-changeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
3.0.18 : - Back :
- Correction de la vulnérabilité Spring https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement
- Changement de gestionnaire de droit (Igesa -> Sugoi)
- Front : Correction de la mise à jour d'un document (fichier physique et RDF peuvent être mis à jour simultanément)
3.0.17 : - Back : Passage à Java 11
- Front : mise à jour des dépendances
- Ajout de la publication d'une nomenclature
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>fr.insee.rmes</groupId>
<artifactId>Bauhaus-BO</artifactId>
<packaging>war</packaging>
<version>3.0.17</version>
<version>3.0.18</version>
<name>Bauhaus-Back-Office</name>
<description>Back-office services for Bauhaus</description>
<url>https://github.com/InseeFr/Bauhaus-Back-Office</url>
Expand Down Expand Up @@ -42,7 +42,7 @@
<jackson.version>2.13.1</jackson.version>
<rdf4j.version>3.7.3</rdf4j.version>
<swagger.core.version>2.1.12</swagger.core.version>
<spring.version>5.3.14</spring.version>
<spring.version>5.3.18</spring.version>
<spring.security.version>5.6.1</spring.security.version>
<log4j2.version>2.17.1</log4j2.version>
<xdocreport.version>2.0.3</xdocreport.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.insee.rmes.bauhaus_services.consutation_gestion;

import fr.insee.rmes.exceptions.RmesException;
import org.json.JSONObject;

public interface ConsultationGestionService {
String getDetailedConcept(String id) throws RmesException;
Expand All @@ -17,5 +18,5 @@ public interface ConsultationGestionService {

String getAllComponents() throws RmesException;

String getComponent(String id) throws RmesException;
JSONObject getComponent(String id) throws RmesException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import java.util.HashMap;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class ConsultationGestionServiceImpl extends RdfService implements ConsultationGestionService {
Expand Down Expand Up @@ -198,7 +196,7 @@ public String getAllComponents() throws RmesException {
}

@Override
public String getComponent(String id) throws RmesException {
public JSONObject getComponent(String id) throws RmesException {
HashMap<String, Object> params = new HashMap<>();
params.put("STRUCTURES_COMPONENTS_GRAPH", Config.STRUCTURES_COMPONENTS_GRAPH);
params.put("CODELIST_GRAPH", Config.CODELIST_GRAPH);
Expand Down Expand Up @@ -289,7 +287,7 @@ public String getComponent(String id) throws RmesException {
}
component.put("format", format);
}
return component.toString();
return component;
}

private void addCloseMatch(JSONObject concept) throws RmesException {
Expand All @@ -315,12 +313,7 @@ private void getStructureComponents(String id, JSONObject structure) throws Rmes
HashMap<String, Object> params = new HashMap<>();
params.put("STRUCTURES_GRAPH", Config.STRUCTURES_GRAPH);
params.put("STRUCTURES_COMPONENTS_GRAPH", Config.STRUCTURES_COMPONENTS_GRAPH);
params.put("CONCEPTS_GRAPH", Config.CONCEPTS_GRAPH);
params.put("CODELIST_GRAPH", Config.CODELIST_GRAPH);

params.put("STRUCTURE_ID", id);
params.put("LG1", Config.LG1);
params.put("LG2", Config.LG2);

JSONArray components = repoGestion.getResponseAsArray(buildRequest("getStructureComponents.ftlh", params));

Expand All @@ -329,45 +322,8 @@ private void getStructureComponents(String id, JSONObject structure) throws Rmes
JSONArray attributes = new JSONArray();

for (int i = 0; i < components.length(); i++) {
JSONObject component = components.getJSONObject(i);
component.put("label", this.formatLabel(component));
component.remove("prefLabelLg1");
component.remove("prefLabelLg2");

if(component.has("attachement")){
component.put("attachement", component.getString("attachement").replace(QB.NAMESPACE, ""));
}
if(component.has("obligatoire")){
component.put("obligatoire", component.getString("obligatoire").equalsIgnoreCase("true") ? "oui": "non");
}
if(component.has("listeCodeUri")){
component.put("representation", "liste de code");

JSONArray codes = getCodes(component.getString("listeCodeNotation"));
JSONObject listCode = new JSONObject();
listCode.put("uri", component.getString("listeCodeUri"));
listCode.put("id", component.getString("listeCodeNotation"));
listCode.put("codes", codes);
component.put("listeCode", listCode);
component.remove("listeCodeUri");
component.remove("listeCodeNotation");
}

if(component.has("conceptUri")){

JSONObject concept = new JSONObject();
concept.put("uri", component.getString("conceptUri"));
concept.put("id", component.getString("conceptId"));
component.put("concept", concept);
component.remove("conceptUri");
component.remove("conceptId");
}

if(component.has("representation")){
component.put("representation", component.getString("representation").replace(IGEO.NAMESPACE, "").replace("http://www.w3.org/2001/XMLSchema#", ""));
}

String idComponent = component.getString("id");
String idComponent = components.getJSONObject(i).getString("id");
JSONObject component = getComponent(idComponent);

if(idComponent.startsWith("a")){
attributes.put(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ private void createRDFForComponent(MutualizedComponent component, Resource resou
else if (component.getRange().equals(XSD.DATETIME.stringValue())) {
RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(PATTERN), component.getPattern(), Config.LG1, model, graph);
}
else if (component.getRange().equals(XSD.INT.stringValue()) || component.getRange().equals(XSD.DOUBLE.stringValue())) {
else if (component.getRange().equals(XSD.INTEGER.stringValue()) || component.getRange().equals(XSD.DOUBLE.stringValue())) {
RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(MIN_LENGTH), component.getMinLength(), Config.LG1, model, graph);
RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(MAX_LENGTH), component.getMaxLength(), Config.LG1, model, graph);
RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("minInclusive"), component.getMinLength(), Config.LG1, model, graph);
RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("maxInclusive"), component.getMaxLength(), Config.LG1, model, graph);
RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("minInclusive"), component.getMinInclusive(), Config.LG1, model, graph);
RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("maxInclusive"), component.getMaxInclusive(), Config.LG1, model, graph);
}
else if (component.getRange().equals(XSD.STRING.stringValue())) {
RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(MIN_LENGTH), component.getMinLength(), Config.LG1, model, graph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

public interface UserRolesManagerService {

public String checkLdapConnexion() throws RmesException ;


public String getAuth(String body);

public String getRoles() throws RmesException;

public String getAgents() throws RmesException;
public String getAgentsSugoi() throws RmesException ;

public void setAddRole(String role, String user);
public void setAddRole(String role, String user) throws RmesException ;

public void setDeleteRole(String roles, String user);
public void setDeleteRole(String roles, String user) throws RmesException;

public String checkSugoiConnexion() throws RmesException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SwaggerConfig(@Context ServletConfig servletConfig) {
super();
OpenAPI openApi = new OpenAPI();

Info info = new Info().title("Bauhaus API").version("3.0.17").description("Rest Endpoints and services Integration used by Bauhaus");
Info info = new Info().title("Bauhaus API").version("3.0.18").description("Rest Endpoints and services Integration used by Bauhaus");
openApi.info(info);

Server server = new Server();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
import java.util.Map;
import java.util.TreeSet;

import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;
Expand Down Expand Up @@ -46,23 +41,15 @@ public class RmesUserRolesManagerImpl implements UserRolesManagerService {
@Autowired
LdapConnexion ldapConnexion;

static final Logger logger = LogManager.getLogger(RmesUserRolesManagerImpl.class);
static final Logger logger = LogManager.getLogger(RmesUserRolesManagerImpl.class);

private static final String IGESA_APP_SEARCH_PATH = "/recherche/application/";
private static final String SUGOI_REALM_SEARCH_PATH = "/realms/";
private static final String SUGOI_APP_SEARCH_PATH = "/applications/";
private static final String SUGOI_SEARCH_APP = Config.SUGOI_URL + SUGOI_REALM_SEARCH_PATH + Config.SUGOI_REALM + SUGOI_APP_SEARCH_PATH + Config.SUGOI_APP ;
private static final String SUGOI_SEARCH_USERS = Config.SUGOI_URL + SUGOI_REALM_SEARCH_PATH + Config.SUGOI_REALM + "/users" ;


private static final String IGESA_ADD_USER_PATH_FMT = Config.IGESA_URL + "/gestion/ajout/personne/application/"
+ Config.IGESA_APP_ID + "/groupe/{1}/utilisateur/{0}";
private static final String IGESA_DELETE_USER_PATH_FMT = Config.IGESA_URL
+ "/gestion/suppression/personne/application/" + Config.IGESA_APP_ID + "/groupe/{1}/utilisateur/{0}";

private static final String ROLE_ID_XPATH = "cn";
private static final String ROLE_PERSON_IDEP_XPATH = "uid";

private static final String SUGOI_ADD_OR_DELETE_USER_PATH_FMT = Config.SUGOI_URL+ "/v2/realms/"+ Config.SUGOI_REALM+SUGOI_APP_SEARCH_PATH+Config.SUGOI_APP+"/groups/{1}/members/{0}";

private Map<String,UserSugoi> mapUsers;

@Override
Expand Down Expand Up @@ -114,53 +101,28 @@ public String getRoles() throws RmesException {
return roles.toString();
}

@Override
public String getAgents() throws RmesException {
TreeSet<JSONObject> agents = new TreeSet<>(new JSONComparator(Constants.LABEL));
logger.info("Connection to LDAP : {}", Config.LDAP_URL);
try {
// Connexion à la racine de l'annuaire
DirContext context = ldapConnexion.getLdapContext();

// Spécification des critères pour la recherche des unités
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
controls.setReturningAttributes(new String[] { ROLE_ID_XPATH,ROLE_PERSON_IDEP_XPATH });
String filter = "(&(objectClass=inseePerson)(!(inseeFonction=Enqueteur de l'INSEE*)))";

// Exécution de la recherche et parcours des résultats
NamingEnumeration<SearchResult> results = context.search("o=insee,c=fr", filter, controls);
while (results.hasMore()) {
SearchResult entree = results.next();
JSONObject jsonO = new JSONObject();
jsonO.put(Constants.LABEL, entree.getAttributes().get(ROLE_ID_XPATH).get().toString());
jsonO.put(Constants.ID, entree.getAttributes().get(ROLE_PERSON_IDEP_XPATH).get().toString());
agents.add(jsonO);
}
context.close();
logger.info("Get agents succeed");
} catch (NamingException e) {
logger.error("Get agents failed : {}", e.getMessage());
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), "Get agents failed");
}
return agents.toString();
}



public String getAgentsSugoi() throws RmesException {
logger.info("get list of agents via Sugoi : {}", SUGOI_SEARCH_USERS);
mapUsers = new HashMap<>(NB_USERS_EXPECTED);


TreeSet<JSONObject> agents = new TreeSet<>(new JSONComparator(Constants.LABEL));

Client client = ClientBuilder.newClient().register(HttpAuthenticationFeature.basic(Config.SUGOI_USER, Config.SUGOI_PASSWORD));
String jsonResponse = client.target(SUGOI_SEARCH_USERS)
.queryParam("size", NB_USERS_EXPECTED)
.request(MediaType.APPLICATION_JSON)
.get(String.class);
logger.info("list of agents in json size {}", jsonResponse.length());

ObjectMapper mapper = new ObjectMapper();
UsersSugoi users;
try {
users = mapper.readValue(jsonResponse, UsersSugoi.class);

for (UserSugoi u : users.getResults()) {
JSONObject jsonUser = new JSONObject();
jsonUser.put(Constants.ID, u.getUsername());
Expand All @@ -171,6 +133,7 @@ public String getAgentsSugoi() throws RmesException {
agents.add(jsonUser);
mapUsers.put(u.getUsername().toLowerCase(), u);
}
logger.info("nb agents : {}", agents.size());
} catch (JsonProcessingException e) {
logger.error("Get agents via Sugoi failed : {}", e.getMessage());
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), "Get agents via Sugoi failed");
Expand All @@ -179,31 +142,17 @@ public String getAgentsSugoi() throws RmesException {
}

@Override
public void setAddRole(String role, String user) {
String url = MessageFormat.format(IGESA_ADD_USER_PATH_FMT, user, role);
Igesa.post(url);
public void setAddRole(String role, String user) throws RmesException{
String url = MessageFormat.format(SUGOI_ADD_OR_DELETE_USER_PATH_FMT, user, role);
Sugoi.put(url);
}

@Override
public void setDeleteRole(String role, String user) {
String url = MessageFormat.format(IGESA_DELETE_USER_PATH_FMT, user, role);
Igesa.post(url);
public void setDeleteRole(String role, String user) throws RmesException {
String url = MessageFormat.format(SUGOI_ADD_OR_DELETE_USER_PATH_FMT, user, role);
Sugoi.delete(url);
}

@Override
public String checkLdapConnexion() throws RmesException {
//IGESA
String xmlResponse ="";
try {
Client client = ClientBuilder.newClient();

xmlResponse = client.target(Config.IGESA_URL + IGESA_APP_SEARCH_PATH + Config.IGESA_APP_ID)
.request(MediaType.APPLICATION_XML).get(String.class);
} catch (Exception e) {
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), "Fail to target IGESA");
}
return StringUtils.isEmpty(xmlResponse)? "KO" : "OK";
}

@Override
public String checkSugoiConnexion() throws RmesException {
Expand Down
Loading

0 comments on commit 04d2000

Please sign in to comment.