Skip to content

Instantly share code, notes, and snippets.

View h-hub's full-sized avatar
🤖
implementing something

Harsha Jayamanna h-hub

🤖
implementing something
View GitHub Profile
Auth.currentCredentials().then( res => {
this.service.getDataFromAws(res).subscribe(
data => {
this.dbItem = data;
},
error => {
this.error = "Unable to connect to the service.";
}
)
package com.harshajayamanna.blog.service;
import com.harshajayamanna.blog.entity.BlogPost;
import com.harshajayamanna.blog.entity.Meta;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.transaction.Transactional;
import java.io.Serializable;
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="blogpostunit"
transaction-type="JTA">
<application location="jakartaee8-hibernate-example.war"
contextRoot="/" >
<classloader commonLibraryRef="hibernate"/>
</application>
<dataSource id="hibernatemysqldb"
jndiName="jdbc/recruittimesdb">
<jdbcDriver libraryRef="MySQLLib" />
<properties databaseName="test_db"
serverName="localhost" password="admin1234" user="root"
serverTimezone="UTC" portNumber="3306" />
</dataSource>
<library id="MySQLLib">
<file
@PreAuthorize("hasRole('ROLE_ROLE_ADMIN')")
@RequestMapping(value = "/test", method = RequestMethod.GET, produces = { "application/json",
"application/xml" })
@ResponseBody
@ResponseStatus(code = HttpStatus.OK)
public Map<String, String> get() {
String hostname = null;
try {
hostname = InetAddress.getLocalHost()
@Component
public class UsernameSubClaimAdapter implements Converter<Map<String, Object>, Map<String, Object>> {
private final MappedJwtClaimSetConverter delegate = MappedJwtClaimSetConverter.withDefaults(Collections.emptyMap());
@Override
public Map<String, Object> convert(Map<String, Object> claims) {
Map<String, Object> convertedClaims = this.delegate.convert(claims);
if (claims.containsKey("cognito:groups")) {
convertedClaims.put("authorities", claims.get("cognito:groups"));
@Bean
public JwtDecoder jwtDecoder() {
NimbusJwtDecoder jwtDecoder = (NimbusJwtDecoder) JwtDecoders.fromIssuerLocation(issuerUri);
OAuth2TokenValidator<Jwt> withClockSkew = new DelegatingOAuth2TokenValidator<>(
new JwtTimestampValidator(Duration.ofSeconds(60)), new JwtIssuerValidator(issuerUri));
jwtDecoder.setJwtValidator(withClockSkew);
jwtDecoder.setClaimSetConverter(new UsernameSubClaimAdapter());
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors();
http.csrf().disable();
http.authorizeRequests().antMatchers("/status").permitAll().anyRequest().authenticated().and()
.oauth2ResourceServer().jwt();
}
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://cognito-idp.ap-southeast-1.amazonaws.com/ap-southeast-xxxxxxxxx
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://cognito-idp.ap-southeast-1.amazonaws.com/ap-southeast-xxxxxxxxx/.well-known/jwks.json