Pages

Sunday, April 16, 2023

Keycloak: production ready configuration

To set up a production-ready Keycloak instance with MySQL using Docker Compose, you can follow these steps:

  1. Create a Docker Compose file named docker-compose.yml with the following contents:
version: '3.7'

services:
  keycloak:
    image: jboss/keycloak:15.0.2
    container_name: keycloak
    environment:
      - KEYCLOAK_USER=admin
      - KEYCLOAK_PASSWORD=admin
      - DB_VENDOR=mysql
      - DB_ADDR=mysql
      - DB_PORT=3306
      - DB_DATABASE=keycloak
      - DB_USER=keycloak
      - DB_PASSWORD=password
    ports:
      - "8080:8080"
    depends_on:
      - mysql

  mysql:
    image: mysql:8.0.27
    container_name: mysql
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=keycloak
      - MYSQL_USER=keycloak
      - MYSQL_PASSWORD=password
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql

volumes:
  mysql_data:


This file will create two services, one for Keycloak and one for MySQL, and link them together using the depends_on directive.

  1. Start the containers by running the following command in the same directory as your docker-compose.yml file:
docker-compose up -d

This will start the Keycloak and MySQL containers in detached mode.

  1. Wait for a few moments for the containers to start up and then access the Keycloak Admin Console by visiting http://localhost:8080/auth/admin/ in your web browser. You can log in using the credentials admin/admin.

