Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import fr.insee.sugoi.core.service.ApplicationService;
import fr.insee.sugoi.core.store.StoreProvider;
import fr.insee.sugoi.model.Application;
import fr.insee.sugoi.model.Group;
import fr.insee.sugoi.model.Realm;
import fr.insee.sugoi.model.exceptions.ApplicationNotFoundException;
import fr.insee.sugoi.model.exceptions.RealmNotFoundException;
import fr.insee.sugoi.model.paging.PageResult;
import fr.insee.sugoi.model.paging.PageableResult;
import fr.insee.sugoi.model.paging.SearchType;
import java.util.ArrayList;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -45,6 +47,9 @@ public class ApplicationServiceImpl implements ApplicationService {
public ProviderResponse create(
String realm, Application application, ProviderRequest providerRequest) {
try {
if (application.getGroups() == null) {
application.setGroups(new ArrayList<Group>());
}
ProviderResponse response =
storeProvider.getWriterStore(realm).createApplication(application, providerRequest);
sugoiEventPublisher.publishCustomEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import fr.insee.sugoi.model.User;
import fr.insee.sugoi.model.exceptions.ApplicationNotFoundException;
import fr.insee.sugoi.model.exceptions.GroupAlreadyExistException;
import fr.insee.sugoi.model.exceptions.NoGroupException;
import fr.insee.sugoi.model.exceptions.UserNotFoundException;
import java.io.File;
import java.io.FileWriter;
Expand Down Expand Up @@ -119,6 +120,9 @@ public ProviderResponse deleteGroup(
@Override
public ProviderResponse createGroup(
String appName, Group appGroup, ProviderRequest providerRequest) {
if (appGroup == null) {
throw new NoGroupException("no group provided");
}
fileReaderStore.setResourceLoader(resourceLoader);
Application application =
fileReaderStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.fasterxml.jackson.databind.ObjectMapper;
import fr.insee.sugoi.model.*;
import fr.insee.sugoi.model.exceptions.NoGroupException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -358,6 +360,17 @@ public void testCreateGroup() {
is("Groupy_Applitest"));
}

@Test
public void testCreateGroupWithNoGroup() {
Group group = null;
assertThrows(
NoGroupException.class,
() -> {
fileWriterStore.createGroup("Applitest", group, null);
},
"Should throw NoGroupException");
}

@Test
public void testDeleteGroup() {
Group group = new Group("Asupprimer_WebServicesLdap", "WebServicesLdap");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import fr.insee.sugoi.model.exceptions.GroupAlreadyExistException;
import fr.insee.sugoi.model.exceptions.GroupNotFoundException;
import fr.insee.sugoi.model.exceptions.InvalidPasswordException;
import fr.insee.sugoi.model.exceptions.NoGroupException;
import fr.insee.sugoi.model.exceptions.OrganizationAlreadyExistException;
import fr.insee.sugoi.model.exceptions.OrganizationNotFoundException;
import fr.insee.sugoi.model.exceptions.StoragePolicyNotMetException;
Expand All @@ -61,6 +62,7 @@
import fr.insee.sugoi.model.technics.StoreMapping;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -213,10 +215,17 @@ public ProviderResponse createGroup(
String appName, Group group, ProviderRequest providerRequest) {

try {
if (ldapReaderStore.getApplication(appName).isEmpty()) {
if (group == null) {
throw new NoGroupException("no group provided");
}
Optional<Application> applicationOptional = ldapReaderStore.getApplication(appName);
if (applicationOptional.isEmpty()) {
throw new ApplicationNotFoundException(appName);
}

Application application = applicationOptional.get();
if (application.getGroups() == null) {
application.setGroups(new ArrayList<Group>());
}
if (ldapReaderStore.getGroup(appName, group.getName()).isPresent()) {
throw new GroupAlreadyExistException(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@
package fr.insee.sugoi.ldap;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;

import fr.insee.sugoi.core.configuration.GlobalKeysConfig;
import fr.insee.sugoi.core.model.ProviderRequest;
import fr.insee.sugoi.core.model.ProviderResponse;
import fr.insee.sugoi.core.model.ProviderResponse.ProviderResponseStatus;
import fr.insee.sugoi.ldap.utils.config.LdapConfigKeys;
import fr.insee.sugoi.model.*;
import fr.insee.sugoi.model.Application;
import fr.insee.sugoi.model.Group;
import fr.insee.sugoi.model.Habilitation;
import fr.insee.sugoi.model.Organization;
import fr.insee.sugoi.model.PostalAddress;
import fr.insee.sugoi.model.Realm;
import fr.insee.sugoi.model.User;
import fr.insee.sugoi.model.UserStorage;
import fr.insee.sugoi.model.exceptions.ApplicationNotFoundException;
import fr.insee.sugoi.model.exceptions.InvalidPasswordException;
import fr.insee.sugoi.model.exceptions.NoGroupException;
import fr.insee.sugoi.model.exceptions.StoragePolicyNotMetException;
import fr.insee.sugoi.model.fixtures.StoreMappingFixture;
import fr.insee.sugoi.store.ldap.LdapReaderStore;
Expand Down Expand Up @@ -383,6 +393,17 @@ public void testCreateGroup() {
is("Groupy_Applitest"));
}

@Test
public void testCreateGroupWithNoGroup() {
Group group = null;
assertThrows(
NoGroupException.class,
() -> {
ldapWriterStore.createGroup("Applitest", group, null);
},
"Should throw NoGroupException");
}

@Test
void testCreateGroupApplicationNotFound() {
Group group = new Group();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.insee.sugoi.model.exceptions;

public class NoGroupException extends BadRequestException {

public NoGroupException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}

public NoGroupException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ Feature: Applications scenario
Then the client receives status code 201
Then the client expect to receive an application

Scenario: Post application without group
When the client perform POST request with body on url /realms/domaine1/applications body:
"""
{
"name": "dada",
"groups": null,
"attributes": {
"owner": "Branche privative de l'application applitest"
}
}
"""
And show body received
Then the client receives status code 201
Then the client expect to receive an application

Scenario: Post application alreadyExist
When the client perform POST request with body on url /realms/domaine1/applications body:
"""
Expand Down