Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
sandipchitale / DefaultOAuth2AuthorizationRequestResolver.java
Last active June 14, 2023 08:35
Where the state parameter is created #oauth2_client
builder.clientId(clientRegistration.getClientId())
.authorizationUri(clientRegistration.getProviderDetails().getAuthorizationUri())
.redirectUri(redirectUriStr)
.scopes(clientRegistration.getScopes())
.state(DEFAULT_STATE_GENERATOR.generateKey());
private static final StringKeyGenerator DEFAULT_STATE_GENERATOR = new Base64StringKeyGenerator(
Base64.getUrlEncoder());
@sandipchitale
sandipchitale / infoarchive.ldif
Last active June 5, 2023 23:31
Openldap #openldap
# extended LDIF
#
# LDAPv3
# base <dc=infoarchive,dc=opentext,dc=com> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
# infoarchive.opentext.com
dn: dc=infoarchive,dc=opentext,dc=com
@sandipchitale
sandipchitale / ModifyHttpServletResponse.java
Last active May 21, 2023 07:19
Modify HttpServletResponse #spring-web-mvc #springframework
public static class LoginResponseFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
if (request.getRequestURI().equals("/login") && request.getMethod().equals(HttpMethod.GET.name())) {
ContentCachingResponseWrapper contentCachingResponseWrapper = new ContentCachingResponseWrapper(response);
filterChain.doFilter(request, contentCachingResponseWrapper);
byte[] content = contentCachingResponseWrapper.getContentAsByteArray();
String html = new String(content, StandardCharsets.UTF_8);
// Fix favicon.ico
@sandipchitale
sandipchitale / visualizer.js
Last active May 19, 2023 07:35
OAuth2 visualizer for Postman #postman #oauth2_tokens
let context = {};
let authorizationHeaderValue = pm.request.headers.get('Authorization');
if (authorizationHeaderValue && authorizationHeaderValue.startsWith('Bearer ')) {
authorizationHeaderValue = authorizationHeaderValue.substring(7);
let authorizationHeaderValue_access_token_parts = authorizationHeaderValue.split('.');
if (authorizationHeaderValue_access_token_parts.length === 3) {
context.authorizationHeader_access_token = {};
context.authorizationHeader_access_token.header = JSON.stringify(JSON.parse(atob(authorizationHeaderValue_access_token_parts[0])), null, ' ');
context.authorizationHeader_access_token.payload = JSON.stringify(JSON.parse(atob(authorizationHeaderValue_access_token_parts[1])), null, ' ');
}
@sandipchitale
sandipchitale / GetRequest.java
Last active May 12, 2023 03:35
Get hold of current request #spring-web-mvc
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes servletRequestAttributes) {
HttpServletRequest httpServletRequest = servletRequestAttributes.getRequest();
HttpServletResponse httpServletResponse= servletRequestAttributes.getResponse();
}
@sandipchitale
sandipchitale / DumpObjectUsingObjectMapper.java
Last active May 8, 2023 07:35
Dump object using ObjectMapper #springframework
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT); //pretty print
try {
System.out.println(objectMapper.writeValueAsString(ANY_OBJECT));
} catch (JsonProcessingException e) {
}
/*
Output:
{
@sandipchitale
sandipchitale / CLR.java
Last active May 8, 2023 07:17
Dump bean names and class names #springframework
@Component
public static class CLR implements CommandLineRunner, ApplicationContextAware {
private ApplicationContext applicationContext;
@Override
public void run(String... args) throws Exception {
if (this.applicationContext != null) {
String[] beanDefinitionNames = this.applicationContext.getBeanDefinitionNames();
for (String beanDefinitionName : beanDefinitionNames) {
System.out.println("Bean: " + beanDefinitionName + " = "
@sandipchitale
sandipchitale / NOTES.md
Last active June 26, 2023 23:34
Spring Security OAuth2 Bookmarks #oauth2_bookmarks
  • The place where code is exchanged for OAuth2Tokens
ResponseEntity<OAuth2AccessTokenResponse> org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient.getResponse(RequestEntity<?> request)
  • Client Authentication Methods
org.springframework.security.oauth2.core.ClientAuthenticationMethod
@sandipchitale
sandipchitale / CLR.java
Last active May 8, 2023 06:38
Spring Security OAuth2 Client with Client Credentials #oauth2_client_with_client_credentials
import java.util.Arrays;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.ConfigurableEnvironment;
@sandipchitale
sandipchitale / application.yaml
Last active August 17, 2023 23:06
httpclient5 logging #httpclient5 #logging
logging:
level:
root: WARN
'[org.springframework.web]': TRACE
'[org.springframework.http]': TRACE
'[org.apache.http]': TRACE
'[org.apache.hc.client5.http]': TRACE
'[org.apache.http.wire]': DEBUG
logging: