Commit b6e6620e authored by Jannik Hüls's avatar Jannik Hüls

added backend app

parent b3801e29
# The Backend
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.codecentric</groupId>
<artifactId>keycloakspring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>keycloakspring</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-adapter</artifactId>
<version>4.7.0.Final</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-tomcat8-adapter</artifactId>
<version>4.7.0.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package de.codecentric.keycloakspring;
import org.keycloak.KeycloakPrincipal;
import org.keycloak.representations.AccessToken;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
@SpringBootApplication
public class KeycloakspringApplication {
public static void main(String[] args) {
SpringApplication.run(KeycloakspringApplication.class, args);
}
}
package de.codecentric.keycloakspring;
import org.keycloak.KeycloakPrincipal;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin(origins = { "http://localhost:8081" }, maxAge = 3000)
@RestController
public class PageController {
@RequestMapping("/user")
public String user(Model model, KeycloakPrincipal principal) {
return "usercontent";
}
@RequestMapping(value = "/admin")
public String admin(Model model, KeycloakPrincipal principal) {
return "admincontent";
}
}
package de.codecentric.keycloakspring;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
}
server.port=8082
keycloak.realm=
keycloak.auth-server-url=
keycloak.credentials.secret=
keycloak.resource=
keycloak.ssl-required=external
keycloak.public-client=false
keycloak.principal-attribute=preferred_username
keycloak.bearer-only=true
keycloak.cors=true
keycloak.use-resource-role-mappings=false
keycloak.securityConstraints[0].securityCollections[0].patterns[0]=/css/*
keycloak.securityConstraints[0].securityCollections[0].patterns[1]=/fonts/*
keycloak.securityConstraints[0].securityCollections[0].patterns[2]=/js/*
keycloak.securityConstraints[0].securityCollections[0].patterns[3]=/logout
keycloak.securityConstraints[1].authRoles[0] = user
keycloak.securityConstraints[1].securityCollections[0].name = insecure stuff
keycloak.securityConstraints[1].securityCollections[0].patterns[0] = /user
keycloak.securityConstraints[2].authRoles[0] = admin
keycloak.securityConstraints[2].securityCollections[0].name = admin stuff
keycloak.securityConstraints[2].securityCollections[0].patterns[0] = /admin
#keycloak.policy-enforcer-config.on-deny-redirect-to=/accessDenied
#keycloak.policy-enforcer-config.paths[0].name=Default Resource
#keycloak.policy-enforcer-config.paths[0].path=/*
#keycloak.policy-enforcer-config.paths[1].name=User Resource
#keycloak.policy-enforcer-config.paths[1].path=/user
#keycloak.policy-enforcer-config.paths[0].name=Default Resource
#keycloak.policy-enforcer-config.paths[0].path=/*
#keycloak.policy-enforcer-config.paths[1].name=Admin Resource
#keycloak.policy-enforcer-config.paths[1].path=/admin
package de.codecentric.keycloakspring;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class KeycloakspringApplicationTests {
@Test
public void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment