Skip to content

Commit

Permalink
初始化ng-ui项目,添加基础配置和初始代码。
Browse files Browse the repository at this point in the history
本次提交包括以下内容:
- 创建ng-ui项目目录和初始文件结构。
- 配置.vscode目录下的settings.json、extensions.json、launch.json和tasks.json文件,以优化开发环境和体验。
- 添加docker相关配置,包括Dockerfile和web.json文件,用于构建和配置nginx服务。
- 在projects/commons目录下初始化一个Angular库,并配置相应的tsconfig文件、ng-package.json和package.json文件。- 添加BrowserStorage.service.ts和BrowserStorageServer.service.ts文件,提供浏览器存储服务的实现。
- 创建commons.component.ts、commons.component.spec.ts和commons.service.ts文件,作为库的示例组件和服务。
- 添加public-api.ts文件,导出库的公共API。
- 初始化ng-ui项目的README.md文件,提供项目简介和说明。

这些更改将为后续的开发工作奠定基础,并优化开发环境和构建流程。
  • Loading branch information
vnobo committed Jul 8, 2024
1 parent 9c3372a commit cbed6ad
Show file tree
Hide file tree
Showing 124 changed files with 154 additions and 20,036 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
import org.springframework.security.config.annotation.rsocket.EnableRSocketSecurity;
import org.springframework.security.config.annotation.rsocket.RSocketSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.jwt.JwtException;
import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder;
import org.springframework.security.oauth2.jwt.ReactiveJwtDecoders;
import org.springframework.security.rsocket.core.PayloadSocketAcceptorInterceptor;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.authentication.HttpBasicServerAuthenticationEntryPoint;
Expand Down Expand Up @@ -48,6 +53,7 @@
*/
@Configuration(proxyBeanMethods = false)
@EnableReactiveMethodSecurity
@EnableRSocketSecurity
@RequiredArgsConstructor
public class SecurityConfiguration {

Expand All @@ -60,15 +66,24 @@ public PasswordEncoder passwordEncoder() {

@Bean
public PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
rsocket.authorizePayload(authorize -> authorize.anyRequest().permitAll().anyExchange().permitAll())
rsocket.authorizePayload(authorize ->
authorize
.route("request.stream").authenticated()
.anyRequest().authenticated()
.anyExchange().permitAll()
)
.simpleAuthentication(Customizer.withDefaults());
return rsocket.build();
}

public ReactiveJwtDecoder jwtDecoder() {
return ReactiveJwtDecoders.fromIssuerLocation("http://localhost:8080/oauth2/realms/issuer");
}

@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http.authorizeExchange(exchange -> {
exchange.pathMatchers("/captcha/code", "/oauth2/qr/code","/command/v1/send").permitAll();
exchange.pathMatchers("/captcha/code", "/oauth2/qr/code","/oauth2/realms/issuer/**").permitAll();
exchange.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();
exchange.pathMatchers("/tenants/**", "/users/**", "/groups/**")
.hasAnyRole("SYSTEM_ADMINISTRATORS", "ADMINISTRATORS");
Expand All @@ -85,6 +100,13 @@ public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http)
return http.build();
}

static class ReactiveJwtDecoderToken implements ReactiveJwtDecoder {
@Override
public Mono<Jwt> decode(String token) throws JwtException {
return null;
}
}

private void setCsrfSpec(ServerHttpSecurity.CsrfSpec csrfSpec) {
csrfSpec.requireCsrfProtectionMatcher(new IgnoreRequireCsrfProtectionMatcher());
csrfSpec.csrfTokenRepository(CookieServerCsrfTokenRepository.withHttpOnlyFalse());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.platform.boot.config;

import io.rsocket.metadata.WellKnownMimeType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -9,6 +10,10 @@
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.rsocket.metadata.SimpleAuthenticationEncoder;
import org.springframework.security.rsocket.metadata.UsernamePasswordMetadata;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;

Expand All @@ -27,8 +32,13 @@ public class WebConfiguration implements WebFluxConfigurer {

@Bean
public RSocketRequester rSocketRequester(RSocketRequester.Builder requesterBuilder, RSocketMessageHandler handler) {
MimeType authenticationMimeType =
MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.getString());
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("admin", "123456");
URI url = URI.create("http://localhost:" + serverPort + "/rsocket");
return requesterBuilder.setupData("CommandClient").setupRoute("connect.setup")
.setupMetadata(credentials, authenticationMimeType)
.rsocketStrategies(strategies->strategies.encoder(new SimpleAuthenticationEncoder()))
.rsocketConnector(connector -> connector.acceptor(handler.responder())).websocket(url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.extern.log4j.Log4j2;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
Expand Down Expand Up @@ -47,13 +48,15 @@ public void send(MessageIn message) {
}
}

@Scheduled(fixedDelay = 10000)
public void taskTest() {
if (this.clients.isEmpty() || !this.clients.containsKey("CommandClient")) {
return;
}
ConnectedClient connectedClient = this.clients.get("CommandClient");
connectedClient.getRequester().route("user.message")
.data(MessageOut.of(MessageType.COMMAND, "test", "test").status(200))
.send().subscribe();
connectedClient.getRequester().route("request.sender")
.data(MessageIn.of(MessageType.COMMAND, "test", "test"))
.retrieveMono(MessageOut.class).subscribe(out ->
log.debug("CommandClient send message result : {}", out));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.platform.boot.security;

import com.platform.boot.commons.exception.RestServerException;
import com.platform.boot.commons.utils.BeanUtils;
import com.platform.boot.commons.utils.ContextUtils;
import com.platform.boot.security.core.AuthenticationToken;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository;
Expand All @@ -17,6 +19,8 @@
import org.springframework.web.server.WebSession;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
* @author <a href="https://github.com/vnobo">Alex bob</a>
*/
Expand All @@ -29,11 +33,18 @@ public class SecurityController {
private final PasswordEncoder passwordEncoder;
private final ServerOAuth2AuthorizedClientRepository clientRepository;

@GetMapping("/realms/issuer")
public Mono<Map<String,Object>> issuer(SecurityDetails principal) {
return ReactiveSecurityContextHolder.getContext().map(securityContext -> BeanUtils.beanToMap(securityContext
.getAuthentication().getDetails()));
}
@GetMapping("token")
public Mono<AuthenticationToken> token(WebSession session, Authentication authentication) {
return Mono.defer(() -> Mono.just(AuthenticationToken.build(session, authentication)));
}



@GetMapping("csrf")
public Mono<CsrfToken> csrfToken() {
return Mono.deferContextual((contextView) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import java.io.Serializable;

/**
* @author billb
*/
public record AuthenticationToken(String token, Long expires, Long lastAccessTime,
Object details) implements Serializable {

Expand Down
26 changes: 6 additions & 20 deletions ng-ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"outputPath": "dist/web",
"index": "projects/web/src/index.html",
"browser": "projects/web/src/main.ts",
"polyfills": ["@angular/localize/init", "zone.js"],
"polyfills": ["@angular/localize/init"],
"tsConfig": "projects/web/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
Expand All @@ -35,25 +35,11 @@
}
],
"styles": [
{
"input": "node_modules/bootstrap/dist/css/bootstrap.css",
"bundleName": "bootstrap"
},
{
"input": "node_modules/bootstrap-icons/font/bootstrap-icons.css",
"bundleName": "icons"
},
{
"input": "projects/web/src/styles.scss",
"bundleName": "main"
}
],
"scripts": [
{
"input": "node_modules/bootstrap/dist/js/bootstrap.bundle.js",
"bundleName": "bootstrap"
}
"node_modules/bootstrap/dist/css/bootstrap.css",
"node_modules/bootstrap-icons/font/bootstrap-icons.css",
"projects/web/src/styles.scss"
],
"scripts": ["node_modules/bootstrap/dist/js/bootstrap.bundle.js"],
"optimization": {
"scripts": true,
"styles": {
Expand Down Expand Up @@ -117,7 +103,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": ["@angular/localize/init", "zone.js", "zone.js/testing"],
"polyfills": ["@angular/localize/init"],
"tsConfig": "projects/web/tsconfig.spec.json",
"inlineStyleLanguage": "sass",
"assets": [
Expand Down
6 changes: 3 additions & 3 deletions ng-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions ng-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"ng-zorro-antd": "^18.0.0",
"plate-commons": "^0.0.3",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
"tslib": "^2.3.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^18.0.6",
Expand Down
Binary file removed ng-ui/projects/app/public/favicon.ico
Binary file not shown.
57 changes: 0 additions & 57 deletions ng-ui/projects/app/server.ts

This file was deleted.

Empty file.
Loading

0 comments on commit cbed6ad

Please sign in to comment.