Showing posts from September, 2017

Deploy Spring Boot app in digitalocean cloud (or any cloud as long asyou have ssh access)

First thing first. Assuming that you got an account at digitalocean, lets create a droplet. But before that add your ssh keys of your computers in Settings>Security>Add SSH Key.
1. Resolving SSH Keys
If you need to generate ssh key go here.

If you already have a ssh key then copy the content of your public key and paste it on digialocean.
2. Create Droplet
For this purpose I choose ubuntu 16.04 with 1 gigabyte if Ram. Choose it according to your need. And yes, DON'T forget to choose your pc (SSH Keys) when creating droplet. After creating droplet you'll get an IP address of your machine. If you can't find the IP, well consult your eye specialist ;)
3. Access to your droplet
If you are from mac or linux just open terminal and execute this command.
ssh [email protected]_address
If you copied your public key to digitalocean when creating the droplet you should get access at this point. If you forgot to do that you have to add your ssh key on the operating system manually.
4. Inst…

Flood Control (Limit Login Attempts) in Spring Security

May be sometimes you wanna limit your users login attempt for better security, to protect them from buitforce attack, so that their account isn't compromised. I'm gonna show you how you can limit login attempts and control flooding.
1. Dependency
We'll use Googles Guava for caching, so please add this dependency in your pom.xmlfile.

2. Login Attempt Service
To control login attemps determine if it's blocked we'll create a service called LoginAttemptService.
public class LoginAttemptService {
private final int MAX_ATTEMPT = 10;
private LoadingCache<String, Integer> attemptsCache;

public LoginAttemptService() {
attemptsCache = CacheBuilder.newBuilder().
expireAfterWrite(1, TimeUnit.DAYS).build(new CacheLoader<String, Integer>() {

User activity logging: Spring


In this article I'll show you how you can log user activity in your spring application. We'll use spring's HandlerInterceptorAdapter to intercept requests and thus logging activities.
1. Create Activity entity
Create an entity that represents an activity. When user sends a request to an url we'll save this object to our database (On Condition lol).
public class Activity extends BaseEntity{

private String userAgent;
private String ip;
private String expires;
private User user;
private String requestMethod;
private String url;

private Long totalVisitors;

public String getUserAgent() {
return userAgent;

public void setUserAgent(String userAgent) {
this.userAgent = userAgent;

public String getExpires() {
return expires;

public void setExpires(String expires) {
this.expires = expires;

public User getUser() {
return user;