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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions data/auth_sandeep.postman_collection.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
Binary file added data/database
Binary file not shown.
20 changes: 18 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -68,13 +69,28 @@
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.3.RELEASE</version>
<version>2.3.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>

</build>
</project>
5 changes: 5 additions & 0 deletions src/main/java/sandeep/demo/controller/OwnerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ public HttpStatus deleteById(@PathVariable Integer ownerId) {
return HttpStatus.ACCEPTED;
}

@GetMapping(value = "/name/{firstName}")
public List<OwnerBO> byExample(@PathVariable String firstName) {
List<OwnerBO> owners = ownerManager.getByExample(firstName);
return owners;
}

}
18 changes: 18 additions & 0 deletions src/main/java/sandeep/demo/manager/OwnerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,5 +47,21 @@ public OwnerBO getById(Integer ownerId) {
public void deleteById(Integer ownerId) {
ownerRepository.deleteById(ownerId);
}

public List<OwnerBO> getByExample(String name){


Owner owner = new Owner();
owner.setFirstName(name);
Example<Owner> example = Example.of(owner);
List<Owner> results = ownerRepository.findAll(example);
results.forEach(action-> {
System.out.println("action "+action.getId());
});
List<OwnerBO> list = new ArrayList<>();
results.forEach(o -> list.add(ModelEntityMapper.convertToBO(o)));
return list;

}

}
4 changes: 2 additions & 2 deletions src/main/java/sandeep/demo/repository/OwnerRepository.java
Original file line number Diff line number Diff line change
@@ -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<Owner, Integer>, JpaSpecificationExecutor<Owner>{
public interface OwnerRepository extends JpaRepository<Owner, Integer>, JpaSpecificationExecutor<Owner>{

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
spring.data.rest.basePath=/api
spring.banner.location=classpath:/banner/banner.txt
5 changes: 5 additions & 0 deletions src/main/resources/banner/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/ ___| __ _ _ __ __| | ___ ___ _ __
\___ \ / _` | | '_ \ / _` | / _ \ / _ \ | '_ \
___) | | (_| | | | | | | (_| | | __/ | __/ | |_) |
|____/ \__,_| |_| |_| \__,_| \___| \___| | .__/
|_|