diff --git a/data/auth_sandeep.postman_collection.json b/data/auth_sandeep.postman_collection.json new file mode 100644 index 0000000..d4102ac --- /dev/null +++ b/data/auth_sandeep.postman_collection.json @@ -0,0 +1,119 @@ +{ + "info": { + "_postman_id": "2b4658ae-097a-49a8-b1c9-25fbb587278e", + "name": "auth_sandeep", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "get token", + "request": { + "auth": { + "type": "basic", + "basic": [ + { + "key": "password", + "value": "sandeep.kumar", + "type": "string" + }, + { + "key": "username", + "value": "sandeep.kumar@pepcus.com", + "type": "string" + } + ] + }, + "method": "POST", + "header": [ + { + "key": "Accept", + "value": "application/json", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "grant_type", + "value": "password", + "type": "text" + }, + { + "key": "username", + "value": "sandeep", + "type": "text" + }, + { + "key": "password", + "value": "sandeep123", + "type": "text" + } + ] + }, + "url": { + "raw": "localhost:8080/oauth/token", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "oauth", + "token" + ] + } + }, + "response": [] + }, + { + "name": "get api", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "auth": { + "type": "noauth" + }, + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "application/json", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Authorization", + "value": "bearer 608e6937-04cf-41bc-b335-68e892761864", + "type": "text" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [] + }, + "url": { + "raw": "localhost:8080/owners", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "owners" + ] + } + }, + "response": [] + } + ], + "protocolProfileBehavior": {} +} \ No newline at end of file diff --git a/data/database b/data/database new file mode 100644 index 0000000..946d10f Binary files /dev/null and b/data/database differ diff --git a/pom.xml b/pom.xml index 08cf259..600aca2 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -68,13 +69,28 @@ org.springframework.security.oauth spring-security-oauth2 - 2.3.3.RELEASE + 2.3.5.RELEASE + org.modelmapper modelmapper 2.3.5 + + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + diff --git a/src/main/java/sandeep/demo/controller/OwnerController.java b/src/main/java/sandeep/demo/controller/OwnerController.java index b880366..b7cfb9d 100644 --- a/src/main/java/sandeep/demo/controller/OwnerController.java +++ b/src/main/java/sandeep/demo/controller/OwnerController.java @@ -53,5 +53,10 @@ public HttpStatus deleteById(@PathVariable Integer ownerId) { return HttpStatus.ACCEPTED; } + @GetMapping(value = "/name/{firstName}") + public List byExample(@PathVariable String firstName) { + List owners = ownerManager.getByExample(firstName); + return owners; + } } diff --git a/src/main/java/sandeep/demo/manager/OwnerManager.java b/src/main/java/sandeep/demo/manager/OwnerManager.java index a427f8c..74a6855 100644 --- a/src/main/java/sandeep/demo/manager/OwnerManager.java +++ b/src/main/java/sandeep/demo/manager/OwnerManager.java @@ -5,9 +5,11 @@ import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Example; import org.springframework.stereotype.Component; import sandeep.demo.entity.Owner; +import sandeep.demo.entity.data.res.Person; import sandeep.demo.model.ModelEntityMapper; import sandeep.demo.model.OwnerBO; import sandeep.demo.repository.OwnerRepository; @@ -45,5 +47,21 @@ public OwnerBO getById(Integer ownerId) { public void deleteById(Integer ownerId) { ownerRepository.deleteById(ownerId); } + + public List getByExample(String name){ + + + Owner owner = new Owner(); + owner.setFirstName(name); + Example example = Example.of(owner); + List results = ownerRepository.findAll(example); + results.forEach(action-> { + System.out.println("action "+action.getId()); + }); + List list = new ArrayList<>(); + results.forEach(o -> list.add(ModelEntityMapper.convertToBO(o))); + return list; + + } } diff --git a/src/main/java/sandeep/demo/repository/OwnerRepository.java b/src/main/java/sandeep/demo/repository/OwnerRepository.java index 953805f..a985604 100644 --- a/src/main/java/sandeep/demo/repository/OwnerRepository.java +++ b/src/main/java/sandeep/demo/repository/OwnerRepository.java @@ -1,10 +1,10 @@ package sandeep.demo.repository; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.repository.CrudRepository; import sandeep.demo.entity.Owner; -public interface OwnerRepository extends CrudRepository, JpaSpecificationExecutor{ +public interface OwnerRepository extends JpaRepository, JpaSpecificationExecutor{ } diff --git a/src/main/java/sandeep/demo/spring/security/AuthorizationServerConfiguration.java b/src/main/java/sandeep/demo/spring/security/AuthorizationServerConfiguration.java index 7c48ba7..544f15e 100644 --- a/src/main/java/sandeep/demo/spring/security/AuthorizationServerConfiguration.java +++ b/src/main/java/sandeep/demo/spring/security/AuthorizationServerConfiguration.java @@ -5,7 +5,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; @@ -41,10 +40,10 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { - clients.inMemory().withClient("sandeep") + clients.inMemory().withClient("sandeep.kumar@pepcus.com") .authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit") - .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT").scopes("read", "write", "trust").secret("{noop}secret") - .accessTokenValiditySeconds(120).// Access token is only valid for 2 minutes. + .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT").scopes("read", "write", "trust").secret("{noop}sandeep.kumar") + .accessTokenValiditySeconds(3600).// Access token is only valid for 60 minutes. refreshTokenValiditySeconds(600);// Refresh token is only valid for 10 minutes. } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f1806a6..22e9155 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,9 +3,11 @@ spring.datasource.url=jdbc:postgresql://localhost:5432/study spring.datasource.username=postgres spring.datasource.password=postgres spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +#pring.jpa.hibernate.ddl-auto=create pring.jpa.hibernate.ddl-auto=update spring.datasource.driver-class-name=org.postgresql.Driver flyway.baseline-on-migrate=true spring.flyway.baseline-on-migrate = true spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true -spring.data.rest.basePath=/api \ No newline at end of file +spring.data.rest.basePath=/api +spring.banner.location=classpath:/banner/banner.txt \ No newline at end of file diff --git a/src/main/resources/banner/banner.txt b/src/main/resources/banner/banner.txt new file mode 100644 index 0000000..984faad --- /dev/null +++ b/src/main/resources/banner/banner.txt @@ -0,0 +1,5 @@ + / ___| __ _ _ __ __| | ___ ___ _ __ + \___ \ / _` | | '_ \ / _` | / _ \ / _ \ | '_ \ + ___) | | (_| | | | | | | (_| | | __/ | __/ | |_) | + |____/ \__,_| |_| |_| \__,_| \___| \___| | .__/ + |_| \ No newline at end of file