Skip to content

Instantly share code, notes, and snippets.

View rajeevshukla's full-sized avatar
🎯
Focusing

Rajeev Shukla rajeevshukla

🎯
Focusing
View GitHub Profile
@RequestMapping("login")
public String login() {
return "login"; // will look for login.jsp inside WEB-INF/jsp/
}
@rajeevshukla
rajeevshukla / AuthController.java
Last active May 1, 2020 04:33
oauth2Login success mapping
@Autowired
OAuth2AuthorizedClientService authclientService;
@RequestMapping("/oauth2LoginSuccess")
public String getOauth2LoginInfo(Model model,@AuthenticationPrincipal OAuth2AuthenticationToken authenticationToken) {
// fetching the client details and user details
System.out.println(authenticationToken.getAuthorizedClientRegistrationId()); // client name like facebook, google etc.
System.out.println(authenticationToken.getName()); // facebook/google userId
// 1.Fetching User Info
@rajeevshukla
rajeevshukla / AuthController.java
Created May 1, 2020 04:32
Form-Based Login success mapping
@RequestMapping("/formLoginSuccess")
public String getFormLoginInfo(Model model, @AuthenticationPrincipal Authentication authentication) {
// In form-based login flow you get UserDetails as principal while in Oauth based flow you get Oauth2User
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
model.addAttribute("name", userDetails.getUsername());
return "home";
}
@rajeevshukla
rajeevshukla / login.jsp
Created May 1, 2020 04:45
Login Page snippet
<form action="/login" method="post">
<h2 class="text-center">Sign in</h2>
<div class="text-center social-btn">
<a href="/oauth2/authorization/facebook" class="btn btn-primary btn-block"><i class="fa fa-facebook"></i> Sign in with <b>Facebook</b></a>
<!-- <a href="/oauth2/authorization/google" class="btn btn-info btn-block"><i class="fa fa-google"></i> Sign in with <b>Google</b></a> -->
</div>
<div class="or-seperator"><i>or</i></div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
@rajeevshukla
rajeevshukla / application.properties
Created May 1, 2020 04:47
Application Property configuration
spring:
security:
oauth2:
client:
registration:
facebook:
client-id: <facebook client Id>
client-secret: <facebook secret Id>
scope:
- email
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Dashboard</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
@rajeevshukla
rajeevshukla / installVault.sh
Last active July 17, 2020 15:44
Vault installation steps in Ubuntu
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update
sudo apt-get install vault
root@rajeev-Latitude-5480:/home/rajeev# vault operator init -address=http://127.0.0.1:8200
Unseal Key 1: UGumETpBdy/CAQRUT2vpIk+AExIjptJRwEFch9Z0XDK1
Unseal Key 2: waqRq56mn1YAdf6wvjZ6Dz1TwqkC4ZGegAqM/lp4e9TN
Unseal Key 3: NNlZugZmOdSjUQtDwGBIEKaBQ0DN/exskH7kSH6X3dXZ
Unseal Key 4: KQ9C8yqkN4ejPPubsiSQjz2hABXmwqbAza5/e6q3d3O6
Unseal Key 5: XLgPYeRDVRneQXQ+qttQRrEC0vJdE75LaJappezUZ7GQ
Initial Root Token: s.lL1wRFK79QQQRflLyIS3WyYm
Vault initialized with 5 key shares and a key threshold of 3. Please securely
listener "tcp" {
address = "127.0.0.1:8200"
tls_disable = true
}
storage "file" {
path = "/opt/vault/data"
}
ui = true
root@rajeev-Latitude-5480:/home/rajeev# vault operator unseal waqRq56mn1YAdf6wvjZ6Dz1TwqkC4ZGegAqM/lp4e9TN 
Key Value
 - - - - -
Seal Type shamir
Initialized true
Sealed true
Total Shares 5
Threshold 3
Unseal Progress 2/3
Unseal Nonce 181be784–7c72-a040–48a5–105eb398f026