Skip to content

Instantly share code, notes, and snippets.

View kbzsoft's full-sized avatar
😀
Focusing

kbzsoft kbzsoft

😀
Focusing
View GitHub Profile
@kbzsoft
kbzsoft / CustomErrorController.java
Created November 11, 2019 06:52 — forked from jonikarppinen/CustomErrorController.java
Example of replacing Spring Boot "whitelabel" error page with custom error responses (with JSON response body)
package com.company.project.controllers;
import com.company.project.model.api.ErrorJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
@kbzsoft
kbzsoft / KeycloakAdminClientExample.java
Created June 24, 2019 05:43 — forked from thomasdarimont/KeycloakAdminClientExample.java
Using Keycloak Admin Client to create user with roles (Realm and Client level)
package de.tdlabs.keycloak.client;
import java.util.Arrays;
import java.util.Collections;
import javax.ws.rs.core.Response;
import org.keycloak.OAuth2Constants;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
@kbzsoft
kbzsoft / UserRestControllerTest.java
Created June 20, 2019 01:37 — forked from ekswai/UserRestControllerTest.java
spring oauth2 rest template with client credentials grant sample
import org.junit.Test;
import org.junit.runner.RunWith;
import org.master.Application;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;