Symfony security annotation on controller class and inherited action method

Symfony security extension annotation class and methodThis is a quick code example on how to extend the Symfony security extension in your bundle so you could have rules on the controller’s class as annotation and also inherit those and merge with the action method annotations.

namespace AppBundle\Configuration;

 * @Annotation
class Security extends \Sensio\Bundle\FrameworkExtraBundle\Configuration\Security
    public function getAliasName()
        return 'app_security';

    public function allowArray()
        // allow nested configuration (class/method).
        return true;

Read more ›

Posted in PHP, Symfony2 Tagged with: , , ,

ElasticSearch Nested Filter Not Matching Emails

no match elasticsearch email filter uax tokenizerThere’s one situation where we need to help ElasticSearch to understand the structure of our data in order to be able to query it fully – when dealing with arrays of complex objects.

ElasticSearch has one great feature that it allows us to search in nested properties of complex JSON objects. It’s normally used for list of objects inside the parent document. Just to mention I am using ElasticSearch 1.4 for legacy reasons. Here is an example of the model we have stored locally in ES: Read more ›

Posted in ElasticSearch, NoSQL Tagged with: , , , , , ,

MySQL not starting – unknown variable table_cache

Table open cache mysql upgrade errorI’ve upgraded my dev server to latest version of Debian. Everything was going smoothly until I’ve got an error from mysql-server that it cannot be installed due to an error. I checked few websites that I have there running and all of them were down. Checked the logs but nothing obvious was there, eventually I realised the MySQL process was not running at all which was understandable considering the previous failure to install myslq server. So this was my error:

[ERROR] mysqld: unknown variable 'table_cache=64'
[ERROR] Aborting

Read more ›

Posted in Servers, Unix Tagged with: , , ,

Get All Files in Directory and All Child Directories

PHP walk recursively with iterator over all directories and filesI was playing with PHP the other day and was trying to fetch and rename 1000s of files I have stored locally on my machine. Seemingly PHP isn’t the best language to that operation Python or even BASH could do the job though it was nice to give it a try. So this is what I came up, simple and straightforward.

Read more ›

Posted in PHP, Small Tips Tagged with: , , , , ,

Change default date for Jackson in Spring Boot application

Java date convert timestamp in iso8601 for json swagger jackson spring bootDates as a concept are seamingly simple and straight forward. Though in programming world those could be rather complex starting from format, representation, time zones, machine default configuration going through different calendars and date manipulations.

In this post I won’t to give a quick tip on handling dates in an application that I am building. It will be short post, I promise.

Read more ›

Posted in API, Java, Small Tips, Spring MVC, Swagger Tagged with: , , , , , ,

Swagger and polymorphic type handling with Jackson

polimorphic types with jackson and swaggerPolymorphic type handling based on JSON property

Building an API that supports inheritance could be quite crucial. Imagine the case where you want to have an endpoint that stores a profile data for a given provider and that provider could be your main website or any 3rd party platform that can provide the data. We might have a base Profile class which in our case would be abstract class with firstName and lastName fields and an abstract method to provide the name of the actual profile provider getProfile().

You can do all of that quite easily with few Jackson annotations, for  polymorphic types, on the base class and on the children that extend the base class. No more words here is an example: Read more ›

Posted in API, Java, Spring MVC, Swagger Tagged with: , , , , , ,

Spring Boot: Executing asynchronous method backed with a queue

Spring Boot - asynchronous execution of controller method with threading backed by a queueMany people go for different solutions and sometimes overcomplicate their applciation with message queues like ActiveMQ, RabbitMQ and other options out there. Though this is yet another part in the application architecture that would require maintenance and support and it’s also a possible failiure point.

There are good reasons to use this approach but in most cases you can get through with normal in-memmory queue with multi-threading. Read more ›

Posted in Java, Spring MVC Tagged with: , , , ,

Best practices in Agile Retrospectives

agile scrum retrospective meeting best practices dos dontsOne of the core Agile practices is to inspect and adapt. We inspect the developed software in the business review or demo meeting to ensure that we are delivering the right product. And we inspect how the team performs and interacts in the retrospective meeting to make sure that we are working in the right way and that we keep improving.

We should work on maximizing the benefits of the retrospective meeting and adapt according to its outputs, or it will turn into a useless ritual.

In this article, I share some tips on things you can do to improve your retrospective meetings, and things you should avoid as well.
Read more ›

Posted in Project Management Tagged with: , , , ,

API Versioning – best practices

API Service versioning best practices URL headersWhat happens if you need to make changes to your API?

If you’re making additions to the API – e.g., adding services or adding fields to your services – you likely don’t need to do anything more to notify users than to tell them about the changes.

But what happens if you need to make a change that will affect users?

  • Adding authentication
  • Adding authorization rules
  • Removing a service
  • Removing or renaming fields inside services

Such changes as these impact your existing users. At times like these, you need to create a new version of your API.

But how do you do that? Read more ›

Posted in API, Small Tips Tagged with: , , ,

Load configurations from custom bundle in Symfony2

Symfony2 configuration file for custom bundleWhen I build apps or add new functionality to Symfony2 I build it into a separate bundle, thus trying to keep the structure modular which is generally a good practice as everyone knows. Keeping all parts of the bundle together makes it easy to maintain and also easy to change the configurations as they reside in same place as the code itself.

In this post I’ll show you how to make Symfony2 core discover your config.yml and services files defined in your custom bundle.

Create new bundle

First let’s create a new bundle that we’ll use as a demo. Run following command in the terminal: Read more ›

Posted in PHP, Small Tips, Symfony2 Tagged with: , , ,