working Spring Boot oauth2 connection to nextcloud oidc
This commit is contained in:
13
src/main/java/de/ship/nextcloud/ClientApplication.java
Normal file
13
src/main/java/de/ship/nextcloud/ClientApplication.java
Normal file
@ -0,0 +1,13 @@
|
||||
package de.ship.nextcloud;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ClientApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ClientApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
13
src/main/java/de/ship/nextcloud/ServletInitializer.java
Normal file
13
src/main/java/de/ship/nextcloud/ServletInitializer.java
Normal file
@ -0,0 +1,13 @@
|
||||
package de.ship.nextcloud;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(ClientApplication.class);
|
||||
}
|
||||
|
||||
}
|
20
src/main/java/de/ship/nextcloud/config/SecurityConfig.java
Normal file
20
src/main/java/de/ship/nextcloud/config/SecurityConfig.java
Normal file
@ -0,0 +1,20 @@
|
||||
package de.ship.nextcloud.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
@Bean
|
||||
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests(r -> r
|
||||
.requestMatchers("/").permitAll().requestMatchers("/index").permitAll()
|
||||
.requestMatchers("/inside").authenticated())
|
||||
.oauth2Login(l -> l.authorizationEndpoint(e -> e.baseUri("/oauth2/authorize-client")))
|
||||
.oidcLogout();
|
||||
return http.build();
|
||||
}
|
||||
}
|
30
src/main/java/de/ship/nextcloud/modules/Check.java
Normal file
30
src/main/java/de/ship/nextcloud/modules/Check.java
Normal file
@ -0,0 +1,30 @@
|
||||
package de.ship.nextcloud.modules;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henkej
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class Check {
|
||||
|
||||
@GetMapping("/")
|
||||
public String getRoot() {
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@GetMapping("/index")
|
||||
public String getIndex() {
|
||||
return "/index";
|
||||
}
|
||||
|
||||
@GetMapping("/inside")
|
||||
public String getMapping(Model model) {
|
||||
model.addAttribute("authenticated", "Die nextcloud-Authentifizierung hat funktioniert.");
|
||||
return "/inside";
|
||||
}
|
||||
}
|
8
src/main/resources/application.properties
Normal file
8
src/main/resources/application.properties
Normal file
@ -0,0 +1,8 @@
|
||||
server.port = 9999
|
||||
|
||||
# required
|
||||
spring.security.oauth2.client.provider.nextcloud.issuer-uri = http://localhost
|
||||
spring.security.oauth2.client.registration.nextcloud.client-id = XvDdIXcOFERJq4p2si5ydI8EO3u3VcuTDXtEvGybGm2ILhg2vpSV1nXdG9QKyr5C
|
||||
spring.security.oauth2.client.registration.nextcloud.client-secret = sd5SAhh4TNyj5When1i83JqtJK5MzHaBDY2ChWvFzSsvnBdwyOozFFdyMRIxnFDt
|
||||
spring.security.oauth2.client.registration.nextcloud.authorization-grant-type = authorization_code
|
||||
spring.security.oauth2.client.registration.nextcloud.redirect-uri = http://localhost:9999/login/oauth2/code/herbert
|
29
src/main/resources/nextcloud-config/docker-compose.yml
Normal file
29
src/main/resources/nextcloud-config/docker-compose.yml
Normal file
@ -0,0 +1,29 @@
|
||||
version: '3'
|
||||
services:
|
||||
db:
|
||||
image: mariadb
|
||||
restart: always
|
||||
volumes:
|
||||
- nextcloud-db:/var/lib/mysql
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=password
|
||||
- MYSQL_DATABASE=nextcloud
|
||||
- MYSQL_USER=nextcloud
|
||||
- MYSQL_PASSWORD=password
|
||||
|
||||
app:
|
||||
image: nextcloud
|
||||
restart: always
|
||||
ports:
|
||||
- 80:80
|
||||
volumes:
|
||||
- nextcloud:/var/www/html
|
||||
environment:
|
||||
- MYSQL_HOST=db
|
||||
- MYSQL_DATABASE=nextcloud
|
||||
- MYSQL_USER=nextcloud
|
||||
- MYSQL_PASSWORD=password
|
||||
|
||||
volumes:
|
||||
nextcloud-db:
|
||||
nextcloud:
|
BIN
src/main/resources/nextcloud-config/nextcloud-install-oidc.png
Normal file
BIN
src/main/resources/nextcloud-config/nextcloud-install-oidc.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 93 KiB |
BIN
src/main/resources/nextcloud-config/nextcloud-oidc-config.png
Normal file
BIN
src/main/resources/nextcloud-config/nextcloud-oidc-config.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 120 KiB |
9
src/main/resources/templates/index.html
Normal file
9
src/main/resources/templates/index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<a th:href="@{/inside}">Betreten</a>
|
||||
</body>
|
||||
</html>
|
11
src/main/resources/templates/inside.html
Normal file
11
src/main/resources/templates/inside.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<span th:text="${authenticated}"></span>
|
||||
<br />
|
||||
<a th:href="@{/logout}">abmelden</a>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user