Question: I am trying to implement role based authorization on my rest apis.
I have been able to successfully implement and run the project but there are some things that I am confused about.

CustomeUserDetailsService.java:

```
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Optional<UsersAuth> optionalUsers = usersAuthRepository.findByName(username);

    optionalUsers
            .orElseThrow(() -> new UsernameNotFoundException("Username not found"));
    return optionalUsers
            .map(CustomUserDetails::new).get();
}

```

CustomUserDeatils.java:

```
 @Override
public Collection<? extends GrantedAuthority> getAuthorities() {

    return getRoles()
            .stream()
            .map(role -> new SimpleGrantedAuthority("ROLE_" + role.getRole()))
            .collect(Collectors.toList());
}

```

I want to know what the above two code snippets are actually doing. can someone explain to me? I have searched alot but did not understand. Specially what is the use of Granted authority? I know for a fact that CustomUserDetailsService is taking a username and if it does not exist, it throws an exception. If anyone could elaborate in detail? It would help me alot.

Answer: 
> 
> A year ago it were actually working fine, Does anyone have any idea, what's going wrong here inside my docker-compose file now.
> 
> 
> 

Seems like you pulled the fresh image, where in the new image you should specify Postgres user password. You can look into Dockerhub, the image is **update** **one month ago**

[![enter image description here](https://i.stack.imgur.com/JCHqy.png)](https://i.stack.imgur.com/JCHqy.png)

[postgress-11-alpine](https://hub.docker.com/_/postgres?tab=tags&page=1&name=11-alpine)

```
  db:
    image: postgres:11-alpine
    restart: always
    environment:
      POSTGRES_PASSWORD: example

```

As the error message is self expalinatory

```
You must specify POSTGRES_PASSWORD to a non-empty value for the
        superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

```

or `POSTGRES_HOST_AUTH_METHOD=trust` use this which is not recommended.

```
You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
 connections without a password. This is *not* recommended.

```

**POSTGRES\_PASSWORD**

> 
> This environment **variable is required** for you to use the PostgreSQL image. **It must not be empty or undefined**. This environment variable sets the superuser password for PostgreSQL. The default superuser is defined by the `POSTGRES_USER` environment variable.
> 
> 
> 

[Environment Variables](https://hub.docker.com/_/postgres)
Adding on ArifMustafa's answer, This worked for me.

```
  postgres:
    image:  'postgres:12-alpine'
    environment:
        POSTGRES_PASSWORD: mypassword
    expose:
      - 5432
    volumes: 
      - postgres_data:/var/lib/postgres/data/

volumes:
   postgres_data:

```