From bfd4efb41c48705afe4eea1fdc914743b4511e80 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 00:52:01 +0100 Subject: [PATCH 01/24] Changed model --- .../controller/ExampleEntityController.java | 107 ----------------- .../entity/controller/package-info.java | 29 ----- .../domain/entity/model/DtoExampleEntity.java | 42 ------- .../entity/model/PersistentExampleEntity.java | 72 ------------ .../domain/entity/model/package-info.java | 31 ----- .../repository/ExampleEntityRepository.java | 53 --------- .../persistence/repository/package-info.java | 31 ----- .../service/DefaultExampleEntityService.java | 111 ------------------ .../entity/service/ExampleEntityService.java | 80 ------------- .../domain/entity/service/package-info.java | 32 ----- .../PlaceholderPersonRepository.java | 38 ++++++ .../rest/controller/PersonController.java} | 56 ++++----- .../ws/basic/person/domain/model/Person.java | 6 + .../domain/repository/PersonRepository.java | 12 ++ .../usecase/service/DefaultPersonService.java | 33 ++++++ .../person/usecase/service/PersonService.java | 12 ++ 16 files changed, 125 insertions(+), 620 deletions(-) delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/controller/ExampleEntityController.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/controller/package-info.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/DtoExampleEntity.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/PersistentExampleEntity.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/package-info.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/persistence/repository/ExampleEntityRepository.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/persistence/repository/package-info.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/DefaultExampleEntityService.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/ExampleEntityService.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/package-info.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{domain/entity/model/ExampleEntity.java => person/adapter/outbound/rest/controller/PersonController.java} (55%) create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/controller/ExampleEntityController.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/controller/ExampleEntityController.java deleted file mode 100644 index b43a2a4..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/controller/ExampleEntityController.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.controller; - -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.bernardomg.example.spring.security.ws.basic.domain.entity.model.ExampleEntity; -import com.bernardomg.example.spring.security.ws.basic.domain.entity.service.ExampleEntityService; - -import lombok.AllArgsConstructor; -import lombok.NonNull; - -/** - * Rest controller for the example entities. - * - * @author Bernardo Martínez Garrido - */ -@RestController -@RequestMapping("/rest/entity") -@AllArgsConstructor -public class ExampleEntityController { - - /** - * Example entity service. - */ - @NonNull - private final ExampleEntityService exampleEntityService; - - /** - * Creates an entity. - * - * @param entity - * entity to create - * @return the created entity - */ - @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) - public ExampleEntity create(final ExampleEntity entity) { - return exampleEntityService.create(entity); - } - - /** - * Deletes the entity for the received id. - * - * @param id - * id of the entity to delete - * @return {@code true} if it was deleted, {@code false} otherwise - */ - @DeleteMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public Boolean delete(@PathVariable("id") final Long id) { - return exampleEntityService.delete(id); - } - - /** - * Returns all the entities. - * - * @return all the entities - */ - @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) - public Iterable read() { - return exampleEntityService.getAll(); - } - - /** - * Updates the entity for the received id. - * - * @param id - * entity id - * @param entity - * new entity data - * @return the updated entity - */ - @PutMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public ExampleEntity update(@PathVariable("id") final Long id, @RequestBody final ExampleEntity entity) { - return exampleEntityService.update(id, entity); - } - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/controller/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/controller/package-info.java deleted file mode 100644 index 9fecfb8..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/controller/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/** - * Controller classes. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.controller; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/DtoExampleEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/DtoExampleEntity.java deleted file mode 100644 index 7c6875a..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/DtoExampleEntity.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.model; - -import lombok.Data; - -@Data -public final class DtoExampleEntity implements ExampleEntity { - - /** - * Entity id. - */ - private Long id; - - /** - * Entity name. - */ - private String name; - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/PersistentExampleEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/PersistentExampleEntity.java deleted file mode 100644 index b9f87e1..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/PersistentExampleEntity.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.model; - -import java.io.Serializable; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import jakarta.persistence.Transient; -import lombok.Data; - -/** - * Persistent entity for the example application. - *

- * This makes use of JPA annotations for the persistence configuration. - * - * @author Bernardo Martínez Garrido - */ -@Entity(name = "ExampleEntity") -@Table(name = "example_entities") -@Data -public class PersistentExampleEntity implements Serializable { - - /** - * Serialization ID. - */ - @Transient - private static final long serialVersionUID = 1328776989450853491L; - - /** - * Entity's ID. - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false, unique = true) - private Long id = -1L; - - /** - * Name of the entity. - *

- * This is to have additional data apart from the id, to be used on the tests. - */ - @Column(name = "name", nullable = false, unique = true) - private String name = ""; - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/package-info.java deleted file mode 100644 index 85990d5..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/package-info.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/** - * Model classes. - *

- * These represent the main sets of data which the application works with. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/persistence/repository/ExampleEntityRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/persistence/repository/ExampleEntityRepository.java deleted file mode 100644 index 2723b87..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/persistence/repository/ExampleEntityRepository.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.persistence.repository; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; - -import com.bernardomg.example.spring.security.ws.basic.domain.entity.model.PersistentExampleEntity; - -/** - * Spring-JPA repository for {@link PersistentExampleEntity}. - *

- * This is a simple repository just to allow the endpoints querying the entities they are asked for. - * - * @author Bernardo Martínez Garrido - */ -public interface ExampleEntityRepository extends JpaRepository { - - /** - * Returns all entities with a partial match to the name. - * - * @param name - * name for searching - * @param page - * pagination to apply - * @return all entities at least partially matching the name - */ - public Page findByNameContaining(final String name, final Pageable page); - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/persistence/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/persistence/repository/package-info.java deleted file mode 100644 index 2a0470d..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/persistence/repository/package-info.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -/** - * Repositories. - *

- * Similar to a DAO, a repository is a pattern which allows handling the persistence layer as if it was a collection, - * where entities are stored and read from. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.persistence.repository; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/DefaultExampleEntityService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/DefaultExampleEntityService.java deleted file mode 100644 index 6a925e5..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/DefaultExampleEntityService.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.service; - -import java.util.stream.Collectors; - -import org.springframework.stereotype.Service; - -import com.bernardomg.example.spring.security.ws.basic.domain.entity.model.DtoExampleEntity; -import com.bernardomg.example.spring.security.ws.basic.domain.entity.model.ExampleEntity; -import com.bernardomg.example.spring.security.ws.basic.domain.entity.model.PersistentExampleEntity; -import com.bernardomg.example.spring.security.ws.basic.domain.entity.persistence.repository.ExampleEntityRepository; - -import lombok.AllArgsConstructor; - -/** - * Default implementation of the example entity service. - * - * @author Bernardo Martínez Garrido - */ -@Service -@AllArgsConstructor -public final class DefaultExampleEntityService implements ExampleEntityService { - - /** - * Repository for the domain entities handled by the service. - */ - private final ExampleEntityRepository entityRepository; - - @Override - public final ExampleEntity create(final ExampleEntity data) { - final PersistentExampleEntity entity; - final PersistentExampleEntity saved; - - entity = toEntity(data); - - saved = entityRepository.save(entity); - - return toDto(saved); - } - - @Override - public final Boolean delete(final Long id) { - entityRepository.deleteById(id); - - return true; - } - - @Override - public final Iterable getAll() { - return entityRepository.findAll() - .stream() - .map(this::toDto) - .collect(Collectors.toList()); - } - - @Override - public final ExampleEntity update(final Long id, final ExampleEntity data) { - final PersistentExampleEntity entity; - final PersistentExampleEntity saved; - - entity = toEntity(data); - - saved = entityRepository.save(entity); - - return toDto(saved); - } - - private final ExampleEntity toDto(final PersistentExampleEntity data) { - final DtoExampleEntity dto; - - dto = new DtoExampleEntity(); - dto.setId(data.getId()); - dto.setName(data.getName()); - - return dto; - } - - private final PersistentExampleEntity toEntity(final ExampleEntity data) { - final PersistentExampleEntity entity; - - entity = new PersistentExampleEntity(); - entity.setId(data.getId()); - entity.setName(data.getName()); - - return entity; - } - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/ExampleEntityService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/ExampleEntityService.java deleted file mode 100644 index 75cc194..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/ExampleEntityService.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.service; - -import org.springframework.security.access.prepost.PreAuthorize; - -import com.bernardomg.example.spring.security.ws.basic.domain.entity.model.ExampleEntity; - -/** - * Service for the example entity domain. - *

- * This is a domain service just to allow the endpoints querying the entities they are asked for. - * - * @author Bernardo Martínez Garrido - */ -public interface ExampleEntityService { - - /** - * Creates the received entity. - * - * @param entity - * entity to create - * @return the entity created - */ - @PreAuthorize("hasAuthority('CREATE_DATA')") - public ExampleEntity create(final ExampleEntity entity); - - /** - * Deletes the entity for the received id. - * - * @param id - * entity id - * @return {@code true} if it was deleted, {@code false} otherwise - */ - @PreAuthorize("hasAuthority('DELETE_DATA')") - public Boolean delete(final Long id); - - /** - * Returns all the entities. - * - * @return all the entities - */ - @PreAuthorize("hasAuthority('READ_DATA')") - public Iterable getAll(); - - /** - * Updates the entity for the received id. - * - * @param id - * entity id - * @param entity - * new entity data - * @return the updated entity - */ - @PreAuthorize("hasAuthority('UPDATE_DATA')") - public ExampleEntity update(final Long id, final ExampleEntity entity); - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/package-info.java deleted file mode 100644 index 0792da5..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/service/package-info.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/** - * Services. - *

- * While in the MVC architecture all the logic seems to be contained inside the controllers, using an additional layer - * of services helps to isolate all the important logic in the application. - */ - -package com.bernardomg.example.spring.security.ws.basic.domain.entity.service; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java new file mode 100644 index 0000000..d99521b --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java @@ -0,0 +1,38 @@ + +package com.bernardomg.example.spring.security.ws.basic.person.adapter.inbound.placeholder.repository; + +import java.util.Collection; +import java.util.List; + +import org.springframework.stereotype.Repository; + +import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; +import com.bernardomg.example.spring.security.ws.basic.person.domain.repository.PersonRepository; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Repository +public final class PlaceholderPersonRepository implements PersonRepository { + + public PlaceholderPersonRepository() { + super(); + } + + @Override + public final Collection findAll() { + final Person person; + final Collection persons; + + log.debug("Finding all the persons"); + + person = new Person("id", "Name", "Surname"); + + persons = List.of(person); + + log.debug("Found all the persons: {}", persons); + + return persons; + } + +} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/ExampleEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java similarity index 55% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/ExampleEntity.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java index a1fe865..491e275 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/domain/entity/model/ExampleEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2023 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,45 +22,37 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.domain.entity.model; +package com.bernardomg.example.spring.security.ws.basic.person.adapter.outbound.rest.controller; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; +import com.bernardomg.example.spring.security.ws.basic.person.usecase.service.PersonService; + +import lombok.AllArgsConstructor; /** - * A simple entity to be used as an example. + * Person REST controller. * * @author Bernardo Martínez Garrido + * */ -public interface ExampleEntity { - - /** - * Returns the identifier assigned to this entity. - *

- * If no identifier has been assigned yet, then the value is expected to be {@code null} or lower than zero. - * - * @return the entity's identifier - */ - public Long getId(); - - /** - * Returns the name of the entity. - * - * @return the entity's name - */ - public String getName(); +@RestController +@RequestMapping("/rest/person") +@AllArgsConstructor +public class PersonController { /** - * Sets the identifier assigned to this entity. - * - * @param identifier - * the identifier for the entity + * Person service. */ - public void setId(final Long identifier); + private final PersonService service; - /** - * Changes the name of the entity. - * - * @param name - * the name to set on the entity - */ - public void setName(final String name); + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public Iterable readAll() { + return service.getAll(); + } } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java new file mode 100644 index 0000000..752c52d --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java @@ -0,0 +1,6 @@ + +package com.bernardomg.example.spring.security.ws.basic.person.domain.model; + +public record Person(String id, String name, String surname) { + +} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java new file mode 100644 index 0000000..9ad4d49 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java @@ -0,0 +1,12 @@ + +package com.bernardomg.example.spring.security.ws.basic.person.domain.repository; + +import java.util.Collection; + +import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; + +public interface PersonRepository { + + public Collection findAll(); + +} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java new file mode 100644 index 0000000..d8e1ea7 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java @@ -0,0 +1,33 @@ + +package com.bernardomg.example.spring.security.ws.basic.person.usecase.service; + +import java.util.Collection; +import java.util.Objects; + +import org.springframework.stereotype.Service; + +import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; +import com.bernardomg.example.spring.security.ws.basic.person.domain.repository.PersonRepository; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public final class DefaultPersonService implements PersonService { + + private final PersonRepository personRepository; + + public DefaultPersonService(final PersonRepository personRepo) { + super(); + + personRepository = Objects.requireNonNull(personRepo); + } + + @Override + public final Collection getAll() { + log.debug("Reading all persons"); + + return personRepository.findAll(); + } + +} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java new file mode 100644 index 0000000..e2acb22 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java @@ -0,0 +1,12 @@ + +package com.bernardomg.example.spring.security.ws.basic.person.usecase.service; + +import java.util.Collection; + +import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; + +public interface PersonService { + + public Collection getAll(); + +} From 5b2d1bef23383d16b8fc2fee2773c5431c6d3849 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 14:16:35 +0100 Subject: [PATCH 02/24] Removed login --- .../rest/controller/LoginController.java | 66 ----------- .../rest/controller/package-info.java | 29 ----- .../adapter/outbound/rest/model/UserForm.java | 35 ------ .../outbound/rest/model/package-info.java | 29 ----- .../basic/login/domain/model/LoginStatus.java | 35 ------ .../login/domain/model/package-info.java | 29 ----- .../usecase/service/DefaultLoginService.java | 111 ------------------ .../login/usecase/service/LoginService.java | 48 -------- .../login/usecase/service/package-info.java | 29 ----- .../ITLoginControllerSecurity.java | 70 ----------- .../usecase/service/unit/ITLoginService.java | 67 ----------- .../service/unit/ITLoginServiceNoData.java | 34 ------ .../unit/ITLoginServiceNoPrivileges.java | 36 ------ 13 files changed, 618 deletions(-) delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/controller/LoginController.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/controller/package-info.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/model/UserForm.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/model/package-info.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/login/domain/model/LoginStatus.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/login/domain/model/package-info.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/DefaultLoginService.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/LoginService.java delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/package-info.java delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/adapter/outbound/rest/controller/integration/ITLoginControllerSecurity.java delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginService.java delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginServiceNoData.java delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginServiceNoPrivileges.java diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/controller/LoginController.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/controller/LoginController.java deleted file mode 100644 index e3388fd..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/controller/LoginController.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.login.adapter.outbound.rest.controller; - -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.bernardomg.example.spring.security.ws.basic.login.adapter.outbound.rest.model.UserForm; -import com.bernardomg.example.spring.security.ws.basic.login.domain.model.LoginStatus; -import com.bernardomg.example.spring.security.ws.basic.login.usecase.service.LoginService; - -import lombok.AllArgsConstructor; - -/** - * Login controller. Allows a user to log into the application. - * - * @author Bernardo Martínez Garrido - * - */ -@RestController -@RequestMapping("/login") -@AllArgsConstructor -public class LoginController { - - /** - * Login service. - */ - private final LoginService service; - - /** - * Logs in a user. - * - * @param user - * user details - * @return the login status after the login attempt - */ - @PostMapping - public LoginStatus login(@RequestBody final UserForm user) { - return service.login(user.username(), user.password()); - } - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/controller/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/controller/package-info.java deleted file mode 100644 index 3f63cfb..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/controller/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/** - * Login model. - */ - -package com.bernardomg.example.spring.security.ws.basic.login.adapter.outbound.rest.controller; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/model/UserForm.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/model/UserForm.java deleted file mode 100644 index 5cb6c71..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/model/UserForm.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.login.adapter.outbound.rest.model; - -/** - * Contains all the data for a login attempt. - * - * @author Bernardo Martínez Garrido - * - */ -public record UserForm(String username, String password) { - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/model/package-info.java deleted file mode 100644 index b40ef11..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/adapter/outbound/rest/model/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/** - * Login controller model. - */ - -package com.bernardomg.example.spring.security.ws.basic.login.adapter.outbound.rest.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/domain/model/LoginStatus.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/domain/model/LoginStatus.java deleted file mode 100644 index b2857dd..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/domain/model/LoginStatus.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.login.domain.model; - -/** - * Status after a login attempt. - * - * @author Bernardo Martínez Garrido - * - */ -public record LoginStatus(String username, Boolean logged, String token) { - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/domain/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/domain/model/package-info.java deleted file mode 100644 index 9e019fc..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/domain/model/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/** - * Login model. - */ - -package com.bernardomg.example.spring.security.ws.basic.login.domain.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/DefaultLoginService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/DefaultLoginService.java deleted file mode 100644 index 042de60..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/DefaultLoginService.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.login.usecase.service; - -import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.Optional; - -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; - -import com.bernardomg.example.spring.security.ws.basic.login.domain.model.LoginStatus; - -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -/** - * Default implementation of the login service. - * - * @author Bernardo Martínez Garrido - * - */ -@Service -@Slf4j -@AllArgsConstructor -public final class DefaultLoginService implements LoginService { - - /** - * Password encoder, for validating passwords. - */ - private final PasswordEncoder passwordEncoder; - - /** - * User details service, to find and validate users. - */ - private final UserDetailsService userDetailsService; - - @Override - public final LoginStatus login(final String username, final String password) { - final Boolean logged; - final LoginStatus status; - final String token; - Optional details; - - log.debug("Log in attempt for {}", username); - - // Find the user - try { - details = Optional.of(userDetailsService.loadUserByUsername(username)); - } catch (final UsernameNotFoundException e) { - details = Optional.empty(); - } - - // Check if the user is valid - if (details.isEmpty()) { - // No user found for username - log.debug("No user for username {}", username); - logged = false; - } else { - // Validate password - logged = passwordEncoder.matches(password, details.get() - .getPassword()); - if (!logged) { - log.debug("Received password doesn't match the one stored for username {}", username); - } - } - - // Generate token - token = generateToken(username, password); - - status = new LoginStatus(username, logged, token); - - log.debug("Finished log in attempt for {}. Logged in: {}", username, logged); - - return status; - } - - private final String generateToken(final String username, final String password) { - final String rawToken; - - rawToken = String.format("%s:%s", username, password); - return Base64.getEncoder() - .encodeToString(rawToken.getBytes(StandardCharsets.UTF_8)); - } - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/LoginService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/LoginService.java deleted file mode 100644 index 435b0e4..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/LoginService.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.login.usecase.service; - -import com.bernardomg.example.spring.security.ws.basic.login.domain.model.LoginStatus; - -/** - * Login service. Takes the user credentials and returns a token. - * - * @author Bernardo Martínez Garrido - * - */ -public interface LoginService { - - /** - * Receives credentials and returns the login status. If it was valid then it contains a token. - * - * @param username - * username to authenticate - * @param password - * password to authenticate - * @return login status - */ - public LoginStatus login(final String username, final String password); - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/package-info.java deleted file mode 100644 index b1227e4..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/login/usecase/service/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/** - * Login services. - */ - -package com.bernardomg.example.spring.security.ws.basic.login.usecase.service; diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/adapter/outbound/rest/controller/integration/ITLoginControllerSecurity.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/adapter/outbound/rest/controller/integration/ITLoginControllerSecurity.java deleted file mode 100644 index dcd83ea..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/adapter/outbound/rest/controller/integration/ITLoginControllerSecurity.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.test.login.adapter.outbound.rest.controller.integration; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.MvcIntegrationTest; - -@MvcIntegrationTest -@DisplayName("Login controller - security") -@Sql({ "/db/queries/user/single.sql", "/db/queries/security/default_role.sql" }) -public final class ITLoginControllerSecurity { - - @Autowired - private MockMvc mockMvc; - - public ITLoginControllerSecurity() { - super(); - } - - @Test - @DisplayName("Accepts unauthenticated requests") - public final void testGet_unauthorized() throws Exception { - final ResultActions result; - - result = mockMvc.perform(getRequest()); - - // The operation was accepted - result.andExpect(MockMvcResultMatchers.status() - .isOk()); - } - - private final RequestBuilder getRequest() { - return MockMvcRequestBuilders.post("/login") - .contentType(MediaType.APPLICATION_JSON) - .content("{ \"username\":\"admin\", \"password\":\"1234\" }"); - } - -} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginService.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginService.java deleted file mode 100644 index 206032e..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginService.java +++ /dev/null @@ -1,67 +0,0 @@ - -package com.bernardomg.example.spring.security.ws.basic.test.login.usecase.service.unit; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; - -import com.bernardomg.example.spring.security.ws.basic.login.domain.model.LoginStatus; -import com.bernardomg.example.spring.security.ws.basic.login.usecase.service.LoginService; -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.IntegrationTest; - -@IntegrationTest -@DisplayName("Login service") -@Sql({ "/db/queries/user/single.sql", "/db/queries/security/default_role.sql" }) -public class ITLoginService { - - @Autowired - private LoginService service; - - public ITLoginService() { - super(); - } - - @Test - @DisplayName("An existing user with invalid password doesn't log in") - public final void testLogin_invalidPassword() { - final LoginStatus result; - - result = service.login("admin", "abc"); - - Assertions.assertFalse(result.logged()); - } - - @Test - @DisplayName("A not existing user doesn't log in") - public final void testLogin_notExisting() { - final LoginStatus result; - - result = service.login("abc", "1234"); - - Assertions.assertFalse(result.logged()); - } - - @Test - @DisplayName("An existing user with valid password logs in") - public final void testLogin_valid() { - final LoginStatus result; - - result = service.login("admin", "1234"); - - Assertions.assertTrue(result.logged()); - } - - @Test - @DisplayName("A valid login returns all the data") - public final void testLogin_valid_data() { - final LoginStatus result; - - result = service.login("admin", "1234"); - - Assertions.assertEquals("admin", result.username()); - Assertions.assertEquals("YWRtaW46MTIzNA==", result.token()); - } - -} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginServiceNoData.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginServiceNoData.java deleted file mode 100644 index 4212122..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginServiceNoData.java +++ /dev/null @@ -1,34 +0,0 @@ - -package com.bernardomg.example.spring.security.ws.basic.test.login.usecase.service.unit; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import com.bernardomg.example.spring.security.ws.basic.login.domain.model.LoginStatus; -import com.bernardomg.example.spring.security.ws.basic.login.usecase.service.LoginService; -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.IntegrationTest; - -@IntegrationTest -@DisplayName("Login service - no data") -public class ITLoginServiceNoData { - - @Autowired - private LoginService service; - - public ITLoginServiceNoData() { - super(); - } - - @Test - @DisplayName("Trying to log in returns a user which isn't logged in") - public final void testLogin_invalidPassword() { - final LoginStatus result; - - result = service.login("admin", "abc"); - - Assertions.assertFalse(result.logged()); - } - -} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginServiceNoPrivileges.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginServiceNoPrivileges.java deleted file mode 100644 index 9b16c3f..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/login/usecase/service/unit/ITLoginServiceNoPrivileges.java +++ /dev/null @@ -1,36 +0,0 @@ - -package com.bernardomg.example.spring.security.ws.basic.test.login.usecase.service.unit; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; - -import com.bernardomg.example.spring.security.ws.basic.login.domain.model.LoginStatus; -import com.bernardomg.example.spring.security.ws.basic.login.usecase.service.LoginService; -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.IntegrationTest; - -@IntegrationTest -@DisplayName("Login service - no privileges") -@Sql({ "/db/queries/user/single.sql", "/db/queries/security/default_role_no_privileges.sql" }) -public class ITLoginServiceNoPrivileges { - - @Autowired - private LoginService service; - - public ITLoginServiceNoPrivileges() { - super(); - } - - @Test - @DisplayName("An existing user can't log in") - public final void testLogin_valid() { - final LoginStatus result; - - result = service.login("admin", "1234"); - - Assertions.assertFalse(result.logged()); - } - -} From 8343037e4dde52563e87671f1a44b4732d91dc06 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 14:20:58 +0100 Subject: [PATCH 03/24] Removed logs --- logs/app.log | 102 --------------------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 logs/app.log diff --git a/logs/app.log b/logs/app.log deleted file mode 100644 index fdac2e2..0000000 --- a/logs/app.log +++ /dev/null @@ -1,102 +0,0 @@ -2024-12-05T23:05:19,195 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarting(53): Starting Application using Java 21.0.4 with PID 16536 (D:\repositories\spring-ws-basic-security-example\target\classes started by Bernardo in D:\repositories\spring-ws-basic-security-example) -2024-12-05T23:05:19,206 DEBUG [restartedMain] c.b.e.s.s.w.b.Application.logStarting(54): Running with Spring Boot v3.4.0, Spring v6.2.0 -2024-12-05T23:05:19,208 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStartupProfileInfo(652): No active profile set, falling back to 1 default profile: "default" -2024-12-05T23:05:24,986 WARN [restartedMain] o.s.b.a.o.j.JpaBaseConfiguration$JpaWebConfiguration.openEntityManagerInViewInterceptor(241): spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning -2024-12-05T23:05:26,391 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarted(59): Started Application in 7.695 seconds (process running for 8.657) -2024-12-05T23:09:44,571 DEBUG [http-nio-8080-exec-2] c.b.e.s.s.w.b.s.a.AuditEventLogger.auditEventHappened(94): Audit event AUTHORIZATION_FAILURE for anonymousUser from address 0:0:0:0:0:0:0:1 -2024-12-05T23:09:44,593 DEBUG [http-nio-8080-exec-2] c.b.e.s.s.w.b.s.a.AuditEventLogger.auditEventHappened(94): Audit event AUTHORIZATION_FAILURE for anonymousUser with session id E1E20214398AEFAC3C42B5562BE1F338 from address 0:0:0:0:0:0:0:1 -2024-12-05T23:10:03,228 DEBUG [http-nio-8080-exec-3] c.b.e.s.s.w.b.s.a.AuditEventLogger.auditEventHappened(94): Audit event AUTHORIZATION_FAILURE for anonymousUser with session id E1E20214398AEFAC3C42B5562BE1F338 from address 0:0:0:0:0:0:0:1 -2024-12-05T23:10:03,233 DEBUG [http-nio-8080-exec-3] c.b.e.s.s.w.b.s.a.AuditEventLogger.auditEventHappened(94): Audit event AUTHORIZATION_FAILURE for anonymousUser with session id E1E20214398AEFAC3C42B5562BE1F338 from address 0:0:0:0:0:0:0:1 -2024-12-05T23:10:12,539 DEBUG [http-nio-8080-exec-4] c.b.e.s.s.w.b.s.u.PersistentUserDetailsService.loadUserByUsername(125): User admin exists -2024-12-05T23:10:12,539 DEBUG [http-nio-8080-exec-4] c.b.e.s.s.w.b.s.u.PersistentUserDetailsService.loadUserByUsername(126): Authorities for admin: [CREATE_DATA, DELETE_DATA, READ_DATA, UPDATE_DATA] -2024-12-05T23:10:12,541 DEBUG [http-nio-8080-exec-4] c.b.e.s.s.w.b.s.u.PersistentUserDetailsService.loadUserByUsername(127): User flags for admin. Enabled: true. Non expired: true. Non locked: true. Credentials non expired: true -2024-12-05T23:10:12,544 DEBUG [http-nio-8080-exec-4] c.b.e.s.s.w.b.s.a.AuditEventLogger.auditEventHappened(94): Audit event AUTHENTICATION_SUCCESS for admin with session id E1E20214398AEFAC3C42B5562BE1F338 from address 0:0:0:0:0:0:0:1 -2024-12-05T23:10:16,632 WARN [http-nio-8080-exec-5] c.b.e.s.s.w.b.s.u.PersistentUserDetailsService.loadUserByUsername(119): Username noroles has no authorities -2024-12-05T23:10:16,824 WARN [http-nio-8080-exec-5] c.b.e.s.s.w.b.s.u.PersistentUserDetailsService.loadUserByUsername(119): Username noroles has no authorities -2024-12-05T23:10:16,919 DEBUG [http-nio-8080-exec-5] c.b.e.s.s.w.b.s.a.AuditEventLogger.auditEventHappened(94): Audit event AUTHENTICATION_FAILURE for noroles with session id E1E20214398AEFAC3C42B5562BE1F338 from address 0:0:0:0:0:0:0:1 (Bad credentials) -2024-12-05T23:10:16,923 DEBUG [http-nio-8080-exec-5] c.b.e.s.s.w.b.s.a.AuditEventLogger.auditEventHappened(94): Audit event AUTHORIZATION_FAILURE for anonymousUser with session id E1E20214398AEFAC3C42B5562BE1F338 from address 0:0:0:0:0:0:0:1 -2024-12-05T23:10:58,623 WARN [Thread-5] o.s.b.f.s.DisposableBeanAdapter.destroy(221): Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-232] -2024-12-05T23:10:58,762 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarting(53): Starting Application using Java 21.0.4 with PID 16536 (D:\repositories\spring-ws-basic-security-example\target\classes started by Bernardo in D:\repositories\spring-ws-basic-security-example) -2024-12-05T23:10:58,763 DEBUG [restartedMain] c.b.e.s.s.w.b.Application.logStarting(54): Running with Spring Boot v3.4.0, Spring v6.2.0 -2024-12-05T23:10:58,763 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStartupProfileInfo(652): No active profile set, falling back to 1 default profile: "default" -2024-12-05T23:10:59,334 WARN [restartedMain] o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext.refresh(635): Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.bernardomg.example.spring.security.ws.basic.login.service.DefaultLoginService] for bean with name 'defaultLoginService' defined in file [D:\repositories\spring-ws-basic-security-example\target\classes\com\bernardomg\example\spring\security\ws\basic\login\service\DefaultLoginService.class]: problem with class file or dependent class -2024-12-05T23:10:59,362 ERROR [restartedMain] o.s.b.SpringApplication.reportFailure(857): Application run failed -org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.bernardomg.example.spring.security.ws.basic.login.service.DefaultLoginService] for bean with name 'defaultLoginService' defined in file [D:\repositories\spring-ws-basic-security-example\target\classes\com\bernardomg\example\spring\security\ws\basic\login\service\DefaultLoginService.class]: problem with class file or dependent class - at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1555) - at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:686) - at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:654) - at org.springframework.beans.factory.support.AbstractBeanFactory.getType(AbstractBeanFactory.java:735) - at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAnnotationOnBean(DefaultListableBeanFactory.java:765) - at org.springframework.boot.sql.init.dependency.AnnotationDependsOnDatabaseInitializationDetector.detect(AnnotationDependsOnDatabaseInitializationDetector.java:36) - at org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer$DependsOnDatabaseInitializationPostProcessor.detectDependsOnInitializationBeanNames(DatabaseInitializationDependencyConfigurer.java:152) - at org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer$DependsOnDatabaseInitializationPostProcessor.postProcessBeanFactory(DatabaseInitializationDependencyConfigurer.java:115) - at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:363) - at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:197) - at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791) - at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609) - at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) - at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) - at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) - at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) - at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361) - at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) - at com.bernardomg.example.spring.security.ws.basic.Application.main(Application.java:46) - at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) - at java.base/java.lang.reflect.Method.invoke(Method.java:580) - at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) -Caused by: java.lang.ClassFormatError: Duplicate method name "login" with signature "(Ljava.lang.String;Ljava.lang.String;)LLoginStatus;" in class file com/bernardomg/example/spring/security/ws/basic/login/service/DefaultLoginService - at java.base/java.lang.ClassLoader.defineClass1(Native Method) - at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027) - at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) - at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524) - at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427) - at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421) - at java.base/java.security.AccessController.doPrivileged(AccessController.java:714) - at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420) - at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.findClass(RestartClassLoader.java:136) - at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:118) - at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) - at java.base/java.lang.Class.forName0(Native Method) - at java.base/java.lang.Class.forName(Class.java:534) - at java.base/java.lang.Class.forName(Class.java:513) - at org.springframework.util.ClassUtils.forName(ClassUtils.java:321) - at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:503) - at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1620) - at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1545) - ... 21 more -2024-12-05T23:11:06,632 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarting(53): Starting Application using Java 21.0.4 with PID 16536 (D:\repositories\spring-ws-basic-security-example\target\classes started by Bernardo in D:\repositories\spring-ws-basic-security-example) -2024-12-05T23:11:06,635 DEBUG [restartedMain] c.b.e.s.s.w.b.Application.logStarting(54): Running with Spring Boot v3.4.0, Spring v6.2.0 -2024-12-05T23:11:06,636 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStartupProfileInfo(652): No active profile set, falling back to 1 default profile: "default" -2024-12-05T23:11:08,076 WARN [restartedMain] o.s.b.a.o.j.JpaBaseConfiguration$JpaWebConfiguration.openEntityManagerInViewInterceptor(241): spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning -2024-12-05T23:11:08,894 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarted(59): Started Application in 2.382 seconds (process running for 351.16) -2024-12-05T23:11:23,627 WARN [Thread-7] o.s.b.f.s.DisposableBeanAdapter.destroy(221): Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-232] -2024-12-05T23:11:23,727 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarting(53): Starting Application using Java 21.0.4 with PID 16536 (D:\repositories\spring-ws-basic-security-example\target\classes started by Bernardo in D:\repositories\spring-ws-basic-security-example) -2024-12-05T23:11:23,728 DEBUG [restartedMain] c.b.e.s.s.w.b.Application.logStarting(54): Running with Spring Boot v3.4.0, Spring v6.2.0 -2024-12-05T23:11:23,728 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStartupProfileInfo(652): No active profile set, falling back to 1 default profile: "default" -2024-12-05T23:11:24,921 WARN [restartedMain] o.s.b.a.o.j.JpaBaseConfiguration$JpaWebConfiguration.openEntityManagerInViewInterceptor(241): spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning -2024-12-05T23:11:25,712 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarted(59): Started Application in 2.022 seconds (process running for 367.978) -2024-12-05T23:11:46,550 WARN [Thread-15] o.s.b.f.s.DisposableBeanAdapter.destroy(221): Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-232] -2024-12-05T23:11:46,658 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarting(53): Starting Application using Java 21.0.4 with PID 16536 (D:\repositories\spring-ws-basic-security-example\target\classes started by Bernardo in D:\repositories\spring-ws-basic-security-example) -2024-12-05T23:11:46,659 DEBUG [restartedMain] c.b.e.s.s.w.b.Application.logStarting(54): Running with Spring Boot v3.4.0, Spring v6.2.0 -2024-12-05T23:11:46,660 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStartupProfileInfo(652): No active profile set, falling back to 1 default profile: "default" -2024-12-05T23:11:48,178 WARN [restartedMain] o.s.b.a.o.j.JpaBaseConfiguration$JpaWebConfiguration.openEntityManagerInViewInterceptor(241): spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning -2024-12-05T23:11:48,989 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarted(59): Started Application in 2.374 seconds (process running for 391.255) -2024-12-05T23:12:11,921 WARN [Thread-19] o.s.b.f.s.DisposableBeanAdapter.destroy(221): Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-232] -2024-12-05T23:12:12,022 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarting(53): Starting Application using Java 21.0.4 with PID 16536 (D:\repositories\spring-ws-basic-security-example\target\classes started by Bernardo in D:\repositories\spring-ws-basic-security-example) -2024-12-05T23:12:12,023 DEBUG [restartedMain] c.b.e.s.s.w.b.Application.logStarting(54): Running with Spring Boot v3.4.0, Spring v6.2.0 -2024-12-05T23:12:12,024 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStartupProfileInfo(652): No active profile set, falling back to 1 default profile: "default" -2024-12-05T23:12:13,409 WARN [restartedMain] o.s.b.a.o.j.JpaBaseConfiguration$JpaWebConfiguration.openEntityManagerInViewInterceptor(241): spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning -2024-12-05T23:12:14,315 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarted(59): Started Application in 2.329 seconds (process running for 416.581) -2024-12-05T23:12:50,682 WARN [Thread-23] o.s.b.f.s.DisposableBeanAdapter.destroy(221): Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-232] -2024-12-05T23:12:50,790 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarting(53): Starting Application using Java 21.0.4 with PID 16536 (D:\repositories\spring-ws-basic-security-example\target\classes started by Bernardo in D:\repositories\spring-ws-basic-security-example) -2024-12-05T23:12:50,792 DEBUG [restartedMain] c.b.e.s.s.w.b.Application.logStarting(54): Running with Spring Boot v3.4.0, Spring v6.2.0 -2024-12-05T23:12:50,793 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStartupProfileInfo(652): No active profile set, falling back to 1 default profile: "default" -2024-12-05T23:12:52,213 WARN [restartedMain] o.s.b.a.o.j.JpaBaseConfiguration$JpaWebConfiguration.openEntityManagerInViewInterceptor(241): spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning -2024-12-05T23:12:52,952 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarted(59): Started Application in 2.204 seconds (process running for 455.218) -2024-12-05T23:12:59,601 WARN [Thread-27] o.s.b.f.s.DisposableBeanAdapter.destroy(221): Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-232] -2024-12-05T23:12:59,713 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarting(53): Starting Application using Java 21.0.4 with PID 16536 (D:\repositories\spring-ws-basic-security-example\target\classes started by Bernardo in D:\repositories\spring-ws-basic-security-example) -2024-12-05T23:12:59,714 DEBUG [restartedMain] c.b.e.s.s.w.b.Application.logStarting(54): Running with Spring Boot v3.4.0, Spring v6.2.0 -2024-12-05T23:12:59,715 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStartupProfileInfo(652): No active profile set, falling back to 1 default profile: "default" -2024-12-05T23:13:00,904 WARN [restartedMain] o.s.b.a.o.j.JpaBaseConfiguration$JpaWebConfiguration.openEntityManagerInViewInterceptor(241): spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning -2024-12-05T23:13:01,663 INFO [restartedMain] c.b.e.s.s.w.b.Application.logStarted(59): Started Application in 1.987 seconds (process running for 463.929) -2024-12-05T23:14:29,184 WARN [SpringApplicationShutdownHook] o.s.b.f.s.DisposableBeanAdapter.destroy(221): Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-232] From 7cf3bcf4ac056f664131a360627f853164f2a70b Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 14:21:28 +0100 Subject: [PATCH 04/24] Ignored logs --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9419d78..3b01119 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ # Log files # /*.log /*.log.* +/logs/** # Output folders # /test-output/ From c2bb2d1125c58680bedd6c4072a8fa75ce731f0f Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 23:03:00 +0100 Subject: [PATCH 05/24] Reworked user model --- .../ws/basic/config/SecurityConfig.java | 10 +- .../inbound/jpa/model/PrivilegeEntity.java} | 4 +- .../adapter/inbound/jpa/model/RoleEntity.java | 79 +++++++++++ .../inbound/jpa/model/UserEntity.java} | 33 +++-- .../inbound/jpa}/model/package-info.java | 2 +- .../jpa/repository/JpaUserRepository.java | 65 +++++++++ .../jpa/repository/UserSpringRepository.java} | 17 +-- .../inbound/jpa}/repository/package-info.java | 2 +- .../security/user/domain/model/Privilege.java | 35 +++++ .../security/user/domain/model/User.java | 74 ++++++++++ .../repository/UserRepository.java} | 38 +++--- .../PersistentUserDetailsService.java | 126 ++++++++---------- .../ITExampleEntityControllerSecurity.java | 4 +- .../integration/ITUserRepository.java | 16 +-- .../integration/ITPrivilegeRepository.java | 67 ---------- .../ITPrivilegeRepositoryNoData.java | 35 ----- 16 files changed, 372 insertions(+), 235 deletions(-) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/{persistence/model/PersistentPrivilege.java => adapter/inbound/jpa/model/PrivilegeEntity.java} (96%) create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/RoleEntity.java rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/{persistence/model/PersistentUser.java => adapter/inbound/jpa/model/UserEntity.java} (76%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/{persistence => adapter/inbound/jpa}/model/package-info.java (97%) create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/{persistence/repository/UserRepository.java => adapter/inbound/jpa/repository/UserSpringRepository.java} (77%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/{persistence => adapter/inbound/jpa}/repository/package-info.java (97%) create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/Privilege.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/{persistence/repository/PrivilegeRepository.java => domain/repository/UserRepository.java} (57%) rename src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/{persistence => domain}/repository/integration/ITUserRepository.java (76%) delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITPrivilegeRepository.java delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITPrivilegeRepositoryNoData.java diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java index 479a942..7cbaef7 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java @@ -31,8 +31,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository.PrivilegeRepository; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository.UserRepository; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; import com.bernardomg.example.spring.security.ws.basic.security.userdetails.PersistentUserDetailsService; /** @@ -67,14 +66,11 @@ public PasswordEncoder getPasswordEncoder() { * * @param userRepository * repository for finding users - * @param privilegeRepository - * repository for finding user privileges * @return the user details service */ @Bean("userDetailsService") - public UserDetailsService getUserDetailsService(final UserRepository userRepository, - final PrivilegeRepository privilegeRepository) { - return new PersistentUserDetailsService(userRepository, privilegeRepository); + public UserDetailsService getUserDetailsService(final UserRepository userRepository) { + return new PersistentUserDetailsService(userRepository); } } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/model/PersistentPrivilege.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java similarity index 96% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/model/PersistentPrivilege.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java index 5a03643..a325838 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/model/PersistentPrivilege.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model; +package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model; import java.io.Serializable; @@ -49,7 +49,7 @@ @Table(name = "privileges") @TableGenerator(name = "seq_privileges_id", table = "sequences", pkColumnName = "sequence", valueColumnName = "count", allocationSize = 1) -public class PersistentPrivilege implements Serializable { +public class PrivilegeEntity implements Serializable { /** * Serialization id. diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/RoleEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/RoleEntity.java new file mode 100644 index 0000000..455440a --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/RoleEntity.java @@ -0,0 +1,79 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model; + +import java.io.Serializable; +import java.util.Collection; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import jakarta.persistence.TableGenerator; +import lombok.Data; + +/** + * Role entity. + * + * @author Bernardo Martínez Garrido + * + */ +@Data +@Entity(name = "Role") +@Table(name = "roles") +@TableGenerator(name = "seq_roles_id", table = "sequences", pkColumnName = "sequence", valueColumnName = "count", + allocationSize = 1) +public class RoleEntity implements Serializable { + + /** + * Serialization id. + */ + private static final long serialVersionUID = 8513041662486312372L; + + /** + * Entity id. + */ + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "seq_privileges_id") + @Column(name = "id", nullable = false, unique = true) + private Long id; + + /** + * Privilege name. + */ + @Column(name = "name", nullable = false, unique = true, length = 60) + private String name; + + @OneToMany + @JoinTable(name = "role_privileges", joinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") }, + inverseJoinColumns = { @JoinColumn(name = "privilege_id", referencedColumnName = "id") }) + private Collection privileges; + +} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/model/PersistentUser.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java similarity index 76% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/model/PersistentUser.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java index f22b4d8..f5e385e 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/model/PersistentUser.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java @@ -22,15 +22,19 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model; +package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model; import java.io.Serializable; +import java.util.Collection; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import jakarta.persistence.TableGenerator; import jakarta.persistence.Transient; @@ -50,37 +54,37 @@ @Table(name = "users") @TableGenerator(name = "seq_users_id", table = "sequences", pkColumnName = "sequence", valueColumnName = "count", allocationSize = 1) -public class PersistentUser implements Serializable { +public class UserEntity implements Serializable { /** * Serialization id. */ @Transient - private static final long serialVersionUID = 4807136960800402795L; + private static final long serialVersionUID = 4807136960800402795L; /** * User expired flag. */ @Column(name = "credentials_expired", nullable = false) - private Boolean credentialsExpired; + private Boolean credentialsExpired; /** * User email. */ @Column(name = "email", nullable = false, length = 60) - private String email; + private String email; /** * User enabled flag. */ @Column(name = "enabled", nullable = false) - private Boolean enabled; + private Boolean enabled; /** * User expired flag. */ @Column(name = "expired", nullable = false) - private Boolean expired; + private Boolean expired; /** * Entity id. @@ -88,30 +92,35 @@ public class PersistentUser implements Serializable { @Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "seq_users_id") @Column(name = "id", nullable = false, unique = true) - private Long id; + private Long id; /** * User locked flag. */ @Column(name = "locked", nullable = false) - private Boolean locked; + private Boolean locked; /** * User name. */ @Column(name = "name", nullable = false, unique = true, length = 60) - private String name; + private String name; /** * User password. */ @Column(name = "password", nullable = false, length = 60) - private String password; + private String password; + + @OneToMany + @JoinTable(name = "user_roles", joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id") }, + inverseJoinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") }) + private Collection roles; /** * User name. */ @Column(name = "username", nullable = false, unique = true, length = 60) - private String username; + private String username; } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java similarity index 97% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/model/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java index 15e4227..63b37d6 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/model/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java @@ -26,4 +26,4 @@ * User model. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model; +package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java new file mode 100644 index 0000000..48e7246 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java @@ -0,0 +1,65 @@ + +package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.repository; + +import java.util.Collection; +import java.util.Objects; +import java.util.Optional; + +import org.springframework.stereotype.Repository; + +import com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model.PrivilegeEntity; +import com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model.RoleEntity; +import com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model.UserEntity; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.Privilege; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; + +@Repository +public final class JpaUserRepository implements UserRepository { + + private final UserSpringRepository userSpringRepository; + + public JpaUserRepository(final UserSpringRepository userSpringRepo) { + super(); + + userSpringRepository = Objects.requireNonNull(userSpringRepo, "Received a null pointer as user repository"); + } + + @Override + public Optional findOne(final String username) { + return userSpringRepository.findOneByUsername(username) + .map(this::toDomain); + } + + @Override + public Optional findPassword(final String username) { + return userSpringRepository.findOneByUsername(username) + .map(UserEntity::getPassword); + } + + private Privilege toDomain(final PrivilegeEntity entity) { + return new Privilege(entity.getName()); + } + + private User toDomain(final UserEntity entity) { + final Collection privileges; + + privileges = entity.getRoles() + .stream() + .map(RoleEntity::getPrivileges) + .flatMap(Collection::stream) + .map(this::toDomain) + .toList(); + return User.builder() + .withName(entity.getName()) + .withEmail(entity.getEmail()) + .withUsername(entity.getUsername()) + .withEnabled(entity.getEnabled()) + .withExpired(entity.getExpired()) + .withLocked(entity.getLocked()) + .withPasswordExpired(entity.getCredentialsExpired()) + .withPrivileges(privileges) + .build(); + } + +} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/repository/UserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/UserSpringRepository.java similarity index 77% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/repository/UserRepository.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/UserSpringRepository.java index 06f0d70..0496c18 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/repository/UserRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/UserSpringRepository.java @@ -22,13 +22,13 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository; +package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.repository; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model.PersistentUser; +import com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model.UserEntity; /** * Repository for users. @@ -36,16 +36,7 @@ * @author Bernardo Martínez Garrido * */ -public interface UserRepository extends JpaRepository { - - /** - * Returns the user details for the received email. - * - * @param email - * email to search for - * @return the user details for the received email - */ - public Optional findOneByEmail(final String email); +public interface UserSpringRepository extends JpaRepository { /** * Returns the user details for the received username. @@ -54,6 +45,6 @@ public interface UserRepository extends JpaRepository { * username to search for * @return the user details for the received username */ - public Optional findOneByUsername(final String username); + public Optional findOneByUsername(final String username); } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java similarity index 97% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/repository/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java index 79a5fe4..04e6398 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/repository/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java @@ -26,4 +26,4 @@ * User repositories. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository; +package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.repository; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/Privilege.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/Privilege.java new file mode 100644 index 0000000..be3ecf2 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/Privilege.java @@ -0,0 +1,35 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.bernardomg.example.spring.security.ws.basic.security.user.domain.model; + +/** + * Privilege. + * + * @author Bernardo Martínez Garrido + * + */ +public record Privilege(String name) { + +} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java new file mode 100644 index 0000000..6829a29 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java @@ -0,0 +1,74 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.bernardomg.example.spring.security.ws.basic.security.user.domain.model; + +import java.util.Collection; +import java.util.Objects; + +import lombok.Builder; + +/** + * Representation of a user. + *

+ * FIXME: this should be immutable + * + * @author Bernardo Martínez Garrido + * + */ +@Builder(setterPrefix = "with") +public record User(String email, boolean enabled, boolean expired, boolean locked, String name, boolean passwordExpired, + Collection privileges, String username) { + + public User(final String email, final boolean enabled, final boolean expired, final boolean locked, + final String name, final boolean passwordExpired, final Collection privileges, + final String username) { + if (Objects.nonNull(name)) { + this.name = name.trim(); + } else { + this.name = null; + } + + if (Objects.nonNull(username)) { + this.username = username.trim() + .toLowerCase(); + } else { + this.username = null; + } + + if (Objects.nonNull(email)) { + this.email = email.trim() + .toLowerCase(); + } else { + this.email = null; + } + + this.enabled = enabled; + this.expired = expired; + this.locked = locked; + this.passwordExpired = passwordExpired; + this.privileges = privileges; + } + +} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/repository/PrivilegeRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java similarity index 57% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/repository/PrivilegeRepository.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java index 70c3d77..0c2140c 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/persistence/repository/PrivilegeRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2023 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,33 +22,35 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository; +package com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository; -import java.util.Collection; +import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model.PersistentPrivilege; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; /** - * Repository for privileges. + * User repository. * * @author Bernardo Martínez Garrido - * */ -public interface PrivilegeRepository extends JpaRepository { +public interface UserRepository { + + /** + * Returns the user for the received username. + * + * @param username + * user to search for + * @return the user for the received username + */ + public Optional findOne(final String username); /** - * Returns all the privileges for a user. This requires a join from the user up to the privileges. + * Returns the password for the user. * - * @param id - * user id - * @return all the privileges for the user + * @param username + * user to search for the password + * @return the user password */ - @Query(value = "SELECT p.* FROM privileges p JOIN role_privileges rp ON p.id = rp.privilege_id JOIN roles r ON r.id = rp.role_id JOIN user_roles ur ON r.id = ur.role_id JOIN users u ON u.id = ur.user_id WHERE u.id = :id", - nativeQuery = true) - public Collection findForUser(@Param("id") final Long id); + public Optional findPassword(final String username); } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/PersistentUserDetailsService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/PersistentUserDetailsService.java index a9ab71f..b968524 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/PersistentUserDetailsService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/PersistentUserDetailsService.java @@ -27,20 +27,16 @@ import java.util.Collection; import java.util.Locale; import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model.PersistentPrivilege; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model.PersistentUser; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository.PrivilegeRepository; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository.UserRepository; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.Privilege; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; import lombok.extern.slf4j.Slf4j; @@ -74,103 +70,95 @@ public final class PersistentUserDetailsService implements UserDetailsService { /** - * Repository for the privileges. + * User repository. */ - private final PrivilegeRepository privilegeRepo; - - /** - * Repository for the user data. - */ - private final UserRepository userRepo; + private final UserRepository userRepository; /** * Constructs a user details service. * - * @param userRepository - * repository for user details - * @param privilegeRepository - * repository for privileges + * @param userRepo + * users repository */ - public PersistentUserDetailsService(final UserRepository userRepository, - final PrivilegeRepository privilegeRepository) { + public PersistentUserDetailsService(final UserRepository userRepo) { super(); - userRepo = Objects.requireNonNull(userRepository, "Received a null pointer as repository"); - privilegeRepo = Objects.requireNonNull(privilegeRepository, "Received a null pointer as repository"); + userRepository = Objects.requireNonNull(userRepo, "Received a null pointer as user repository"); } @Override public final UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException { - final Optional user; - final Collection authorities; - final UserDetails details; - - user = userRepo.findOneByUsername(username.toLowerCase(Locale.getDefault())); - - if (!user.isPresent()) { - log.warn("Username {} not found in DB", username); - throw new UsernameNotFoundException(username); + final User user; + final UserDetails details; + final String password; + + user = userRepository.findOne(username.toLowerCase(Locale.getDefault())) + .orElseThrow(() -> { + log.error("Username {} not found in database", username); + throw new UsernameNotFoundException(String.format("Username %s not found in database", username)); + }); + + if (user.privileges() + .isEmpty()) { + log.error("Username {} has no authorities", username); + throw new UsernameNotFoundException(String.format("Username %s has no authorities", username)); } - authorities = getAuthorities(user.get() - .getId()); - - if (authorities.isEmpty()) { - log.warn("Username {} has no authorities", username); - throw new UsernameNotFoundException(username); - } + password = userRepository.findPassword(username) + .get(); + details = toUserDetails(user, password); - details = toUserDetails(user.get(), authorities); - - log.debug("User {} exists", username); - log.debug("Authorities for {}: {}", username, details.getAuthorities()); - log.debug("User flags for {}. Enabled: {}. Non expired: {}. Non locked: {}. Credentials non expired: {}", - username, details.isEnabled(), details.isAccountNonExpired(), details.isAccountNonLocked(), + log.debug("User {} exists. Enabled: {}. Non expired: {}. Non locked: {}. Credentials non expired: {}", username, + details.isEnabled(), details.isAccountNonExpired(), details.isAccountNonLocked(), details.isCredentialsNonExpired()); + log.debug("Authorities for {}: {}", username, details.getAuthorities()); return details; } /** - * Returns all the authorities for the user. + * Creates a {@link GrantedAuthority} from the {@link Privilege}. * - * @param id - * id of the user - * @return all the authorities for the user + * @param privilege + * privilege to transform + * @return {@code GrantedAuthority} from the {@code Privilege} */ - private final Collection getAuthorities(final Long id) { - return privilegeRepo.findForUser(id) - .stream() - .map(PersistentPrivilege::getName) - .distinct() - .map(SimpleGrantedAuthority::new) - .collect(Collectors.toList()); + private final GrantedAuthority toGrantedAuthority(final Privilege privilege) { + return new SimpleGrantedAuthority(privilege.name()); } /** - * Transforms a user entity into a user details object. + * Transforms a user into a user details object. * * @param user - * entity to transform + * user to transform + * @param password + * user password * @param authorities * authorities for the user details * @return equivalent user details */ - private final UserDetails toUserDetails(final PersistentUser user, - final Collection authorities) { - final Boolean enabled; - final Boolean accountNonExpired; - final Boolean credentialsNonExpired; - final Boolean accountNonLocked; + private final UserDetails toUserDetails(final User user, final String password) { + final Boolean enabled; + final Boolean accountNonExpired; + final Boolean credentialsNonExpired; + final Boolean accountNonLocked; + final Collection authorities; // Loads status - enabled = user.getEnabled(); - accountNonExpired = !user.getExpired(); - credentialsNonExpired = !user.getCredentialsExpired(); - accountNonLocked = !user.getLocked(); + enabled = user.enabled(); + accountNonExpired = !user.expired(); + credentialsNonExpired = !user.passwordExpired(); + accountNonLocked = !user.locked(); + + // Authorities + authorities = user.privileges() + .stream() + .map(this::toGrantedAuthority) + .toList(); - return new User(user.getUsername(), user.getPassword(), enabled, accountNonExpired, credentialsNonExpired, - accountNonLocked, authorities); + return new org.springframework.security.core.userdetails.User(user.username(), password, enabled, + accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); } } diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurity.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurity.java index f106edb..ec7d417 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurity.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurity.java @@ -73,11 +73,11 @@ public final void testGet_unauthorized() throws Exception { } private final RequestBuilder getRequest() { - return MockMvcRequestBuilders.get("/rest/entity"); + return MockMvcRequestBuilders.get("/rest/person"); } private final RequestBuilder getRequestAuthorized() { - return MockMvcRequestBuilders.get("/rest/entity") + return MockMvcRequestBuilders.get("/rest/person") .header("Authorization", "Basic YWRtaW46MTIzNA=="); } diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITUserRepository.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/domain/repository/integration/ITUserRepository.java similarity index 76% rename from src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITUserRepository.java rename to src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/domain/repository/integration/ITUserRepository.java index 7f2439e..fe2568f 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITUserRepository.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/domain/repository/integration/ITUserRepository.java @@ -1,5 +1,5 @@ -package com.bernardomg.example.spring.security.ws.basic.test.security.user.persistence.repository.integration; +package com.bernardomg.example.spring.security.ws.basic.test.security.user.domain.repository.integration; import java.util.Optional; @@ -9,8 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.jdbc.Sql; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model.PersistentUser; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository.UserRepository; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.IntegrationTest; @IntegrationTest @@ -28,21 +28,21 @@ public ITUserRepository() { @Test @DisplayName("Returns the user for an existing username") public void testFindForUser_existing() { - final Optional result; + final Optional result; - result = repository.findOneByUsername("admin"); + result = repository.findOne("admin"); Assertions.assertTrue(result.isPresent()); Assertions.assertEquals("admin", result.get() - .getUsername()); + .username()); } @Test @DisplayName("Returns no data for a not existing username") public void testFindForUser_notExisting() { - final Optional result; + final Optional result; - result = repository.findOneByUsername("abc"); + result = repository.findOne("abc"); Assertions.assertFalse(result.isPresent()); } diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITPrivilegeRepository.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITPrivilegeRepository.java deleted file mode 100644 index cec8fe7..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITPrivilegeRepository.java +++ /dev/null @@ -1,67 +0,0 @@ - -package com.bernardomg.example.spring.security.ws.basic.test.security.user.persistence.repository.integration; - -import java.util.Collection; -import java.util.stream.Collectors; - -import org.apache.commons.collections4.IterableUtils; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; - -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model.PersistentPrivilege; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository.PrivilegeRepository; -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.IntegrationTest; - -@IntegrationTest -@DisplayName("Privilege repository") -@Sql({ "/db/queries/user/single.sql", "/db/queries/security/default_role.sql" }) -public class ITPrivilegeRepository { - - @Autowired - private PrivilegeRepository repository; - - public ITPrivilegeRepository() { - super(); - } - - @Test - @DisplayName("Returns all the privileges for a user") - public void testFindForUser_Count() { - final Iterable result; - - result = repository.findForUser(1L); - - Assertions.assertEquals(4, IterableUtils.size(result)); - } - - @Test - @DisplayName("Returns all the data for the privileges of a user") - public void testFindForUser_Data() { - final Collection result; - final Collection privileges; - - result = repository.findForUser(1L); - privileges = result.stream() - .map(PersistentPrivilege::getName) - .collect(Collectors.toList()); - - Assertions.assertTrue(privileges.contains("CREATE_DATA")); - Assertions.assertTrue(privileges.contains("READ_DATA")); - Assertions.assertTrue(privileges.contains("UPDATE_DATA")); - Assertions.assertTrue(privileges.contains("DELETE_DATA")); - } - - @Test - @DisplayName("Returns no privileges for a not existing user") - public void testFindForUser_notExisting() { - final Iterable result; - - result = repository.findForUser(-1L); - - Assertions.assertEquals(0, IterableUtils.size(result)); - } - -} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITPrivilegeRepositoryNoData.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITPrivilegeRepositoryNoData.java deleted file mode 100644 index c76d8c7..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/persistence/repository/integration/ITPrivilegeRepositoryNoData.java +++ /dev/null @@ -1,35 +0,0 @@ - -package com.bernardomg.example.spring.security.ws.basic.test.security.user.persistence.repository.integration; - -import org.apache.commons.collections4.IterableUtils; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.model.PersistentPrivilege; -import com.bernardomg.example.spring.security.ws.basic.security.user.persistence.repository.PrivilegeRepository; -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.IntegrationTest; - -@IntegrationTest -@DisplayName("Privilege repository - no data") -public class ITPrivilegeRepositoryNoData { - - @Autowired - private PrivilegeRepository repository; - - public ITPrivilegeRepositoryNoData() { - super(); - } - - @Test - @DisplayName("Returns all the privileges for a user") - public void testFindForUser_Count() { - final Iterable result; - - result = repository.findForUser(1L); - - Assertions.assertEquals(0, IterableUtils.size(result)); - } - -} From e9c92b91eaecd8a9ecabce711f993089f0857625 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 23:06:50 +0100 Subject: [PATCH 06/24] Read persons from users --- .../PlaceholderPersonRepository.java | 22 ++++++++++++++----- .../ws/basic/person/domain/model/Person.java | 2 +- .../jpa/repository/JpaUserRepository.java | 8 +++++++ .../domain/repository/UserRepository.java | 8 +++++++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java index d99521b..ef6880f 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java @@ -2,12 +2,14 @@ package com.bernardomg.example.spring.security.ws.basic.person.adapter.inbound.placeholder.repository; import java.util.Collection; -import java.util.List; +import java.util.Objects; import org.springframework.stereotype.Repository; import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; import com.bernardomg.example.spring.security.ws.basic.person.domain.repository.PersonRepository; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; import lombok.extern.slf4j.Slf4j; @@ -15,24 +17,32 @@ @Repository public final class PlaceholderPersonRepository implements PersonRepository { - public PlaceholderPersonRepository() { + private final UserRepository userRepository; + + public PlaceholderPersonRepository(final UserRepository userRepo) { super(); + + userRepository = Objects.requireNonNull(userRepo, "Received a null pointer as user repository"); } @Override public final Collection findAll() { - final Person person; final Collection persons; log.debug("Finding all the persons"); - person = new Person("id", "Name", "Surname"); - - persons = List.of(person); + persons = userRepository.findAll() + .stream() + .map(this::toPerson) + .toList(); log.debug("Found all the persons: {}", persons); return persons; } + private final Person toPerson(final User user) { + return new Person(user.username(), user.name()); + } + } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java index 752c52d..ae6bf25 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java @@ -1,6 +1,6 @@ package com.bernardomg.example.spring.security.ws.basic.person.domain.model; -public record Person(String id, String name, String surname) { +public record Person(String id, String name) { } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java index 48e7246..7b19c80 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java @@ -25,6 +25,14 @@ public JpaUserRepository(final UserSpringRepository userSpringRepo) { userSpringRepository = Objects.requireNonNull(userSpringRepo, "Received a null pointer as user repository"); } + @Override + public final Collection findAll() { + return userSpringRepository.findAll() + .stream() + .map(this::toDomain) + .toList(); + } + @Override public Optional findOne(final String username) { return userSpringRepository.findOneByUsername(username) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java index 0c2140c..68b94d1 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java @@ -24,6 +24,7 @@ package com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository; +import java.util.Collection; import java.util.Optional; import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; @@ -35,6 +36,13 @@ */ public interface UserRepository { + /** + * Returns all the users. + * + * @return the user for the received username + */ + public Collection findAll(); + /** * Returns the user for the received username. * From 5b8cc2055214ee63ede89ea1b92ffe5ebeacbce5 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 23:23:41 +0100 Subject: [PATCH 07/24] Added tests --- .../ws/basic/config/SecurityConfig.java | 2 +- .../PersistentUserDetailsService.java | 2 +- .../usecase}/package-info.java | 2 +- .../TestPersistentUserDetailsService.java | 299 ++++++++++++++++++ .../config/factory/PermissionConstants.java | 8 + .../test/config/factory/Privileges.java | 12 + .../test/config/factory/UserConstants.java | 18 ++ .../security/test/config/factory/Users.java | 88 ++++++ .../db/queries/security/default_role.sql | 8 +- 9 files changed, 432 insertions(+), 7 deletions(-) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/{userdetails => springframework/usecase}/PersistentUserDetailsService.java (99%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/{userdetails => springframework/usecase}/package-info.java (98%) create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestPersistentUserDetailsService.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/PermissionConstants.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Privileges.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/UserConstants.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Users.java diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java index 7cbaef7..9c18c00 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java @@ -31,8 +31,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; +import com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase.PersistentUserDetailsService; import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; -import com.bernardomg.example.spring.security.ws.basic.security.userdetails.PersistentUserDetailsService; /** * Security configuration. diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/PersistentUserDetailsService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/PersistentUserDetailsService.java similarity index 99% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/PersistentUserDetailsService.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/PersistentUserDetailsService.java index b968524..b04f7a6 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/PersistentUserDetailsService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/PersistentUserDetailsService.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.userdetails; +package com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase; import java.util.Collection; import java.util.Locale; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/package-info.java similarity index 98% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/package-info.java index a12ce4f..c3c945d 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/userdetails/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/package-info.java @@ -26,4 +26,4 @@ * User details components. */ -package com.bernardomg.example.spring.security.ws.basic.security.userdetails; +package com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase; diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestPersistentUserDetailsService.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestPersistentUserDetailsService.java new file mode 100644 index 0000000..579b24f --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestPersistentUserDetailsService.java @@ -0,0 +1,299 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.springframework.usecase.unit; + +import static org.mockito.BDDMockito.given; + +import java.util.Optional; + +import org.assertj.core.api.Assertions; +import org.assertj.core.api.SoftAssertions; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +import com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase.PersistentUserDetailsService; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; +import com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory.PermissionConstants; +import com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory.UserConstants; +import com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory.Users; + +@ExtendWith(MockitoExtension.class) +@DisplayName("PersistentUserDetailsService") +class TestPersistentUserDetailsService { + + @InjectMocks + private PersistentUserDetailsService service; + + @Mock + private UserRepository userRepository; + + public TestPersistentUserDetailsService() { + super(); + } + + @Test + @DisplayName("When the user is disabled it is returned") + void testLoadByUsername_Disabled() { + final UserDetails userDetails; + + // GIVEN + given(userRepository.findOne(UserConstants.USERNAME)).willReturn(Optional.of(Users.disabled())); + given(userRepository.findPassword(UserConstants.USERNAME)).willReturn(Optional.of(UserConstants.PASSWORD)); + + // WHEN + userDetails = service.loadUserByUsername(UserConstants.USERNAME); + + // THEN + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(userDetails.getUsername()) + .as("username") + .isEqualTo(UserConstants.USERNAME); + softly.assertThat(userDetails.getPassword()) + .as("password") + .isEqualTo(UserConstants.PASSWORD); + softly.assertThat(userDetails.isAccountNonExpired()) + .as("non expired") + .isTrue(); + softly.assertThat(userDetails.isAccountNonLocked()) + .as("non locked") + .isTrue(); + softly.assertThat(userDetails.isCredentialsNonExpired()) + .as("credentials non expired") + .isTrue(); + softly.assertThat(userDetails.isEnabled()) + .as("enabled") + .isFalse(); + + softly.assertThat(userDetails.getAuthorities()) + .as("authorities size") + .hasSize(1); + softly.assertThat(userDetails.getAuthorities()) + .extracting(GrantedAuthority::getAuthority) + .first() + .as("authority resource") + .isEqualTo(PermissionConstants.DATA_CREATE); + }); + } + + @Test + @DisplayName("When the user is enabled it is returned") + void testLoadByUsername_Enabled() { + final UserDetails userDetails; + + // GIVEN + given(userRepository.findOne(UserConstants.USERNAME)).willReturn(Optional.of(Users.enabled())); + given(userRepository.findPassword(UserConstants.USERNAME)).willReturn(Optional.of(UserConstants.PASSWORD)); + + // WHEN + userDetails = service.loadUserByUsername(UserConstants.USERNAME); + + // THEN + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(userDetails.getUsername()) + .as("username") + .isEqualTo(UserConstants.USERNAME); + softly.assertThat(userDetails.getPassword()) + .as("password") + .isEqualTo(UserConstants.PASSWORD); + softly.assertThat(userDetails.isAccountNonExpired()) + .as("non expired") + .isTrue(); + softly.assertThat(userDetails.isAccountNonLocked()) + .as("non locked") + .isTrue(); + softly.assertThat(userDetails.isCredentialsNonExpired()) + .as("credentials non expired") + .isTrue(); + softly.assertThat(userDetails.isEnabled()) + .as("enabled") + .isTrue(); + + softly.assertThat(userDetails.getAuthorities()) + .as("authorities size") + .hasSize(1); + softly.assertThat(userDetails.getAuthorities()) + .extracting(GrantedAuthority::getAuthority) + .first() + .as("authority resource") + .isEqualTo(PermissionConstants.DATA_CREATE); + }); + } + + @Test + @DisplayName("When the user is expired it is returned") + void testLoadByUsername_Expired() { + final UserDetails userDetails; + + // GIVEN + given(userRepository.findOne(UserConstants.USERNAME)).willReturn(Optional.of(Users.expired())); + given(userRepository.findPassword(UserConstants.USERNAME)).willReturn(Optional.of(UserConstants.PASSWORD)); + + // WHEN + userDetails = service.loadUserByUsername(UserConstants.USERNAME); + + // THEN + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(userDetails.getUsername()) + .as("username") + .isEqualTo(UserConstants.USERNAME); + softly.assertThat(userDetails.getPassword()) + .as("password") + .isEqualTo(UserConstants.PASSWORD); + softly.assertThat(userDetails.isAccountNonExpired()) + .as("non expired") + .isFalse(); + softly.assertThat(userDetails.isAccountNonLocked()) + .as("non locked") + .isTrue(); + softly.assertThat(userDetails.isCredentialsNonExpired()) + .as("credentials non expired") + .isTrue(); + softly.assertThat(userDetails.isEnabled()) + .as("enabled") + .isTrue(); + + softly.assertThat(userDetails.getAuthorities()) + .as("authorities size") + .hasSize(1); + softly.assertThat(userDetails.getAuthorities()) + .extracting(GrantedAuthority::getAuthority) + .first() + .as("authority resource") + .isEqualTo(PermissionConstants.DATA_CREATE); + }); + } + + @Test + @DisplayName("When the user is locked it is returned") + void testLoadByUsername_Locked() { + final UserDetails userDetails; + + // GIVEN + given(userRepository.findOne(UserConstants.USERNAME)).willReturn(Optional.of(Users.locked())); + given(userRepository.findPassword(UserConstants.USERNAME)).willReturn(Optional.of(UserConstants.PASSWORD)); + + // WHEN + userDetails = service.loadUserByUsername(UserConstants.USERNAME); + + // THEN + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(userDetails.getUsername()) + .as("username") + .isEqualTo(UserConstants.USERNAME); + softly.assertThat(userDetails.getPassword()) + .as("password") + .isEqualTo(UserConstants.PASSWORD); + softly.assertThat(userDetails.isAccountNonExpired()) + .as("non expired") + .isTrue(); + softly.assertThat(userDetails.isAccountNonLocked()) + .as("non locked") + .isFalse(); + softly.assertThat(userDetails.isCredentialsNonExpired()) + .as("credentials non expired") + .isTrue(); + softly.assertThat(userDetails.isEnabled()) + .as("enabled") + .isTrue(); + + softly.assertThat(userDetails.getAuthorities()) + .as("authorities size") + .hasSize(1); + softly.assertThat(userDetails.getAuthorities()) + .extracting(GrantedAuthority::getAuthority) + .first() + .as("authority resource") + .isEqualTo(PermissionConstants.DATA_CREATE); + }); + } + + @Test + @DisplayName("When the user doesn't have authorities an exception is thrown") + void testLoadByUsername_NoPrivileges() { + final ThrowingCallable executable; + final Exception exception; + + // GIVEN + given(userRepository.findOne(UserConstants.USERNAME)).willReturn(Optional.of(Users.noPrivileges())); + + // WHEN + executable = () -> service.loadUserByUsername(UserConstants.USERNAME); + + // THEN + exception = Assertions.catchThrowableOfType(UsernameNotFoundException.class, executable); + + Assertions.assertThat(exception.getMessage()) + .isEqualTo("Username " + UserConstants.USERNAME + " has no authorities"); + } + + @Test + @DisplayName("When the user has the password expired it is returned") + void testLoadByUsername_PasswordExpired() { + final UserDetails userDetails; + + // GIVEN + given(userRepository.findOne(UserConstants.USERNAME)).willReturn(Optional.of(Users.passwordExpired())); + given(userRepository.findPassword(UserConstants.USERNAME)).willReturn(Optional.of(UserConstants.PASSWORD)); + + // WHEN + userDetails = service.loadUserByUsername(UserConstants.USERNAME); + + // THEN + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(userDetails.getUsername()) + .as("username") + .isEqualTo(UserConstants.USERNAME); + softly.assertThat(userDetails.getPassword()) + .as("password") + .isEqualTo(UserConstants.PASSWORD); + softly.assertThat(userDetails.isAccountNonExpired()) + .as("non expired") + .isTrue(); + softly.assertThat(userDetails.isAccountNonLocked()) + .as("non locked") + .isTrue(); + softly.assertThat(userDetails.isCredentialsNonExpired()) + .as("credentials non expired") + .isFalse(); + softly.assertThat(userDetails.isEnabled()) + .as("enabled") + .isTrue(); + + softly.assertThat(userDetails.getAuthorities()) + .as("authorities size") + .hasSize(1); + softly.assertThat(userDetails.getAuthorities()) + .extracting(GrantedAuthority::getAuthority) + .first() + .as("authority resource") + .isEqualTo(PermissionConstants.DATA_CREATE); + }); + } + + @Test + @DisplayName("When the user doesn't exist an exception is thrown") + void testLoadByUsername_UserNotExisting() { + final ThrowingCallable executable; + final Exception exception; + + // GIVEN + given(userRepository.findOne(UserConstants.USERNAME)).willReturn(Optional.empty()); + + // WHEN + executable = () -> service.loadUserByUsername(UserConstants.USERNAME); + + // THEN + exception = Assertions.catchThrowableOfType(UsernameNotFoundException.class, executable); + + Assertions.assertThat(exception.getMessage()) + .isEqualTo("Username " + UserConstants.USERNAME + " not found in database"); + } + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/PermissionConstants.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/PermissionConstants.java new file mode 100644 index 0000000..4cb54cd --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/PermissionConstants.java @@ -0,0 +1,8 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory; + +public final class PermissionConstants { + + public static final String DATA_CREATE = "CREATE:DATA"; + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Privileges.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Privileges.java new file mode 100644 index 0000000..8927183 --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Privileges.java @@ -0,0 +1,12 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory; + +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.Privilege; + +public final class Privileges { + + public static final Privilege create() { + return new Privilege(PermissionConstants.DATA_CREATE); + } + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/UserConstants.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/UserConstants.java new file mode 100644 index 0000000..9ae9d65 --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/UserConstants.java @@ -0,0 +1,18 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory; + +public final class UserConstants { + + public static final String EMAIL = "mail@somewhere.com"; + + public static final String NAME = "name"; + + public static final String PASSWORD = "1234"; + + public static final String USERNAME = "username"; + + private UserConstants() { + super(); + } + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Users.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Users.java new file mode 100644 index 0000000..74e1bcd --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Users.java @@ -0,0 +1,88 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory; + +import java.util.List; + +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; + +public final class Users { + + public static final User disabled() { + return User.builder() + .withPrivileges(List.of(Privileges.create())) + .withName(UserConstants.NAME) + .withUsername(UserConstants.USERNAME) + .withEmail(UserConstants.EMAIL) + .withEnabled(false) + .withExpired(false) + .withPasswordExpired(false) + .withLocked(false) + .build(); + } + + public static final User enabled() { + return User.builder() + .withPrivileges(List.of(Privileges.create())) + .withName(UserConstants.NAME) + .withUsername(UserConstants.USERNAME) + .withEmail(UserConstants.EMAIL) + .withEnabled(true) + .withExpired(false) + .withPasswordExpired(false) + .withLocked(false) + .build(); + } + + public static final User expired() { + return User.builder() + .withPrivileges(List.of(Privileges.create())) + .withName(UserConstants.NAME) + .withUsername(UserConstants.USERNAME) + .withEmail(UserConstants.EMAIL) + .withEnabled(true) + .withExpired(true) + .withPasswordExpired(false) + .withLocked(false) + .build(); + } + + public static final User locked() { + return User.builder() + .withPrivileges(List.of(Privileges.create())) + .withName(UserConstants.NAME) + .withUsername(UserConstants.USERNAME) + .withEmail(UserConstants.EMAIL) + .withEnabled(true) + .withExpired(false) + .withPasswordExpired(false) + .withLocked(true) + .build(); + } + + public static final User noPrivileges() { + return User.builder() + .withPrivileges(List.of()) + .withName(UserConstants.NAME) + .withUsername(UserConstants.USERNAME) + .withEmail(UserConstants.EMAIL) + .withEnabled(true) + .withExpired(false) + .withPasswordExpired(false) + .withLocked(false) + .build(); + } + + public static final User passwordExpired() { + return User.builder() + .withPrivileges(List.of(Privileges.create())) + .withName(UserConstants.NAME) + .withUsername(UserConstants.USERNAME) + .withEmail(UserConstants.EMAIL) + .withEnabled(true) + .withExpired(false) + .withPasswordExpired(true) + .withLocked(false) + .build(); + } + +} diff --git a/src/test/resources/db/queries/security/default_role.sql b/src/test/resources/db/queries/security/default_role.sql index f9edce3..67d8a7f 100644 --- a/src/test/resources/db/queries/security/default_role.sql +++ b/src/test/resources/db/queries/security/default_role.sql @@ -1,9 +1,9 @@ -- All the privileges INSERT INTO privileges (id, name) VALUES - (1, 'CREATE_DATA'), - (2, 'READ_DATA'), - (3, 'UPDATE_DATA'), - (4, 'DELETE_DATA'); + (1, 'CREATE:DATA'), + (2, 'READ:DATA'), + (3, 'UPDATE:DATA'), + (4, 'DELETE:DATA'); -- Default role INSERT INTO roles (id, name) VALUES From 5af9a6d936d75d0de606c8b3e8034bd659e85295 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 23:31:29 +0100 Subject: [PATCH 08/24] Renamed service --- .../security/ws/basic/config/SecurityConfig.java | 4 ++-- ...tailsService.java => UserDomainDetailsService.java} | 4 ++-- ...sService.java => TestUserDomainDetailsService.java} | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/{PersistentUserDetailsService.java => UserDomainDetailsService.java} (97%) rename src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/{TestPersistentUserDetailsService.java => TestUserDomainDetailsService.java} (97%) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java index 9c18c00..565d296 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java @@ -31,7 +31,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; -import com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase.PersistentUserDetailsService; +import com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase.UserDomainDetailsService; import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; /** @@ -70,7 +70,7 @@ public PasswordEncoder getPasswordEncoder() { */ @Bean("userDetailsService") public UserDetailsService getUserDetailsService(final UserRepository userRepository) { - return new PersistentUserDetailsService(userRepository); + return new UserDomainDetailsService(userRepository); } } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/PersistentUserDetailsService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java similarity index 97% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/PersistentUserDetailsService.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java index b04f7a6..d44b5bc 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/PersistentUserDetailsService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java @@ -67,7 +67,7 @@ * */ @Slf4j -public final class PersistentUserDetailsService implements UserDetailsService { +public final class UserDomainDetailsService implements UserDetailsService { /** * User repository. @@ -80,7 +80,7 @@ public final class PersistentUserDetailsService implements UserDetailsService { * @param userRepo * users repository */ - public PersistentUserDetailsService(final UserRepository userRepo) { + public UserDomainDetailsService(final UserRepository userRepo) { super(); userRepository = Objects.requireNonNull(userRepo, "Received a null pointer as user repository"); diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestPersistentUserDetailsService.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java similarity index 97% rename from src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestPersistentUserDetailsService.java rename to src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java index 579b24f..4838ff3 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestPersistentUserDetailsService.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java @@ -18,23 +18,23 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; -import com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase.PersistentUserDetailsService; +import com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase.UserDomainDetailsService; import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; import com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory.PermissionConstants; import com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory.UserConstants; import com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory.Users; @ExtendWith(MockitoExtension.class) -@DisplayName("PersistentUserDetailsService") -class TestPersistentUserDetailsService { +@DisplayName("UserDomainDetailsService") +class TestUserDomainDetailsService { @InjectMocks - private PersistentUserDetailsService service; + private UserDomainDetailsService service; @Mock private UserRepository userRepository; - public TestPersistentUserDetailsService() { + public TestUserDomainDetailsService() { super(); } From 512fd905b5897a14c792d17a365f118ce8efb94b Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 23:41:25 +0100 Subject: [PATCH 09/24] Cleanup --- .../inbound/jpa/model/PrivilegeEntity.java | 5 +--- .../adapter/inbound/jpa/model/UserEntity.java | 5 +--- .../inbound/jpa/model/package-info.java | 2 +- .../jpa/repository/JpaUserRepository.java | 28 ++++++++++++++++++ .../inbound/jpa/repository/package-info.java | 2 +- .../user/domain/model/package-info.java | 29 +++++++++++++++++++ .../user/domain/repository/package-info.java | 29 +++++++++++++++++++ 7 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/package-info.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/package-info.java diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java index a325838..3c2911c 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java @@ -36,10 +36,7 @@ import lombok.Data; /** - * Persistent privilege data. - *

- * JPA entities shouldn't end mixed up with the domain model. For this reason this class won't extend any generic - * interface, and instead is a JPA POJO. + * Privilege entity. * * @author Bernardo Martínez Garrido * diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java index f5e385e..95a373f 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java @@ -41,10 +41,7 @@ import lombok.Data; /** - * Persistent user data. - *

- * JPA entities shouldn't end mixed up with the domain model. For this reason this class won't extend any generic - * interface, and instead is a JPA POJO. + * User entity. * * @author Bernardo Martínez Garrido * diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java index 63b37d6..8347c86 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java @@ -23,7 +23,7 @@ */ /** - * User model. + * JPA user model. */ package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java index 7b19c80..46e616a 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java @@ -1,3 +1,26 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.repository; @@ -14,6 +37,11 @@ import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; +/** + * JPA implementation of the user repository. + * + * @author Bernardo Martínez Garrido + */ @Repository public final class JpaUserRepository implements UserRepository { diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java index 04e6398..fde66a2 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java @@ -23,7 +23,7 @@ */ /** - * User repositories. + * JPA user repositories. */ package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.repository; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/package-info.java new file mode 100644 index 0000000..7f3ab0f --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/package-info.java @@ -0,0 +1,29 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * User model. + */ + +package com.bernardomg.example.spring.security.ws.basic.security.user.domain.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/package-info.java new file mode 100644 index 0000000..cae654d --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/package-info.java @@ -0,0 +1,29 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * User repositories. + */ + +package com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository; From a9e3b2be154ef4c4c267cc14c2f89f7c3bad9365 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 23:44:17 +0100 Subject: [PATCH 10/24] Corrected Maven site version --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index fccd37c..251d145 100644 --- a/pom.xml +++ b/pom.xml @@ -135,6 +135,8 @@ ${project.basedir}/src/config/checkstyle/checkstyle-rules.xml + + 3.12.1 From c4189c967a47af4f67c0d73cedf5129c844d9cbf Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 23:46:20 +0100 Subject: [PATCH 11/24] Renamed class --- .../PlaceholderPersonRepository.java | 48 ------------ .../repository/UserPersonRepository.java | 74 +++++++++++++++++++ 2 files changed, 74 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/UserPersonRepository.java diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java deleted file mode 100644 index ef6880f..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/PlaceholderPersonRepository.java +++ /dev/null @@ -1,48 +0,0 @@ - -package com.bernardomg.example.spring.security.ws.basic.person.adapter.inbound.placeholder.repository; - -import java.util.Collection; -import java.util.Objects; - -import org.springframework.stereotype.Repository; - -import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; -import com.bernardomg.example.spring.security.ws.basic.person.domain.repository.PersonRepository; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Repository -public final class PlaceholderPersonRepository implements PersonRepository { - - private final UserRepository userRepository; - - public PlaceholderPersonRepository(final UserRepository userRepo) { - super(); - - userRepository = Objects.requireNonNull(userRepo, "Received a null pointer as user repository"); - } - - @Override - public final Collection findAll() { - final Collection persons; - - log.debug("Finding all the persons"); - - persons = userRepository.findAll() - .stream() - .map(this::toPerson) - .toList(); - - log.debug("Found all the persons: {}", persons); - - return persons; - } - - private final Person toPerson(final User user) { - return new Person(user.username(), user.name()); - } - -} diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/UserPersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/UserPersonRepository.java new file mode 100644 index 0000000..7db9571 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/UserPersonRepository.java @@ -0,0 +1,74 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.bernardomg.example.spring.security.ws.basic.person.adapter.inbound.placeholder.repository; + +import java.util.Collection; +import java.util.Objects; + +import org.springframework.stereotype.Repository; + +import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; +import com.bernardomg.example.spring.security.ws.basic.person.domain.repository.PersonRepository; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; + +import lombok.extern.slf4j.Slf4j; + +/** + * Person repository which takes the data from the users. + */ +@Slf4j +@Repository +public final class UserPersonRepository implements PersonRepository { + + private final UserRepository userRepository; + + public UserPersonRepository(final UserRepository userRepo) { + super(); + + userRepository = Objects.requireNonNull(userRepo, "Received a null pointer as user repository"); + } + + @Override + public final Collection findAll() { + final Collection persons; + + log.debug("Finding all the persons"); + + persons = userRepository.findAll() + .stream() + .map(this::toPerson) + .toList(); + + log.debug("Found all the persons: {}", persons); + + return persons; + } + + private final Person toPerson(final User user) { + return new Person(user.username(), user.name()); + } + +} From 90ebee668aafc1b9ee948c6d0940599148b99cde Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Mon, 9 Dec 2024 23:50:37 +0100 Subject: [PATCH 12/24] Cleanup --- .../ws/basic/config/WebSecurityConfig.java | 2 +- .../repository/UserPersonRepository.java | 2 +- .../inbound/user/repository/package-info.java | 29 +++++++++++++++++ .../rest/controller/package-info.java | 29 +++++++++++++++++ .../person/domain/model/package-info.java | 29 +++++++++++++++++ .../domain/repository/package-info.java | 29 +++++++++++++++++ .../person/usecase/service/package-info.java | 29 +++++++++++++++++ .../usecase/UserDomainDetailsService.java | 2 -- .../security/user/domain/model/User.java | 31 ------------------- .../WhitelistRequestCustomizer.java | 2 +- .../web/configuration/package-info.java | 29 +++++++++++++++++ ...ErrorResponseAuthenticationEntryPoint.java | 2 +- .../{ => web}/entrypoint/package-info.java | 4 +-- .../unit/TestUserDomainDetailsService.java | 2 +- 14 files changed, 181 insertions(+), 40 deletions(-) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/{placeholder => user}/repository/UserPersonRepository.java (98%) create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/package-info.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/package-info.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/package-info.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/package-info.java create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/package-info.java rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/{ => web}/configuration/WhitelistRequestCustomizer.java (99%) create mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/package-info.java rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/{ => web}/entrypoint/ErrorResponseAuthenticationEntryPoint.java (99%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/security/{ => web}/entrypoint/package-info.java (96%) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java index 45e9af7..1d6e4d1 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java @@ -37,7 +37,7 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.web.SecurityFilterChain; -import com.bernardomg.example.spring.security.ws.basic.security.configuration.WhitelistRequestCustomizer; +import com.bernardomg.example.spring.security.ws.basic.security.web.configuration.WhitelistRequestCustomizer; /** * Web security configuration. diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/UserPersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java similarity index 98% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/UserPersonRepository.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java index 7db9571..569a26e 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/placeholder/repository/UserPersonRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.person.adapter.inbound.placeholder.repository; +package com.bernardomg.example.spring.security.ws.basic.person.adapter.inbound.user.repository; import java.util.Collection; import java.util.Objects; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/package-info.java new file mode 100644 index 0000000..97a5d41 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/package-info.java @@ -0,0 +1,29 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * User-based person repository. + */ + +package com.bernardomg.example.spring.security.ws.basic.person.adapter.inbound.user.repository; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/package-info.java new file mode 100644 index 0000000..9b04236 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/package-info.java @@ -0,0 +1,29 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Person controller. + */ + +package com.bernardomg.example.spring.security.ws.basic.person.adapter.outbound.rest.controller; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/package-info.java new file mode 100644 index 0000000..64faad9 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/package-info.java @@ -0,0 +1,29 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Person model. + */ + +package com.bernardomg.example.spring.security.ws.basic.person.domain.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/package-info.java new file mode 100644 index 0000000..5d560e4 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/package-info.java @@ -0,0 +1,29 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Person repository. + */ + +package com.bernardomg.example.spring.security.ws.basic.person.domain.repository; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/package-info.java new file mode 100644 index 0000000..b16e414 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/package-info.java @@ -0,0 +1,29 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Person service. + */ + +package com.bernardomg.example.spring.security.ws.basic.person.usecase.service; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java index d44b5bc..f074d1a 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java @@ -134,8 +134,6 @@ private final GrantedAuthority toGrantedAuthority(final Privilege privilege) { * user to transform * @param password * user password - * @param authorities - * authorities for the user details * @return equivalent user details */ private final UserDetails toUserDetails(final User user, final String password) { diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java index 6829a29..2845796 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java @@ -25,7 +25,6 @@ package com.bernardomg.example.spring.security.ws.basic.security.user.domain.model; import java.util.Collection; -import java.util.Objects; import lombok.Builder; @@ -41,34 +40,4 @@ public record User(String email, boolean enabled, boolean expired, boolean locked, String name, boolean passwordExpired, Collection privileges, String username) { - public User(final String email, final boolean enabled, final boolean expired, final boolean locked, - final String name, final boolean passwordExpired, final Collection privileges, - final String username) { - if (Objects.nonNull(name)) { - this.name = name.trim(); - } else { - this.name = null; - } - - if (Objects.nonNull(username)) { - this.username = username.trim() - .toLowerCase(); - } else { - this.username = null; - } - - if (Objects.nonNull(email)) { - this.email = email.trim() - .toLowerCase(); - } else { - this.email = null; - } - - this.enabled = enabled; - this.expired = expired; - this.locked = locked; - this.passwordExpired = passwordExpired; - this.privileges = privileges; - } - } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/configuration/WhitelistRequestCustomizer.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/WhitelistRequestCustomizer.java similarity index 99% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/configuration/WhitelistRequestCustomizer.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/WhitelistRequestCustomizer.java index 1b6ccf8..e076370 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/configuration/WhitelistRequestCustomizer.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/WhitelistRequestCustomizer.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.configuration; +package com.bernardomg.example.spring.security.ws.basic.security.web.configuration; import java.util.Collection; import java.util.Objects; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/package-info.java new file mode 100644 index 0000000..6f192d8 --- /dev/null +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/package-info.java @@ -0,0 +1,29 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2023 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Security configuration classes. + */ + +package com.bernardomg.example.spring.security.ws.basic.security.web.configuration; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/entrypoint/ErrorResponseAuthenticationEntryPoint.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/ErrorResponseAuthenticationEntryPoint.java similarity index 99% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/entrypoint/ErrorResponseAuthenticationEntryPoint.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/ErrorResponseAuthenticationEntryPoint.java index 5f0b635..b891a73 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/entrypoint/ErrorResponseAuthenticationEntryPoint.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/ErrorResponseAuthenticationEntryPoint.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.entrypoint; +package com.bernardomg.example.spring.security.ws.basic.security.web.entrypoint; import java.io.IOException; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/entrypoint/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/package-info.java similarity index 96% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/entrypoint/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/package-info.java index 759b285..ec68857 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/entrypoint/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/package-info.java @@ -23,7 +23,7 @@ */ /** - * JWT entry points. + * Security entry points. */ -package com.bernardomg.example.spring.security.ws.basic.security.entrypoint; +package com.bernardomg.example.spring.security.ws.basic.security.web.entrypoint; diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java index 4838ff3..47b56ac 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java @@ -32,7 +32,7 @@ class TestUserDomainDetailsService { private UserDomainDetailsService service; @Mock - private UserRepository userRepository; + private UserRepository userRepository; public TestUserDomainDetailsService() { super(); From 9619e12b1b49a340844eaca720f0095dbd1cd262 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Thu, 12 Dec 2024 14:19:22 +0100 Subject: [PATCH 13/24] Changed REST endpoint --- .../rest/controller/PersonController.java | 2 +- .../resources/basic_auth.postman_collection | 37 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java index 491e275..eb7f97f 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java @@ -41,7 +41,7 @@ * */ @RestController -@RequestMapping("/rest/person") +@RequestMapping("/person") @AllArgsConstructor public class PersonController { diff --git a/src/test/resources/basic_auth.postman_collection b/src/test/resources/basic_auth.postman_collection index 54d5734..c47e628 100644 --- a/src/test/resources/basic_auth.postman_collection +++ b/src/test/resources/basic_auth.postman_collection @@ -1,9 +1,11 @@ { "info": { - "_postman_id": "b05c67a1-9e73-45f7-9e14-992c9c80d4a2", + "_postman_id": "d28cc57e-16ae-457e-b974-a3c656f32761", "name": "Basic auth", "description": "Requests using the basic HTTP authentication scheme. Which means sending the user and password hashed in the header.", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "29322077", + "_collection_link": "https://martian-astronaut-39097.postman.co/workspace/Security-examples~3c194cbc-99d2-481a-a2d3-07aae427b74c/collection/29322077-d28cc57e-16ae-457e-b974-a3c656f32761?action=share&source=collection_link&creator=29322077" }, "item": [ { @@ -26,7 +28,8 @@ " pm.expect(responseJson.errors[0].message).to.eql('Unauthorized');\r", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -34,10 +37,9 @@ "method": "GET", "header": [], "url": { - "raw": "/rest/entity", + "raw": "/person", "path": [ - "rest", - "entity" + "person" ] } }, @@ -86,7 +88,8 @@ " pm.expect(responseJson.errors[0].message).to.eql('Unauthorized');\r", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -94,10 +97,9 @@ "method": "GET", "header": [], "url": { - "raw": "/rest/entity", + "raw": "/person", "path": [ - "rest", - "entity" + "person" ] } }, @@ -155,7 +157,8 @@ " pm.expect(responseJson).to.have.property('content');\r", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -163,10 +166,9 @@ "method": "GET", "header": [], "url": { - "raw": "/rest/entity", + "raw": "/person", "path": [ - "rest", - "entity" + "person" ] } }, @@ -230,7 +232,8 @@ " pm.expect(responseJson.errors[0].message).to.eql('Unauthorized');\r", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -238,9 +241,9 @@ "method": "GET", "header": [], "url": { - "raw": "/entity", + "raw": "/person", "path": [ - "entity" + "person" ] } }, From 50d6a6aabdb134dc6ef0cbd32ef8a2e258db666d Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Thu, 12 Dec 2024 14:28:35 +0100 Subject: [PATCH 14/24] Corrected test --- .../ws/basic/config/SecurityConfig.java | 4 +- .../ws/basic/config/WebSecurityConfig.java | 2 +- .../user/repository/UserPersonRepository.java | 4 +- .../web/configuration/package-info.java | 29 ------- .../audit/AuditEventLogger.java | 2 +- .../audit/package-info.java | 2 +- .../UserDomainDetailsService.java | 8 +- .../userdetails}/package-info.java | 2 +- ...ErrorResponseAuthenticationEntryPoint.java | 2 +- .../web}/WhitelistRequestCustomizer.java | 2 +- .../web}/package-info.java | 2 +- .../inbound/jpa/model/PrivilegeEntity.java | 2 +- .../adapter/inbound/jpa/model/RoleEntity.java | 2 +- .../adapter/inbound/jpa/model/UserEntity.java | 2 +- .../inbound/jpa/model/package-info.java | 2 +- .../jpa/repository/JpaUserRepository.java | 14 +-- .../jpa/repository/UserSpringRepository.java | 4 +- .../inbound/jpa/repository/package-info.java | 2 +- .../user/domain/model/Privilege.java | 2 +- .../user/domain/model/User.java | 2 +- .../user/domain/model/package-info.java | 2 +- .../domain/repository/UserRepository.java | 4 +- .../user/domain/repository/package-info.java | 2 +- ...trollerSecurityCredentialsExpiredUser.java | 68 --------------- ...eEntityControllerSecurityDisabledUser.java | 68 --------------- ...leEntityControllerSecurityExpiredUser.java | 68 --------------- ...pleEntityControllerSecurityLockedUser.java | 68 --------------- .../ITPersonControllerSecurity.java} | 86 +++++++++++++++---- .../test/config/factory/Privileges.java | 12 --- .../user/config/CredentialsExpiredUser.java | 20 +++++ .../security/user/config/DisabledUser.java | 20 +++++ .../security/user/config/ExpiredUser.java | 20 +++++ .../test/security/user/config/LockedUser.java | 20 +++++ .../user/config/UserWithoutPermissions.java | 20 +++++ .../test/security/user/config/ValidUser.java | 20 +++++ .../unit/TestUserDomainDetailsService.java | 12 +-- .../config/factory/PermissionConstants.java | 2 +- .../test/user/config/factory/Privileges.java | 12 +++ .../config/factory/UserConstants.java | 2 +- .../test => user}/config/factory/Users.java | 4 +- .../integration/ITUserRepository.java | 6 +- 41 files changed, 250 insertions(+), 377 deletions(-) delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/package-info.java rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => springframework}/audit/AuditEventLogger.java (97%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => springframework}/audit/package-info.java (93%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security/springframework/usecase => springframework/userdetails}/UserDomainDetailsService.java (94%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security/springframework/usecase => springframework/userdetails}/package-info.java (93%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security/web/entrypoint => springframework/web}/ErrorResponseAuthenticationEntryPoint.java (97%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security/web/configuration => springframework/web}/WhitelistRequestCustomizer.java (96%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security/web/entrypoint => springframework/web}/package-info.java (93%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/adapter/inbound/jpa/model/PrivilegeEntity.java (96%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/adapter/inbound/jpa/model/RoleEntity.java (96%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/adapter/inbound/jpa/model/UserEntity.java (97%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/adapter/inbound/jpa/model/package-info.java (92%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/adapter/inbound/jpa/repository/JpaUserRepository.java (81%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/adapter/inbound/jpa/repository/UserSpringRepository.java (89%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/adapter/inbound/jpa/repository/package-info.java (92%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/domain/model/Privilege.java (93%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/domain/model/User.java (94%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/domain/model/package-info.java (93%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/domain/repository/UserRepository.java (91%) rename src/main/java/com/bernardomg/example/spring/security/ws/basic/{security => }/user/domain/repository/package-info.java (93%) delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityCredentialsExpiredUser.java delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityDisabledUser.java delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityExpiredUser.java delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityLockedUser.java rename src/test/java/com/bernardomg/example/spring/security/ws/basic/test/{domain/entity/controller/integration/ITExampleEntityControllerSecurity.java => person/adapter/outbound/rest/controller/integration/ITPersonControllerSecurity.java} (53%) delete mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Privileges.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/CredentialsExpiredUser.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/DisabledUser.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/ExpiredUser.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/LockedUser.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/UserWithoutPermissions.java create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/ValidUser.java rename src/test/java/com/bernardomg/example/spring/security/ws/basic/test/{security/springframework/usecase => springframework/userdetails}/unit/TestUserDomainDetailsService.java (94%) rename src/test/java/com/bernardomg/example/spring/security/ws/basic/test/{security/test => user}/config/factory/PermissionConstants.java (54%) create mode 100644 src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/Privileges.java rename src/test/java/com/bernardomg/example/spring/security/ws/basic/test/{security/test => user}/config/factory/UserConstants.java (77%) rename src/test/java/com/bernardomg/example/spring/security/ws/basic/test/{security/test => user}/config/factory/Users.java (93%) rename src/test/java/com/bernardomg/example/spring/security/ws/basic/test/{security => }/user/domain/repository/integration/ITUserRepository.java (80%) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java index 565d296..a02a5d6 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java @@ -31,8 +31,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; -import com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase.UserDomainDetailsService; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; +import com.bernardomg.example.spring.security.ws.basic.springframework.userdetails.UserDomainDetailsService; +import com.bernardomg.example.spring.security.ws.basic.user.domain.repository.UserRepository; /** * Security configuration. diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java index 1d6e4d1..744cf70 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java @@ -37,7 +37,7 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.web.SecurityFilterChain; -import com.bernardomg.example.spring.security.ws.basic.security.web.configuration.WhitelistRequestCustomizer; +import com.bernardomg.example.spring.security.ws.basic.springframework.web.WhitelistRequestCustomizer; /** * Web security configuration. diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java index 569a26e..4fe2050 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java @@ -31,8 +31,8 @@ import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; import com.bernardomg.example.spring.security.ws.basic.person.domain.repository.PersonRepository; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; +import com.bernardomg.example.spring.security.ws.basic.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.user.domain.repository.UserRepository; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/package-info.java deleted file mode 100644 index 6f192d8..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/** - * Security configuration classes. - */ - -package com.bernardomg.example.spring.security.ws.basic.security.web.configuration; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/audit/AuditEventLogger.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/AuditEventLogger.java similarity index 97% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/audit/AuditEventLogger.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/AuditEventLogger.java index b3b342b..24670d9 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/audit/AuditEventLogger.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/AuditEventLogger.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.audit; +package com.bernardomg.example.spring.security.ws.basic.springframework.audit; import java.util.Map; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/audit/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/package-info.java similarity index 93% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/audit/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/package-info.java index e45fc71..79d6066 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/audit/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/package-info.java @@ -26,4 +26,4 @@ * Audit components. */ -package com.bernardomg.example.spring.security.ws.basic.security.audit; +package com.bernardomg.example.spring.security.ws.basic.springframework.audit; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/UserDomainDetailsService.java similarity index 94% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/UserDomainDetailsService.java index f074d1a..ef1ebe7 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/UserDomainDetailsService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/UserDomainDetailsService.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase; +package com.bernardomg.example.spring.security.ws.basic.springframework.userdetails; import java.util.Collection; import java.util.Locale; @@ -34,9 +34,9 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.Privilege; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; +import com.bernardomg.example.spring.security.ws.basic.user.domain.model.Privilege; +import com.bernardomg.example.spring.security.ws.basic.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.user.domain.repository.UserRepository; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/package-info.java similarity index 93% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/package-info.java index c3c945d..bee7e91 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/springframework/usecase/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/package-info.java @@ -26,4 +26,4 @@ * User details components. */ -package com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase; +package com.bernardomg.example.spring.security.ws.basic.springframework.userdetails; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/ErrorResponseAuthenticationEntryPoint.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/ErrorResponseAuthenticationEntryPoint.java similarity index 97% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/ErrorResponseAuthenticationEntryPoint.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/ErrorResponseAuthenticationEntryPoint.java index b891a73..b2536bf 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/ErrorResponseAuthenticationEntryPoint.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/ErrorResponseAuthenticationEntryPoint.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.web.entrypoint; +package com.bernardomg.example.spring.security.ws.basic.springframework.web; import java.io.IOException; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/WhitelistRequestCustomizer.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/WhitelistRequestCustomizer.java similarity index 96% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/WhitelistRequestCustomizer.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/WhitelistRequestCustomizer.java index e076370..94aaa9e 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/configuration/WhitelistRequestCustomizer.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/WhitelistRequestCustomizer.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.web.configuration; +package com.bernardomg.example.spring.security.ws.basic.springframework.web; import java.util.Collection; import java.util.Objects; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/package-info.java similarity index 93% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/package-info.java index ec68857..b996860 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/web/entrypoint/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/package-info.java @@ -26,4 +26,4 @@ * Security entry points. */ -package com.bernardomg.example.spring.security.ws.basic.security.web.entrypoint; +package com.bernardomg.example.spring.security.ws.basic.springframework.web; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/PrivilegeEntity.java similarity index 96% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/PrivilegeEntity.java index 3c2911c..f6f7fa0 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/PrivilegeEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/PrivilegeEntity.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model; +package com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model; import java.io.Serializable; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/RoleEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java similarity index 96% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/RoleEntity.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java index 455440a..47e5ee2 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/RoleEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model; +package com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model; import java.io.Serializable; import java.util.Collection; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java similarity index 97% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java index 95a373f..8e26fac 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/UserEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model; +package com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model; import java.io.Serializable; import java.util.Collection; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/package-info.java similarity index 92% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/package-info.java index 8347c86..9910630 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/model/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/package-info.java @@ -26,4 +26,4 @@ * JPA user model. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model; +package com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java similarity index 81% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java index 46e616a..56d1d0c 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/JpaUserRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.repository; +package com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.repository; import java.util.Collection; import java.util.Objects; @@ -30,12 +30,12 @@ import org.springframework.stereotype.Repository; -import com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model.PrivilegeEntity; -import com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model.RoleEntity; -import com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model.UserEntity; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.Privilege; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; +import com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model.PrivilegeEntity; +import com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model.RoleEntity; +import com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model.UserEntity; +import com.bernardomg.example.spring.security.ws.basic.user.domain.model.Privilege; +import com.bernardomg.example.spring.security.ws.basic.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.user.domain.repository.UserRepository; /** * JPA implementation of the user repository. diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/UserSpringRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/UserSpringRepository.java similarity index 89% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/UserSpringRepository.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/UserSpringRepository.java index 0496c18..05a3bd0 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/UserSpringRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/UserSpringRepository.java @@ -22,13 +22,13 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.repository; +package com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.repository; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.model.UserEntity; +import com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model.UserEntity; /** * Repository for users. diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/package-info.java similarity index 92% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/package-info.java index fde66a2..f91ecc6 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/adapter/inbound/jpa/repository/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/package-info.java @@ -26,4 +26,4 @@ * JPA user repositories. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.adapter.inbound.jpa.repository; +package com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.repository; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/Privilege.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/Privilege.java similarity index 93% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/Privilege.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/Privilege.java index be3ecf2..14ca973 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/Privilege.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/Privilege.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.domain.model; +package com.bernardomg.example.spring.security.ws.basic.user.domain.model; /** * Privilege. diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java similarity index 94% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java index 2845796..15f7690 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/User.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.domain.model; +package com.bernardomg.example.spring.security.ws.basic.user.domain.model; import java.util.Collection; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/package-info.java similarity index 93% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/package-info.java index 7f3ab0f..5b94143 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/model/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/package-info.java @@ -26,4 +26,4 @@ * User model. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.domain.model; +package com.bernardomg.example.spring.security.ws.basic.user.domain.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/UserRepository.java similarity index 91% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/UserRepository.java index 68b94d1..66d83b5 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/UserRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/UserRepository.java @@ -22,12 +22,12 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository; +package com.bernardomg.example.spring.security.ws.basic.user.domain.repository; import java.util.Collection; import java.util.Optional; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.user.domain.model.User; /** * User repository. diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/package-info.java similarity index 93% rename from src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/package-info.java rename to src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/package-info.java index cae654d..bdc373c 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/security/user/domain/repository/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/package-info.java @@ -26,4 +26,4 @@ * User repositories. */ -package com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository; +package com.bernardomg.example.spring.security.ws.basic.user.domain.repository; diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityCredentialsExpiredUser.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityCredentialsExpiredUser.java deleted file mode 100644 index 03adc1d..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityCredentialsExpiredUser.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.test.domain.entity.controller.integration; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.MvcIntegrationTest; - -@MvcIntegrationTest -@DisplayName("Example entity controller - security - credentials expired user") -@Sql({ "/db/queries/user/credentials_expired.sql", "/db/queries/security/default_role.sql" }) -public final class ITExampleEntityControllerSecurityCredentialsExpiredUser { - - @Autowired - private MockMvc mockMvc; - - public ITExampleEntityControllerSecurityCredentialsExpiredUser() { - super(); - } - - @Test - @DisplayName("An authenticated request is not authorized") - public final void testGet_authenticated_notAuthorized() throws Exception { - final ResultActions result; - - result = mockMvc.perform(getRequestAuthorized()); - - // The operation was accepted - result.andExpect(MockMvcResultMatchers.status() - .isUnauthorized()); - } - - private final RequestBuilder getRequestAuthorized() { - return MockMvcRequestBuilders.get("/rest/entity") - .header("Authorization", "Basic YWRtaW46MTIzNA=="); - } - -} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityDisabledUser.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityDisabledUser.java deleted file mode 100644 index e47b313..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityDisabledUser.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.test.domain.entity.controller.integration; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.MvcIntegrationTest; - -@MvcIntegrationTest -@DisplayName("Example entity controller - security - disabled user") -@Sql({ "/db/queries/user/disabled.sql", "/db/queries/security/default_role.sql" }) -public final class ITExampleEntityControllerSecurityDisabledUser { - - @Autowired - private MockMvc mockMvc; - - public ITExampleEntityControllerSecurityDisabledUser() { - super(); - } - - @Test - @DisplayName("An authenticated request is not authorized") - public final void testGet_authenticated_notAuthorized() throws Exception { - final ResultActions result; - - result = mockMvc.perform(getRequestAuthorized()); - - // The operation was accepted - result.andExpect(MockMvcResultMatchers.status() - .isUnauthorized()); - } - - private final RequestBuilder getRequestAuthorized() { - return MockMvcRequestBuilders.get("/rest/entity") - .header("Authorization", "Basic YWRtaW46MTIzNA=="); - } - -} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityExpiredUser.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityExpiredUser.java deleted file mode 100644 index ae72403..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityExpiredUser.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.test.domain.entity.controller.integration; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.MvcIntegrationTest; - -@MvcIntegrationTest -@DisplayName("Example entity controller - security - expired user") -@Sql({ "/db/queries/user/expired.sql", "/db/queries/security/default_role.sql" }) -public final class ITExampleEntityControllerSecurityExpiredUser { - - @Autowired - private MockMvc mockMvc; - - public ITExampleEntityControllerSecurityExpiredUser() { - super(); - } - - @Test - @DisplayName("An authenticated request is not authorized") - public final void testGet_authenticated_notAuthorized() throws Exception { - final ResultActions result; - - result = mockMvc.perform(getRequestAuthorized()); - - // The operation was accepted - result.andExpect(MockMvcResultMatchers.status() - .isUnauthorized()); - } - - private final RequestBuilder getRequestAuthorized() { - return MockMvcRequestBuilders.get("/rest/entity") - .header("Authorization", "Basic YWRtaW46MTIzNA=="); - } - -} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityLockedUser.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityLockedUser.java deleted file mode 100644 index b3600f5..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurityLockedUser.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2023 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.test.domain.entity.controller.integration; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.MvcIntegrationTest; - -@MvcIntegrationTest -@DisplayName("Example entity controller - security - locked user") -@Sql({ "/db/queries/user/locked.sql", "/db/queries/security/default_role.sql" }) -public final class ITExampleEntityControllerSecurityLockedUser { - - @Autowired - private MockMvc mockMvc; - - public ITExampleEntityControllerSecurityLockedUser() { - super(); - } - - @Test - @DisplayName("An authenticated request is not authorized") - public final void testGet_authenticated_notAuthorized() throws Exception { - final ResultActions result; - - result = mockMvc.perform(getRequestAuthorized()); - - // The operation was accepted - result.andExpect(MockMvcResultMatchers.status() - .isUnauthorized()); - } - - private final RequestBuilder getRequestAuthorized() { - return MockMvcRequestBuilders.get("/rest/entity") - .header("Authorization", "Basic YWRtaW46MTIzNA=="); - } - -} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurity.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/person/adapter/outbound/rest/controller/integration/ITPersonControllerSecurity.java similarity index 53% rename from src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurity.java rename to src/test/java/com/bernardomg/example/spring/security/ws/basic/test/person/adapter/outbound/rest/controller/integration/ITPersonControllerSecurity.java index ec7d417..bbf39cd 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/domain/entity/controller/integration/ITExampleEntityControllerSecurity.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/person/adapter/outbound/rest/controller/integration/ITPersonControllerSecurity.java @@ -22,12 +22,11 @@ * SOFTWARE. */ -package com.bernardomg.example.spring.security.ws.basic.test.domain.entity.controller.integration; +package com.bernardomg.example.spring.security.ws.basic.test.person.adapter.outbound.rest.controller.integration; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.RequestBuilder; import org.springframework.test.web.servlet.ResultActions; @@ -35,22 +34,33 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.MvcIntegrationTest; +import com.bernardomg.example.spring.security.ws.basic.test.security.user.config.CredentialsExpiredUser; +import com.bernardomg.example.spring.security.ws.basic.test.security.user.config.DisabledUser; +import com.bernardomg.example.spring.security.ws.basic.test.security.user.config.LockedUser; +import com.bernardomg.example.spring.security.ws.basic.test.security.user.config.ValidUser; @MvcIntegrationTest @DisplayName("Example entity controller - security") -@Sql({ "/db/queries/user/single.sql", "/db/queries/security/default_role.sql" }) -public final class ITExampleEntityControllerSecurity { +final class ITPersonControllerSecurity { + + private static final String ROUTE = "/person"; @Autowired - private MockMvc mockMvc; + private MockMvc mockMvc; - public ITExampleEntityControllerSecurity() { - super(); + private final RequestBuilder getRequest() { + return MockMvcRequestBuilders.get(ROUTE); + } + + private final RequestBuilder getRequestAuthorized() { + return MockMvcRequestBuilders.get(ROUTE) + .header("Authorization", "Basic YWRtaW46MTIzNA=="); } @Test @DisplayName("An authenticated request is authorized") - public final void testGet_authorized() throws Exception { + @ValidUser + void testGet_authorized() throws Exception { final ResultActions result; result = mockMvc.perform(getRequestAuthorized()); @@ -61,24 +71,68 @@ public final void testGet_authorized() throws Exception { } @Test - @DisplayName("A not authenticated request is not authorized") - public final void testGet_unauthorized() throws Exception { + @DisplayName("A locked user is not authorized") + @CredentialsExpiredUser + void testGet_credentialsExpired() throws Exception { final ResultActions result; - result = mockMvc.perform(getRequest()); + result = mockMvc.perform(getRequestAuthorized()); // The operation was accepted result.andExpect(MockMvcResultMatchers.status() .isUnauthorized()); } - private final RequestBuilder getRequest() { - return MockMvcRequestBuilders.get("/rest/person"); + @Test + @DisplayName("An expired user is not authorized") + @DisabledUser + void testGet_expired() throws Exception { + final ResultActions result; + + result = mockMvc.perform(getRequestAuthorized()); + + // The operation was accepted + result.andExpect(MockMvcResultMatchers.status() + .isUnauthorized()); } - private final RequestBuilder getRequestAuthorized() { - return MockMvcRequestBuilders.get("/rest/person") - .header("Authorization", "Basic YWRtaW46MTIzNA=="); + @Test + @DisplayName("A locked user is not authorized") + @LockedUser + void testGet_locked() throws Exception { + final ResultActions result; + + result = mockMvc.perform(getRequestAuthorized()); + + // The operation was accepted + result.andExpect(MockMvcResultMatchers.status() + .isUnauthorized()); + } + + @Test + @DisplayName("A disabled user is not authorized") + @DisabledUser + void testGet_notAuthorized() throws Exception { + final ResultActions result; + + result = mockMvc.perform(getRequestAuthorized()); + + // The operation was accepted + result.andExpect(MockMvcResultMatchers.status() + .isUnauthorized()); + } + + @Test + @DisplayName("A not authenticated request is not authorized") + @ValidUser + void testGet_unauthorized() throws Exception { + final ResultActions result; + + result = mockMvc.perform(getRequest()); + + // The operation was accepted + result.andExpect(MockMvcResultMatchers.status() + .isUnauthorized()); } } diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Privileges.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Privileges.java deleted file mode 100644 index 8927183..0000000 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Privileges.java +++ /dev/null @@ -1,12 +0,0 @@ - -package com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory; - -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.Privilege; - -public final class Privileges { - - public static final Privilege create() { - return new Privilege(PermissionConstants.DATA_CREATE); - } - -} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/CredentialsExpiredUser.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/CredentialsExpiredUser.java new file mode 100644 index 0000000..a06498d --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/CredentialsExpiredUser.java @@ -0,0 +1,20 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.user.config; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.jdbc.Sql; + +@Sql({ "/db/queries/user/credentials_expired.sql", "/db/queries/security/default_role.sql" }) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface CredentialsExpiredUser { + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/DisabledUser.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/DisabledUser.java new file mode 100644 index 0000000..0038488 --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/DisabledUser.java @@ -0,0 +1,20 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.user.config; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.jdbc.Sql; + +@Sql({ "/db/queries/user/disabled.sql", "/db/queries/security/default_role.sql" }) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface DisabledUser { + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/ExpiredUser.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/ExpiredUser.java new file mode 100644 index 0000000..78048e4 --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/ExpiredUser.java @@ -0,0 +1,20 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.user.config; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.jdbc.Sql; + +@Sql({ "/db/queries/user/expired.sql", "/db/queries/security/default_role.sql" }) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface ExpiredUser { + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/LockedUser.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/LockedUser.java new file mode 100644 index 0000000..4eec58c --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/LockedUser.java @@ -0,0 +1,20 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.user.config; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.jdbc.Sql; + +@Sql({ "/db/queries/user/locked.sql", "/db/queries/security/default_role.sql" }) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface LockedUser { + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/UserWithoutPermissions.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/UserWithoutPermissions.java new file mode 100644 index 0000000..f28c449 --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/UserWithoutPermissions.java @@ -0,0 +1,20 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.user.config; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.jdbc.Sql; + +@Sql({ "/db/queries/user/single.sql" }) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface UserWithoutPermissions { + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/ValidUser.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/ValidUser.java new file mode 100644 index 0000000..f221993 --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/config/ValidUser.java @@ -0,0 +1,20 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.security.user.config; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.jdbc.Sql; + +@Sql({ "/db/queries/user/single.sql", "/db/queries/security/default_role.sql" }) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface ValidUser { + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/springframework/userdetails/unit/TestUserDomainDetailsService.java similarity index 94% rename from src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java rename to src/test/java/com/bernardomg/example/spring/security/ws/basic/test/springframework/userdetails/unit/TestUserDomainDetailsService.java index 47b56ac..6c2faa8 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/springframework/usecase/unit/TestUserDomainDetailsService.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/springframework/userdetails/unit/TestUserDomainDetailsService.java @@ -1,5 +1,5 @@ -package com.bernardomg.example.spring.security.ws.basic.test.security.springframework.usecase.unit; +package com.bernardomg.example.spring.security.ws.basic.test.springframework.userdetails.unit; import static org.mockito.BDDMockito.given; @@ -18,11 +18,11 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; -import com.bernardomg.example.spring.security.ws.basic.security.springframework.usecase.UserDomainDetailsService; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; -import com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory.PermissionConstants; -import com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory.UserConstants; -import com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory.Users; +import com.bernardomg.example.spring.security.ws.basic.springframework.userdetails.UserDomainDetailsService; +import com.bernardomg.example.spring.security.ws.basic.test.user.config.factory.PermissionConstants; +import com.bernardomg.example.spring.security.ws.basic.test.user.config.factory.UserConstants; +import com.bernardomg.example.spring.security.ws.basic.test.user.config.factory.Users; +import com.bernardomg.example.spring.security.ws.basic.user.domain.repository.UserRepository; @ExtendWith(MockitoExtension.class) @DisplayName("UserDomainDetailsService") diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/PermissionConstants.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/PermissionConstants.java similarity index 54% rename from src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/PermissionConstants.java rename to src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/PermissionConstants.java index 4cb54cd..e54988c 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/PermissionConstants.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/PermissionConstants.java @@ -1,5 +1,5 @@ -package com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory; +package com.bernardomg.example.spring.security.ws.basic.test.user.config.factory; public final class PermissionConstants { diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/Privileges.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/Privileges.java new file mode 100644 index 0000000..aa11f6f --- /dev/null +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/Privileges.java @@ -0,0 +1,12 @@ + +package com.bernardomg.example.spring.security.ws.basic.test.user.config.factory; + +import com.bernardomg.example.spring.security.ws.basic.user.domain.model.Privilege; + +public final class Privileges { + + public static final Privilege create() { + return new Privilege(PermissionConstants.DATA_CREATE); + } + +} diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/UserConstants.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/UserConstants.java similarity index 77% rename from src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/UserConstants.java rename to src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/UserConstants.java index 9ae9d65..e4daf4b 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/UserConstants.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/UserConstants.java @@ -1,5 +1,5 @@ -package com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory; +package com.bernardomg.example.spring.security.ws.basic.test.user.config.factory; public final class UserConstants { diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Users.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/Users.java similarity index 93% rename from src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Users.java rename to src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/Users.java index 74e1bcd..807770b 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/test/config/factory/Users.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/config/factory/Users.java @@ -1,9 +1,9 @@ -package com.bernardomg.example.spring.security.ws.basic.test.security.test.config.factory; +package com.bernardomg.example.spring.security.ws.basic.test.user.config.factory; import java.util.List; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.user.domain.model.User; public final class Users { diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/domain/repository/integration/ITUserRepository.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/domain/repository/integration/ITUserRepository.java similarity index 80% rename from src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/domain/repository/integration/ITUserRepository.java rename to src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/domain/repository/integration/ITUserRepository.java index fe2568f..0dde4f7 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/security/user/domain/repository/integration/ITUserRepository.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/domain/repository/integration/ITUserRepository.java @@ -1,5 +1,5 @@ -package com.bernardomg.example.spring.security.ws.basic.test.security.user.domain.repository.integration; +package com.bernardomg.example.spring.security.ws.basic.test.user.domain.repository.integration; import java.util.Optional; @@ -9,9 +9,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.jdbc.Sql; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.model.User; -import com.bernardomg.example.spring.security.ws.basic.security.user.domain.repository.UserRepository; import com.bernardomg.example.spring.security.ws.basic.test.config.annotation.IntegrationTest; +import com.bernardomg.example.spring.security.ws.basic.user.domain.model.User; +import com.bernardomg.example.spring.security.ws.basic.user.domain.repository.UserRepository; @IntegrationTest @DisplayName("User repository") From f2f2148061db9e7308064987204566f8c90e0ded Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 00:58:08 +0100 Subject: [PATCH 15/24] Corrected assertions --- pom.xml | 14 ++++++++++++++ .../repository/integration/ITUserRepository.java | 13 ++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 251d145..80791f3 100644 --- a/pom.xml +++ b/pom.xml @@ -123,6 +123,7 @@ + 3.26.3 0.1.5 3.4.0 6.2.0 @@ -459,6 +460,19 @@ mockito-core test + + + org.mockito + mockito-junit-jupiter + test + + + + org.assertj + assertj-core + ${assertj.version} + test + org.springframework diff --git a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/domain/repository/integration/ITUserRepository.java b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/domain/repository/integration/ITUserRepository.java index 0dde4f7..5337962 100644 --- a/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/domain/repository/integration/ITUserRepository.java +++ b/src/test/java/com/bernardomg/example/spring/security/ws/basic/test/user/domain/repository/integration/ITUserRepository.java @@ -3,7 +3,7 @@ import java.util.Optional; -import org.junit.jupiter.api.Assertions; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -32,9 +32,11 @@ public void testFindForUser_existing() { result = repository.findOne("admin"); - Assertions.assertTrue(result.isPresent()); - Assertions.assertEquals("admin", result.get() - .username()); + Assertions.assertThat(result) + .isPresent(); + Assertions.assertThat("admin") + .isEqualTo(result.get() + .username()); } @Test @@ -44,7 +46,8 @@ public void testFindForUser_notExisting() { result = repository.findOne("abc"); - Assertions.assertFalse(result.isPresent()); + Assertions.assertThat(result) + .isEmpty(); } } From 87bf268a51ddaf74d9df43f1e68e6be9f2cbb617 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 01:23:13 +0100 Subject: [PATCH 16/24] Fixed audit endpoint config --- src/main/resources/application.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e79d2b9..10e5979 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,7 +15,4 @@ management: endpoints: web: exposure: - include: auditevents - enabled-by-default: false - auditevents: - enabled: true \ No newline at end of file + include: auditevents \ No newline at end of file From df9161dd8f84531856bf19865ff6a062fba88675 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 01:27:01 +0100 Subject: [PATCH 17/24] Added banner --- src/main/resources/banner.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/resources/banner.txt diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 0000000..db60dac --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,9 @@ + ____ _ _ _ _ _ _ _ + | _ \ (_) /\ | | | | | | (_) | | (_) + | |_) | __ _ ___ _ ___ / \ _ _| |_| |__ ___ _ __ | |_ _ ___ __ _| |_ _ ___ _ __ + | _ < / _` / __| |/ __| / /\ \| | | | __| '_ \ / _ \ '_ \| __| |/ __/ _` | __| |/ _ \| '_ \ + | |_) | (_| \__ \ | (__ / ____ \ |_| | |_| | | | __/ | | | |_| | (_| (_| | |_| | (_) | | | | + |____/ \__,_|___/_|\___| /_/ \_\__,_|\__|_| |_|\___|_| |_|\__|_|\___\__,_|\__|_|\___/|_| |_| + +${application.title} ${application.version} +Powered by Spring Boot ${spring-boot.version} From 5efa86d8b39224c1c587bdb22b51a86272cd29d2 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 01:47:57 +0100 Subject: [PATCH 18/24] Fixed config --- .../security/ws/basic/config/WebSecurityConfig.java | 8 ++++++-- .../adapter/inbound/jpa/repository/JpaUserRepository.java | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java index 744cf70..74bbbb9 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java @@ -28,15 +28,16 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; import org.springframework.security.config.annotation.web.configurers.FormLoginConfigurer; import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer; +import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.web.SecurityFilterChain; +import com.bernardomg.example.spring.security.ws.basic.springframework.web.ErrorResponseAuthenticationEntryPoint; import com.bernardomg.example.spring.security.ws.basic.springframework.web.WhitelistRequestCustomizer; /** @@ -77,8 +78,11 @@ public SecurityFilterChain getWebSecurityFilterChain(final HttpSecurity http, .cors(cors -> {}) .formLogin(FormLoginConfigurer::disable) .logout(LogoutConfigurer::disable) + .sessionManagement(t -> t.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // Activates HTTP Basic authentication - .httpBasic(Customizer.withDefaults()); + .httpBasic(t -> + // Return an error response on an auth failure + t.authenticationEntryPoint(new ErrorResponseAuthenticationEntryPoint())); http.userDetailsService(userDetailsService); diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java index 56d1d0c..2196e19 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java @@ -29,6 +29,7 @@ import java.util.Optional; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model.PrivilegeEntity; import com.bernardomg.example.spring.security.ws.basic.user.adapter.inbound.jpa.model.RoleEntity; @@ -43,6 +44,7 @@ * @author Bernardo Martínez Garrido */ @Repository +@Transactional public final class JpaUserRepository implements UserRepository { private final UserSpringRepository userSpringRepository; From 8331e73b5573833ba47ecae93302a675293a5fe9 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 01:48:50 +0100 Subject: [PATCH 19/24] Updated postman config --- src/test/resources/basic_auth.postman_collection | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/test/resources/basic_auth.postman_collection b/src/test/resources/basic_auth.postman_collection index c47e628..dde0475 100644 --- a/src/test/resources/basic_auth.postman_collection +++ b/src/test/resources/basic_auth.postman_collection @@ -23,9 +23,7 @@ "});\r", "\r", "pm.test(\"The response contains the error properties\", () => {\r", - " const responseJson = pm.response.json();\r", - " pm.expect(responseJson.errors).to.have.lengthOf(1);\r", - " pm.expect(responseJson.errors[0].message).to.eql('Unauthorized');\r", + " pm.expect(pm.response.json().message).to.eql('Unauthorized');\r", "});" ], "type": "text/javascript", @@ -83,9 +81,7 @@ "});\r", "\r", "pm.test(\"The response contains the error properties\", () => {\r", - " const responseJson = pm.response.json();\r", - " pm.expect(responseJson.errors).to.have.lengthOf(1);\r", - " pm.expect(responseJson.errors[0].message).to.eql('Unauthorized');\r", + " pm.expect(pm.response.json().message).to.eql('Unauthorized');\r", "});" ], "type": "text/javascript", @@ -227,9 +223,7 @@ "});\r", "\r", "pm.test(\"The response contains the error properties\", () => {\r", - " const responseJson = pm.response.json();\r", - " pm.expect(responseJson.errors).to.have.lengthOf(1);\r", - " pm.expect(responseJson.errors[0].message).to.eql('Unauthorized');\r", + " pm.expect(pm.response.json().message).to.eql('Unauthorized');\r", "});" ], "type": "text/javascript", From bbe7b960c05b17488dd163491a21ee38170df41d Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 13:09:37 +0100 Subject: [PATCH 20/24] Cleaned up config --- .../ws/basic/config/WebSecurityConfig.java | 38 +- .../web/WhitelistRequestCustomizer.java | 70 ---- .../resources/basic_auth.postman_collection | 334 +++++------------- 3 files changed, 120 insertions(+), 322 deletions(-) delete mode 100644 src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/WhitelistRequestCustomizer.java diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java index 74bbbb9..b1aea60 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java @@ -24,10 +24,9 @@ package com.bernardomg.example.spring.security.ws.basic.config; -import java.util.Arrays; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; @@ -36,9 +35,10 @@ import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher; +import org.springframework.web.servlet.handler.HandlerMappingIntrospector; import com.bernardomg.example.spring.security.ws.basic.springframework.web.ErrorResponseAuthenticationEntryPoint; -import com.bernardomg.example.spring.security.ws.basic.springframework.web.WhitelistRequestCustomizer; /** * Web security configuration. @@ -62,6 +62,8 @@ public WebSecurityConfig() { * * @param http * HTTP security component + * @param introspector + * utility class to find routes * @param userDetailsService * user details service * @return web security filter chain with all authentication requirements @@ -70,19 +72,31 @@ public WebSecurityConfig() { */ @Bean("webSecurityFilterChain") public SecurityFilterChain getWebSecurityFilterChain(final HttpSecurity http, - final UserDetailsService userDetailsService) throws Exception { + final HandlerMappingIntrospector introspector, final UserDetailsService userDetailsService) + throws Exception { + final MvcRequestMatcher.Builder mvc; + + mvc = new MvcRequestMatcher.Builder(introspector); http // Whitelist access - .authorizeHttpRequests(new WhitelistRequestCustomizer(Arrays.asList("/actuator/**", "/login/**"))) + .authorizeHttpRequests(c -> c + .requestMatchers(mvc.pattern("/actuator/**"), mvc.pattern("/login/**"), mvc.pattern("/favicon.ico"), + mvc.pattern("/error/**")) + .permitAll()) + // Authenticate all others + .authorizeHttpRequests(c -> c.anyRequest() + .authenticated()) + .httpBasic(Customizer.withDefaults()) + // CSRF and CORS .csrf(CsrfConfigurer::disable) - .cors(cors -> {}) + .cors(Customizer.withDefaults()) + // Authentication error handling + .exceptionHandling(handler -> handler.authenticationEntryPoint(new ErrorResponseAuthenticationEntryPoint())) + // Stateless + .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + // Disable login and logout forms .formLogin(FormLoginConfigurer::disable) - .logout(LogoutConfigurer::disable) - .sessionManagement(t -> t.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) - // Activates HTTP Basic authentication - .httpBasic(t -> - // Return an error response on an auth failure - t.authenticationEntryPoint(new ErrorResponseAuthenticationEntryPoint())); + .logout(LogoutConfigurer::disable); http.userDetailsService(userDetailsService); diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/WhitelistRequestCustomizer.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/WhitelistRequestCustomizer.java deleted file mode 100644 index 94aaa9e..0000000 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/WhitelistRequestCustomizer.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright (c) 2022-2024 the original author or authors. - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.bernardomg.example.spring.security.ws.basic.springframework.web; - -import java.util.Collection; -import java.util.Objects; - -import org.springframework.security.config.Customizer; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer; - -/** - * White list request access configuration. Allows unauthorized access to the routes in the white list. Any other route - * requires authorization. - * - * @author Bernardo Martínez Garrido - * - */ -public final class WhitelistRequestCustomizer implements - Customizer.AuthorizationManagerRequestMatcherRegistry> { - - /** - * White list with the routes which doesn't require authorization. - */ - private final Collection whitelist; - - /** - * Default constructor. - * - * @param list - * white list - */ - public WhitelistRequestCustomizer(final Collection list) { - super(); - - whitelist = Objects.requireNonNull(list); - } - - @Override - public final void customize( - final AuthorizeHttpRequestsConfigurer.AuthorizationManagerRequestMatcherRegistry c) { - c.requestMatchers(whitelist.toArray(new String[whitelist.size()])) - .permitAll() - .anyRequest() - .authenticated(); - } - -} diff --git a/src/test/resources/basic_auth.postman_collection b/src/test/resources/basic_auth.postman_collection index dde0475..323e2f6 100644 --- a/src/test/resources/basic_auth.postman_collection +++ b/src/test/resources/basic_auth.postman_collection @@ -9,277 +9,131 @@ }, "item": [ { - "name": "Unauthorized", - "item": [ - { - "name": "Get data", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Unauthorized request\", () => {\r", - " pm.response.to.have.status(401);\r", - "});\r", - "\r", - "pm.test(\"The response contains the error properties\", () => {\r", - " pm.expect(pm.response.json().message).to.eql('Unauthorized');\r", - "});" - ], - "type": "text/javascript", - "packages": {} - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "/person", - "path": [ - "person" - ] - } - }, - "response": [] - } - ], - "description": "Unauthorized requests. These are using no authentication.", + "name": "Get data with authorization", "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, { "listen": "test", "script": { - "type": "text/javascript", "exec": [ - "" - ] + "pm.test(\"Authorized request\", () => {\r", + " pm.response.to.have.status(200);\r", + "});\r", + "\r", + "pm.test(\"The response contains the data\", () => {\r", + " const responseJson = pm.response.json();\r", + " pm.expect(responseJson).to.have.property('content');\r", + "});" + ], + "type": "text/javascript", + "packages": {} } } - ] - }, - { - "name": "Wrong authorization scheme", - "item": [ - { - "name": "Get data", - "event": [ + ], + "request": { + "auth": { + "type": "basic", + "basic": [ { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Unauthorized request\", () => {\r", - " pm.response.to.have.status(401);\r", - "});\r", - "\r", - "pm.test(\"The response contains the error properties\", () => {\r", - " pm.expect(pm.response.json().message).to.eql('Unauthorized');\r", - "});" - ], - "type": "text/javascript", - "packages": {} - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "/person", - "path": [ - "person" - ] + "key": "password", + "value": "1234", + "type": "string" + }, + { + "key": "username", + "value": "admin", + "type": "string" } - }, - "response": [] + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "/person", + "path": [ + "person" + ] } - ], - "description": "Requests using the wrong authentication scheme. To make sure the server doesn't support them.", - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImlhdCI6MTY3NTY2ODkzNCwiZXhwIjoxNjc1Njg2OTM0fQ._oR6pAYlrhpdQq23gTJdGwGncoxAoaAE-GDKdWHQC_TRLcVxdAZDaO02pSfx8JlmAIH2usOnld-NtStjvzNQyw", - "type": "string" - } - ] }, + "response": [] + }, + { + "name": "Get unauthorized data", "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, { "listen": "test", "script": { - "type": "text/javascript", "exec": [ - "" - ] + "pm.test(\"Unauthorized request\", () => {\r", + " pm.response.to.have.status(401);\r", + "});\r", + "\r", + "pm.test(\"The response contains the error properties\", () => {\r", + " pm.expect(pm.response.json().message).to.eql('Unauthorized');\r", + "});" + ], + "type": "text/javascript", + "packages": {} } } - ] - }, - { - "name": "Authorized", - "item": [ - { - "name": "Get data", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Authorized request\", () => {\r", - " pm.response.to.have.status(200);\r", - "});\r", - "\r", - "pm.test(\"The response contains the data\", () => {\r", - " const responseJson = pm.response.json();\r", - " pm.expect(responseJson).to.have.property('content');\r", - "});" - ], - "type": "text/javascript", - "packages": {} - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "/person", - "path": [ - "person" - ] - } - }, - "response": [] - } ], - "description": "Authorized requests. These check the server handles the authorization scheme.", - "auth": { - "type": "basic", - "basic": [ - { - "key": "username", - "value": "admin", - "type": "string" - }, - { - "key": "password", - "value": "1234", - "type": "string" - } - ] + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "/person", + "path": [ + "person" + ] + } }, + "response": [] + }, + { + "name": "Get data with authorization but no privileges", "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, { "listen": "test", "script": { - "type": "text/javascript", "exec": [ - "" - ] + "pm.test(\"Unauthorized request\", () => {\r", + " pm.response.to.have.status(401);\r", + "});\r", + "\r", + "pm.test(\"The response contains the error properties\", () => {\r", + " pm.expect(pm.response.json().message).to.eql('Unauthorized');\r", + "});" + ], + "type": "text/javascript", + "packages": {} } } - ] - }, - { - "name": "Authorized without privileges", - "item": [ - { - "name": "Get data", - "event": [ + ], + "request": { + "auth": { + "type": "basic", + "basic": [ { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Unauthorized request\", () => {\r", - " pm.response.to.have.status(401);\r", - "});\r", - "\r", - "pm.test(\"The response contains the error properties\", () => {\r", - " pm.expect(pm.response.json().message).to.eql('Unauthorized');\r", - "});" - ], - "type": "text/javascript", - "packages": {} - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "/person", - "path": [ - "person" - ] + "key": "username", + "value": "noroles", + "type": "string" + }, + { + "key": "password", + "value": "1111", + "type": "string" } - }, - "response": [] - } - ], - "description": "Authorized without privileges. In this case these requests cause an authorization error, as the user is authenticated but lacks permissions.", - "auth": { - "type": "basic", - "basic": [ - { - "key": "password", - "value": "1111", - "type": "string" - }, - { - "key": "username", - "value": "noroles", - "type": "string" - } - ] - }, - "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } + ] }, - { - "listen": "test", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } + "method": "GET", + "header": [], + "url": { + "raw": "/person", + "path": [ + "person" + ] } - ] + }, + "response": [] } ], "event": [ From 3c54040d6bddead70ac12abdd836fea3e7d31c05 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 20:14:52 +0100 Subject: [PATCH 21/24] Cleaned up model --- .../spring/security/ws/basic/user/domain/model/User.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java index 15f7690..d0ccfe5 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java @@ -29,15 +29,13 @@ import lombok.Builder; /** - * Representation of a user. - *

- * FIXME: this should be immutable + * User. * * @author Bernardo Martínez Garrido * */ @Builder(setterPrefix = "with") -public record User(String email, boolean enabled, boolean expired, boolean locked, String name, boolean passwordExpired, - Collection privileges, String username) { +public record User(String email, String username, String name, boolean enabled, boolean expired, boolean locked, + boolean passwordExpired, Collection privileges) { } From 75db99a36bf51a83ce3fac04326a9a4be36d5293 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 20:48:11 +0100 Subject: [PATCH 22/24] Cleaned up code --- .../inbound/user/repository/UserPersonRepository.java | 5 ++++- .../basic/person/usecase/service/DefaultPersonService.java | 6 ++++++ .../ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java | 3 +++ .../ws/basic/user/adapter/inbound/jpa/model/UserEntity.java | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java index 4fe2050..6910d2c 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java @@ -37,12 +37,15 @@ import lombok.extern.slf4j.Slf4j; /** - * Person repository which takes the data from the users. + * Person repository which takes the data from the users. Reads from the users repository, and maps into {@code Person}. */ @Slf4j @Repository public final class UserPersonRepository implements PersonRepository { + /** + * User repository. The data for the persons is taken from here. + */ private final UserRepository userRepository; public UserPersonRepository(final UserRepository userRepo) { diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java index d8e1ea7..592aafe 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java @@ -11,10 +11,16 @@ import lombok.extern.slf4j.Slf4j; +/** + * Default person service, which just takes the data from the person repository. + */ @Slf4j @Service public final class DefaultPersonService implements PersonService { + /** + * Person repository to read the data. + */ private final PersonRepository personRepository; public DefaultPersonService(final PersonRepository personRepo) { diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java index 47e5ee2..7b9adab 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java @@ -71,6 +71,9 @@ public class RoleEntity implements Serializable { @Column(name = "name", nullable = false, unique = true, length = 60) private String name; + /** + * Privileges. + */ @OneToMany @JoinTable(name = "role_privileges", joinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "privilege_id", referencedColumnName = "id") }) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java index 8e26fac..5bb6e14 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java @@ -109,6 +109,9 @@ public class UserEntity implements Serializable { @Column(name = "password", nullable = false, length = 60) private String password; + /** + * Roles. + */ @OneToMany @JoinTable(name = "user_roles", joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") }) From b07e2f9053a390fdfd69185bf82ec0ab82976ac3 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 20:51:46 +0100 Subject: [PATCH 23/24] Updated headerrs --- LICENSE | 2 +- .../spring/security/ws/basic/Application.java | 2 +- .../security/ws/basic/config/AuditConfig.java | 2 +- .../ws/basic/config/SecurityConfig.java | 2 +- .../ws/basic/config/WebConfiguration.java | 2 +- .../ws/basic/config/WebSecurityConfig.java | 2 +- .../ws/basic/config/package-info.java | 2 +- .../security/ws/basic/package-info.java | 2 +- .../user/repository/UserPersonRepository.java | 2 +- .../inbound/user/repository/package-info.java | 2 +- .../rest/controller/PersonController.java | 2 +- .../rest/controller/package-info.java | 2 +- .../ws/basic/person/domain/model/Person.java | 23 +++++++++++++++++++ .../person/domain/model/package-info.java | 2 +- .../domain/repository/PersonRepository.java | 23 +++++++++++++++++++ .../domain/repository/package-info.java | 2 +- .../usecase/service/DefaultPersonService.java | 23 +++++++++++++++++++ .../person/usecase/service/PersonService.java | 23 +++++++++++++++++++ .../person/usecase/service/package-info.java | 2 +- .../audit/AuditEventLogger.java | 2 +- .../springframework/audit/package-info.java | 2 +- .../userdetails/UserDomainDetailsService.java | 2 +- .../userdetails/package-info.java | 2 +- ...ErrorResponseAuthenticationEntryPoint.java | 2 +- .../springframework/web/package-info.java | 2 +- .../inbound/jpa/model/PrivilegeEntity.java | 2 +- .../adapter/inbound/jpa/model/RoleEntity.java | 2 +- .../adapter/inbound/jpa/model/UserEntity.java | 2 +- .../inbound/jpa/model/package-info.java | 2 +- .../jpa/repository/JpaUserRepository.java | 2 +- .../jpa/repository/UserSpringRepository.java | 2 +- .../inbound/jpa/repository/package-info.java | 2 +- .../ws/basic/user/domain/model/Privilege.java | 2 +- .../ws/basic/user/domain/model/User.java | 2 +- .../basic/user/domain/model/package-info.java | 2 +- .../domain/repository/UserRepository.java | 2 +- .../user/domain/repository/package-info.java | 2 +- 37 files changed, 125 insertions(+), 33 deletions(-) diff --git a/LICENSE b/LICENSE index 9e6d16f..850d137 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2022-2023 Bernardo Martínez Garrido +Copyright (c) 2022-2025 Bernardo Martínez Garrido Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/Application.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/Application.java index dd962bf..f336750 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/Application.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/Application.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/AuditConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/AuditConfig.java index dc6accc..07b93dd 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/AuditConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/AuditConfig.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java index a02a5d6..ebaa6e2 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/SecurityConfig.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebConfiguration.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebConfiguration.java index 2f51f16..8099412 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebConfiguration.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebConfiguration.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java index b1aea60..c2bc832 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/WebSecurityConfig.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/package-info.java index bf69e2d..8339718 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/config/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/package-info.java index 308962e..31c804d 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java index 6910d2c..878bc58 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/package-info.java index 97a5d41..6db57d2 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java index eb7f97f..69249f4 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/PersonController.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/package-info.java index 9b04236..b3c90ae 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/outbound/rest/controller/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java index ae6bf25..67478a0 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java @@ -1,3 +1,26 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2025 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package com.bernardomg.example.spring.security.ws.basic.person.domain.model; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/package-info.java index 64faad9..d486416 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java index 9ad4d49..d28c94f 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java @@ -1,3 +1,26 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2025 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package com.bernardomg.example.spring.security.ws.basic.person.domain.repository; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/package-info.java index 5d560e4..90e2dd6 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java index 592aafe..78818ec 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java @@ -1,3 +1,26 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2025 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package com.bernardomg.example.spring.security.ws.basic.person.usecase.service; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java index e2acb22..7d7cd62 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java @@ -1,3 +1,26 @@ +/** + * The MIT License (MIT) + *

+ * Copyright (c) 2022-2025 the original author or authors. + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package com.bernardomg.example.spring.security.ws.basic.person.usecase.service; diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/package-info.java index b16e414..24308cb 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/AuditEventLogger.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/AuditEventLogger.java index 24670d9..76f5ead 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/AuditEventLogger.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/AuditEventLogger.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/package-info.java index 79d6066..fe01e7e 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/audit/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/UserDomainDetailsService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/UserDomainDetailsService.java index ef1ebe7..42b484d 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/UserDomainDetailsService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/UserDomainDetailsService.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/package-info.java index bee7e91..3ea1383 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/userdetails/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/ErrorResponseAuthenticationEntryPoint.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/ErrorResponseAuthenticationEntryPoint.java index b2536bf..dd6b7b4 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/ErrorResponseAuthenticationEntryPoint.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/ErrorResponseAuthenticationEntryPoint.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/package-info.java index b996860..b51a03e 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/springframework/web/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/PrivilegeEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/PrivilegeEntity.java index f6f7fa0..35ca952 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/PrivilegeEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/PrivilegeEntity.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java index 7b9adab..511cbba 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/RoleEntity.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java index 5bb6e14..e1cc4c4 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/UserEntity.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/package-info.java index 9910630..af009fe 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/model/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java index 2196e19..fb1b237 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/JpaUserRepository.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/UserSpringRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/UserSpringRepository.java index 05a3bd0..333633d 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/UserSpringRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/UserSpringRepository.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/package-info.java index f91ecc6..959b6d7 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/adapter/inbound/jpa/repository/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/Privilege.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/Privilege.java index 14ca973..b119ac2 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/Privilege.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/Privilege.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java index d0ccfe5..f3b2849 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/User.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/package-info.java index 5b94143..67eaf07 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/model/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/UserRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/UserRepository.java index 66d83b5..903c167 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/UserRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/UserRepository.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/package-info.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/package-info.java index bdc373c..ac5d23f 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/package-info.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/user/domain/repository/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) *

- * Copyright (c) 2022-2023 the original author or authors. + * Copyright (c) 2022-2025 the original author or authors. *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal From 710a8f087d144437c71bbd94bbcc0c2dc6caf1eb Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 14 Dec 2024 20:54:48 +0100 Subject: [PATCH 24/24] Cleanup --- .../inbound/user/repository/UserPersonRepository.java | 2 ++ .../security/ws/basic/person/domain/model/Person.java | 5 +++++ .../person/domain/repository/PersonRepository.java | 10 ++++++++++ .../person/usecase/service/DefaultPersonService.java | 2 ++ .../ws/basic/person/usecase/service/PersonService.java | 10 ++++++++++ 5 files changed, 29 insertions(+) diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java index 878bc58..558942d 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/adapter/inbound/user/repository/UserPersonRepository.java @@ -38,6 +38,8 @@ /** * Person repository which takes the data from the users. Reads from the users repository, and maps into {@code Person}. + * + * @author Bernardo Martínez Garrido */ @Slf4j @Repository diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java index 67478a0..347fda7 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/model/Person.java @@ -24,6 +24,11 @@ package com.bernardomg.example.spring.security.ws.basic.person.domain.model; +/** + * Person. + * + * @author Bernardo Martínez Garrido + */ public record Person(String id, String name) { } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java index d28c94f..05d87ac 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/domain/repository/PersonRepository.java @@ -28,8 +28,18 @@ import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; +/** + * Person repository. + * + * @author Bernardo Martínez Garrido + */ public interface PersonRepository { + /** + * Returns all the people. + * + * @return all the people + */ public Collection findAll(); } diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java index 78818ec..2b16039 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/DefaultPersonService.java @@ -36,6 +36,8 @@ /** * Default person service, which just takes the data from the person repository. + * + * @author Bernardo Martínez Garrido */ @Slf4j @Service diff --git a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java index 7d7cd62..00de137 100644 --- a/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java +++ b/src/main/java/com/bernardomg/example/spring/security/ws/basic/person/usecase/service/PersonService.java @@ -28,8 +28,18 @@ import com.bernardomg.example.spring.security.ws.basic.person.domain.model.Person; +/** + * Person service. + * + * @author Bernardo Martínez Garrido + */ public interface PersonService { + /** + * Returns all the people. + * + * @return all the people + */ public Collection getAll(); }