That's it! You now have a production-ready Keycloak instance with MySQL running in Docker. Note that this is just a basic configuration, and you may need to adjust it to suit your specific needs.


    Diakin

    Keycloak: Client roles spring boot

    Keycloak is an open-source Identity and Access Management (IAM) solution that provides authentication and authorization services for applications and services. The Keycloak Admin Console is a web-based user interface that allows administrators to manage and configure the Keycloak server.

    To access the Keycloak Admin Console, follow these steps:
    1. Open a web browser and go to the URL where Keycloak is installed.
    2. Click on the "Administration Console" link located in the top-right corner of the login screen.
    3. Enter your administrative username and password to log in.
    4. Once you have logged in, you will be presented with the Keycloak Admin Console dashboard, where you can manage and configure your Keycloak instance.

    From the Admin Console, you can perform a wide range of tasks, such as:

    • Create and manage users and groups
    • Configure identity providers and client applications
    • Define authentication and authorization policies
    • Monitor server performance and logs
    • Configure themes and templates
    • And much more.
    Overall, the Keycloak Admin Console provides a powerful set of tools for managing and securing your applications and services.

    Create client roles using admin console:

    Login to the admin console http://localhost:8080/admin/ using your admin credentials. Switch to the realm of your client. Click on your client ID from the list of ‘clients’ that you can see when clicking on Clients button in the left side navigation bar. In the next screen switch to ‘Roles’ tab and click on ‘Add Role’ button.








                                                                                                                                                                                
    We have successfully created a client role, let us add this to a user. For that click on Users button on the left side navigation bar and then click on the user id or edit button which is corresponding to the preferred user. Then go to Role Mappings tab; From the Client Roles drop down button select your preferred client; then select the role from the Available Roles area and click on Add Selected to assign that particular client role to that particular user.      


    Time to move on to the interesting part! From now we will look into how we can do all the above works programmatically in Spring Boot using Keycloak admin client API. Let’s start.

    With Spring Boot application


    Open your preferred browser and go to start.spring.io and create a new spring boot application. Make sure the following dependencies are added in pom.xml file.


    <dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-admin-client</artifactId>
    <version>11.0.3</version>
    </dependency>
    <dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.1.3.Final</version>
    </dependency>         


    Yes it is coding time!! Let’s first have a look on how to get a Keycloak instance.

    Controller for create roles, Getting all clients level roles, and make role as composite.

    @RestController
    @Log4j2
    @RequestMapping(RefoConstant.BASE_ROLE_URL)
    public class RoleController {

    private final RoleService roleService;

    public RoleController(RoleService roleService) {
    this.roleService = roleService;
    }

    @GetMapping("/fetchAllRoles")
    @Operation(summary = "fetchAllRoles", security = @SecurityRequirement(name = "AccessToken"))
    public List<RoleRepresentation> getAllRoles(HttpServletRequest request){
    return roleService.getAllRoles();
    }

    @PostMapping("/createRole")
    @Operation(summary = "createRole", security = @SecurityRequirement(name = "AccessToken"))
    public RoleResponseDTO createRole(HttpServletRequest servletRequest,@RequestBody @NotNull RoleRequestDTO request){
    return roleService.createRole(request);
    }

    @GetMapping("/{name}")
    @Operation(summary = "createRole", security = @SecurityRequirement(name = "AccessToken"))
    public RoleRepresentation getRoleByName(HttpServletRequest servletRequest,
    @PathVariable("name") String name) throws RefoException {
    return roleService.getRoleByName(name);
    }

    }      

    Role Service Interface.

    public interface RoleService {
    RoleResponseDTO createRole(RoleRequestDTO request);

    RoleRepresentation getRoleByName(String name) throws RefoException;

    List<RoleRepresentation> getAllRoles();
    }

    Fine, if it is successful we can do the magic with our keycloak instance. Follow on folks. The below code snippet shows how we can get all the available roles for the particular client registered in our keycloak server.



    @Service
    @Slf4j
    public class RoleServiceImpl implements RoleService {

    private final Keycloak keycloak;
    private final KeycloakClientConfig keycloakClientConfig;

    public RoleServiceImpl(Keycloak keycloak, KeycloakClientConfig keycloakClientConfig) {
    this.keycloak = keycloak;
    this.keycloakClientConfig = keycloakClientConfig;
    }

    public List<RoleRepresentation> getAllRoles() {
    return keycloak.realm(keycloakClientConfig.getRealm())
    .roles().list();
    }

    public RoleRepresentation getRoleByName(String roleName) throws RefoException {
    try{
    return keycloak.realm(keycloakClientConfig.getRealm())
    .roles().get(roleName).toRepresentation();
    }catch(Exception e){
    throw new RefoException(ExceptionMessageCode.REFO_ROLE_0001,String.format("%s doesn't exists!",roleName));
    }
    }

    @Override
    public RoleResponseDTO createRole(RoleRequestDTO request){
    RoleRepresentation roleRepresentation = new RoleRepresentation();
    roleRepresentation.setName(request.getName());
    roleRepresentation.setContainerId(keycloakClientConfig.getRealm());
    try{
    keycloak.realm(keycloakClientConfig.getRealm())
    .roles().create(roleRepresentation);
    return RoleResponseDTO.builder().message("Role created successfully.").build();
    }catch (ClientErrorException cee){
    if(cee.getResponse().getStatus()==409){
    return RoleResponseDTO.builder().message("Role already exists.").build();
    }else {
    return RoleResponseDTO.builder().message("Role not created.").build();
    }
    }
    }
    }


                                                                                                                                               
    Hope you enjoyed this blog. Follow me to get to know some more interesting stuffs like this. Please don’t forget to give some clapping.

    Thursday, August 10, 2017

    5 Ways To Build Bigger Arms In 2 Weeks



    You can sure sweep the girl of your dreams off her feet with your charm; but if you can lift her in Superhero-like arms that promise her to catch every time she falls, then you’ve arrived.

    Tired of scrawny arms? Time to build up some brawn up there—and that too in just a couple of weeks! Read on to build bigger arms and earn instant respect.


    Always Train Arms With A Thick Bar


    In order to develop maximum muscular size and strength, use a thick-handled bar always. It helps in developing big arms and levels of upper body power strength to such an extent which is incomprehensible to those who train only with regular bars.

    Train Your Forearms


    It’s not just your biceps that will go a long way in impressing others, but training your forearms should be an important part of your goal. If you have stick forearms, then it doesn’t matter how big your biceps or triceps are, because you will still end up having small arms.

    Dedicate A Day To Arms


    Fitness experts across the globe agree that nothing, we repeat, nothing will help you get big arms faster then training biceps, triceps and forearms together on a single day. When you are fresh and when your glycogen stores are full, that’s the best time to train your arms, as it will produce a much more intense arm workout leading to better gains. The body parts trained first will always improve faster than those at the end of the workout when you are fatigued.

    Get Leaner & Respect Your Elbows



    Yes, these are two things and two very important things. Firstly, your arms will always look bigger and better when you can see the definition and vascularity (veins) which only happens when you are lean. Secondly, you must always respect your elbows as staying injury free is very important because if you injure yourself in the elbows, your arms will be atrophying (shrinking) and not hypertrophying (growing).






    Monday, March 13, 2017

    13 Ways to Reduce Cell Phone Radiation



    Method 1:

    When talking on your cell phone, your safest bet is speakerphone mode with your phone a hand’s length away. Not quite as good (because it still emits some radiation), but better than holding the phone to your head, is a wired headset. A Bluetooth emitter is your third choice. It will deliver lower levels of microwave radiation than your cell phone, but more than the wired headset. Turn your headset off when the phone is not in use. [For best protection, CEP also recommends only using cell phone for emergencies, keeping cell phones away from babies, children and pregnant women, not holding cell phone at all, place on table two. 

     

    Method 2: 

    Try not to keep your phone turned on next to your body throughout the day. Or, if you must, position the cell phone so that the antenna, which emits radiation, is facing away from you. [For best protection: keep cell phone off when not in use and use shielded pouch to keep it in, available online at www.lessemf.com.

     



    Method 3 

    Try to use your phone when you have the maximum number of bars, indicating the best reception. When signal quality is poor, your phone emits more radiation.

     

    Method 4:

    Try not to use your cell phone in elevators, cars, trains or planes. Cell phones draw more power, and emit more radiation, in enclosed metal spaces.





    Method 5:

     Text instead of calling whenever possible. The farther your phone is from your body, the better.






    Method 6:

    When you are home, use a wired landline. Remember, cordless phones connected to a landline can emit radiation much like cell phones.






    Method 7:


    You may be tempted to use one of the many radiation shields on the market, but keep in mind that they may hamper reception, causing your cell phone to churn out more radiation. turning cell phones off when not in use and considering use of bullion mesh shielding material when using cell phone, testing effectiveness with an rf field meter that measures in microwave range, if desired.






    Method 8:

    If you have a wireless router in your house or apartment, keep it in a little-used room and out of the bedroom (or turn it off altogether at night). Strive to keep your bedroom as free of electronic radiation as possible. In addition to routers, banish cell phones, wireless phones and computers. Purists will want to unplug electric devices near the bed. If you are worried about “dirty electricity,” use a battery-powered alarm clock and make sure that extension cords or power strips do not sit under or around the bed. Avoid electric blankets and wired mattress warmers. [For best protection, not having a wireless router, use wired cable or phone line Internet only, remove all cordless phones from home, do not use cell phone in home, use landline only.






    Method 9:



    Connect to the Internet with an Ethernet cord, not a wireless router, whenever possible. For best protection, CEP recommends wired connections and elimination of all wireless in home.







    Method 10:

    Disable your computer’s wireless connectivity software, including Bluetooth, Airport and the like. Otherwise, your computer will continuously send out electronic “handshakes,” exposing you to more EMFs.

     

      

    Method 11:


    Use a “wired-only” printer, as well as wired computer peripherals like a mouse and keyboard.






    Method 12:

    The new generation of wireless baby monitors, often configured to sit right under the bed or the mattress, emit radiation comparable to a cell phone. For best protection,  recommends never using a wireless baby monitor in home. Humans are the best baby monitors!

     

    Method 13:

    Beware of radio-frequency-based smart meters, increasingly being installed by utilities around the United States to control power consumption within a house. They have come under suspicion as a significant source of electromagnetic radiation.

    Tuesday, December 20, 2016

    Free Paytm Cash Earning Apps / Websites December 2016

    How to earn free Paytm cash in December 2016: There are so many free recharge earning apps in play store. But nowadays we all are searching for android app which gives free Paytm money. So we have come up with the list of top free paytm balance earning apps & websites. You can also earn free Paytm money using these promo codes.


    LIST OF APPS / SITES TO EARN FREE PAYTM MONEY

    • Benefito: Another latest android app to earn free Paytm Cash. It’s offering Rs 10 on signup & Rs 10 per referral. Visit Benefito paytm offer page for full details & proof.
    • vStart App: New free Paytm cash / Paypal money earning app for android and It is 100% genuine. Earn free Paytm money by daily login, watching video, spin to win, scratching card, tap to get coin, taking offers & referring friends. Download vStart app & must use Referral Code  to get 50 sign up bonus.
    • Slide App: Get free mobile top up, Paytm free cash, Mobikwik balance with Slide app. Earn whether while sitting idle or traveling, just slide on the content pieces, Read, learn & earn real money. Download Slide app here, sign up using email (NOT Facebook), then verify your email to get Rs 5 registration bonus. Also refer and earn Rs 5 per referral.
    • Don App: Participate in contests & earn free Paytm money. Get free Paytm wallet for Referring friends. Redeem your earnings for prepaid recharges & postpaid bill payments. You can also transfer your earned money to paytm wallet. Download Don app & use referral code “D77A35A0” to get Rs 15 sign up bonus.
    • CashNgifts.in website: Get paytm cash by installing apps. It’s a Paytm money generator site, it offers free Paytm cash, Freecharge freefund codes, Earn free Mobikwik wallet balance, real money in cash, flipkart, amazon.in gift voucher, paypal money & much more. Visit cashngift.in.
    • Taskbucks App: How to earn free paytm cash code by downloading apps through Taskbucks. Refer & earn Rs 40 free Paytm wallet money per referral. Check Taskbucks paytm cash offer.
    • Zapstore Website: Earn Free Paytm cash by “Spin & Win” contest with Zapstore. Earn Rs 100 Paytm money daily on Zapstore.com. Check Zapstore offer for full details.
    • CashBoss App: Earn free recharge, free Paytm balance. Get high paying referral amount i.e Rs 15 per invitation. Download Cashboss app & get unlimited free Paytm cash promo codes.
    • Ladooo App: Ladooo is an old free paytm cash earning app. Get paytm cash along with prepaid mobile recharge, DTH recharge & Postpaid bill payment services. To add money in wallet refer friends, take surveys, complete offers. For step by step guide for Ladooo free recharge app paytm offer
    • Adzync Website: Free Paytm cash code generator site is Adzync. Earn Paytm wallet money, Freecharge promotional code, Bata, Baskin Robbins, Crossword, Big Cinemas, Lifestyle, Dominos Pizza, Bookmyshow, Pizza Hut, Jabong.com, Pantaloons, Amazon.in, Westride, Myntra, Big Bazaar, Sigree, Cafe Coffee Day, Mainland China, PVR Cinemas, Archies, Shopclues, Fasttrack, Cleartrip, Yatra.com & much more e-gift cards & voucher for watching ads & referring friends.  Visit Adzync.com offer page

    These are the apps that giving free Paytm money. And now you should earn some Freecharge wallet balance with these trusted apps. If you know other genuine apps offering paytm cash, then share with us. Thanks 🙂