Posts

Showing posts with the label learn

Migrating from Traditional DAO to Spring Data REST with JPA

Image
Spring Data Rest is a spring boot project but it's like a more advanced and less coding application. There are three new concepts in Spring Data Rest -   Configuration  It adds 's' automatically to the entity. You can also give path for your URL  Add @RepositoryRestResource(path="members") annotation at top of Repository interface. Pagination  # change default page size  spring.data.rest.default-page-size=3  Sorting  http://localhost:8080/magic-api/members?sort=age ---default in ascending  http://localhost:8080/magic-api/members?sort=age ---in descending Steps to develop CRUD application-   Go to https://start.spring.io/ and kick start your project. Add necessary dependencies like Spring Data JPA, Spring Web, Spring Boot DevTools, MySql Driver, spring-boot-starter-data-rest . Select as maven and enter.   Import as maven project and check pom for dependencies we added.  Create entity class in entity package and write ...

What to change for JDBC connection in Spring Security

Image
  What to change for JDBC connection in Spring Security? Add annotation @PropertySource("classpath:persistance-mysql.properties") in AppConfig   setup variables to hold properties @Autowired private Environment env;   setup a logger for diagnostics private Logger logger = Logger.getLogger(getClass().getName());   define a bean for security datasource  @Bean  public DataSource securityDataSource() {    //create connection pool  ComboPooledDataSource securityDataSource = new ComboPooledDataSource();    //set jdbc driver class  try {  securityDataSource.setDriverClass(env.getProperty("jdbc.driver"));  }catch(PropertyVetoException exc) {  throw new RuntimeException(exc);  }    //log connection properties  //to make sure data we are reading is correct  logger.info(">>> jdbc.url=" +env.getProperty("jdbc.url"));  logger.info(">>> jdbc.user=" +env.getProperty...

Springing into Security: Best Practices for a Secure Application

Image
Spring Security is a spring framework for security. It is implemented using servlet filters in the background.  There are two ways to secure spring webapps-  Declarative Security  Programmatic Security  In Declarative Security we define application security constraints in configuration I.e., all java config (@Configuration, no XML) or spring XML config. It provides separation of concerns between application code and security.     In programmatic Security spring security provides an api for custom application coding and it provides greater customization for specific application requirements.    CSRF (Cross-site-request-forgery) protection Spring security protects against CSRF(Cross-site-request-forgery). It is a security attack where maybe an evil website tricks you into executing an action on a web application while you are logged in.  For instance, you are logged in your bank portal so you can be tricked into transferring money to other...