concept list in category spring

appears as: list, The list, list
Spring Microservices in Action, 2E

This is an excerpt from Manning's book Spring Microservices in Action, 2E.

It’s important to understand that there isn’t a formal definition of how to create a microservice, but on the next section, I’m going to describe a list of common aspects you have to take into consideration while building a microservice.

A dockerfile is a simple text file that contains a list of instructions and commands that the docker client calls to create and prepare an image. Docker created this file to automate the image creation process.  The commands used in the dockerfile are similar to the Linux commands what makes it easier to understand.

Spring Security in Action

This is an excerpt from Manning's book Spring Security in Action.

There are many types of injection attacks. Even the XSS that we mention in section 1.4.3 can be considered an injection vulnerability. In the end, injection attacks inject a client-side script with the means of harming the system somehow. Other examples could be SQL injection, XPath injection, OS command injection, LDAP injection, and the list continues.

The ProductService class defines the service method we protect with @PreFilter. You find the ProductService class presented in listing 17.3. Above the sellProducts() method, you observe the use of the @PreFilter annotation. The Spring Expression Language (SpEL) used with the annotation is filterObject.owner == authentication.name which allows in the list only the values where the owner attribute of the Product equals the username of the logged-in user. On the left side of the equal operator in the expression, we used filterObject. With filterObject we refer to objects in the list provided as a parameter. Because we have a list of products, the filterObject in our case is of type Product. For this reason, we can refer to the product’s attribute named owner. On the right side of the equal operator in the expression, we used the authentication object. For the @PreFilter and @PostFilter annotations, we can directly refer to the authentication object, which is available in the SecurityContext after the authentication (figure 17.4).

Figure 17.4 When using pre-filtering, by filterObject, we refer to the objects inside the list, which the caller provided as a parameter. The authentication object is the one stored after the authentication process in the SecurityContext.

The service method returns, in the end, the list exactly as the method received. This way, we can test and validate that the framework filtered the list as we expected by checking the list returned in the HTTP response body.

Listing 17.3 Using the @PreFilter annotation in the ProductService class
@Service
public class ProductService {
 
  @PreFilter[CA]    #A
    ("filterObject.owner == authentication.name")
  public List<Product> sellProducts(List<Product> products) {
    // sell products and return the sold products list
    return products;    #B
  }
}

#A In the list given as a parameter, only products owned by the authenticated user are allowed.