Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Lấy dữ liệu từ 1 trang web trong spring boot
Em chào mọi người.<p> Em có câu hỏi là làm cách nào để lấy được data từ Api của 1 trang web ạ em sử dụng spring boot. </p>
Answer
Avatar
0
Chan Beginner
Chan Beginner
maxhistory logback not working
Em chào anh và mọi người<p> Em có làm file logback và em có thêm phần "&lt; maxHistory > 30 &lt; / maxHistory >" để lưu log trong 30 ngày nhưng nó lại không hoạt đông. Em có tham khảo nhiều tài liệu trên mạng nhưng không được. Anh và mọi người ở đây đã ai làm về phần này có thể tư vấn cho em được không ạ </p> <p> Em xin cảm ơn </p>
Answer
Avatar
0
Tran Duy Tung Beginner
Tran Duy Tung Beginner
Lưu dữ liệu từ Activemq vào Elasticsearch
Em chào anh.<p> Em đang có 1 task lấy data từ Activemq đã đưọc đọc và lưu vào Elasticsearch. Tuy nhiên em chưa có hướng để làm phần này. Anh có thể giúp em được không ạ. </p> <p> Em cảm ơn ạ </p>
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Xác thực oauth2 trong spring 3.1.x và spring security 6.1.x
Em chào anh trong quá trình chuyển spring 2.4.x lên 3.1.x phần xác thực oauth2 trong dự án em gặp vấn đề <ul> <li>Spring 3.1.x không còn hỗ trợ WebSecurityConfigurerAdapter Lib spring-security-oauth2-autoconfigure</li></ul> <p> em chuyển sang các thư viện thay thế </p> <div class="markdown-block position-relative overflow-auto source-groovy"> <pre> spring-boot-starter-oauth2-resource-server 3.1.4 spring-boot-starter-oauth2-client 3.1.4 spring-security-oauth2-authorization-server 1.1.3 </pre> </div><p> và cấu hình </p> <div class="markdown-block position-relative overflow-auto source-groovy"> <pre> spring.security.oauth2.client.registration.sales.authorization-grant-type=password,authorization_code spring.security.oauth2.client.registration.sales.client-id=sales spring.security.oauth2.client.registration.sales.client-secret=password spring.security.oauth2.client.registration.sales.scope[0]=user_info spring.security.oauth2.client.provider.sales.authorization-uri=http://port:8668/sso-server/oauth/check_token </pre> </div><p> nhưng có vẻ không hoạt động </p> <p> làm sao để cấu hình lại phần oauth2 ạ </p> <p> code config ban đầu </p> <div class="markdown-block position-relative overflow-auto source-java"> <pre> <span class="pl-s">@Configuration</span> <span class="pl-s">@EnableResourceServer</span> <span class="pl-s">@EnableGlobalMethodSecurity</span>(prePostEnabled = true) <span class="pl-k">public</span> <span class="pl-k">class</span> ResourceServer <span class="pl-k">extends</span> ResourceServerConfigurerAdapter { <span class="pl-s">@Value</span>(<span class="pl-s">"${oauth2.token-endpoint-url}"</span>) private String tokenEndpointUrl; <span class="pl-s">@Value</span>(<span class="pl-s">"${oauth2.client-id}"</span>) private String clientId; <span class="pl-s">@Value</span>(<span class="pl-s">"${oauth2.client-secret}"</span>) private String clientSecret; <span class="pl-s">@Bean</span> <span class="pl-k">public</span> RemoteTokenServices tokenServices() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { RemoteTokenServices tokenServices = <span class="pl-k">new</span> RemoteTokenServices(); tokenServices.setCheckTokenEndpointUrl(tokenEndpointUrl); tokenServices.setClientId(clientId); tokenServices.setClientSecret(clientSecret); <span class="pl-k">return</span> tokenServices; } <span class="pl-s">@Override</span> <span class="pl-k">public</span> <span class="pl-k">void</span> configure(HttpSecurity http) throws Exception { http.cors().and() .requestMatchers().antMatchers(<span class="pl-s">"/api/**"</span>).and().authorizeRequests().anyRequest().authenticated(); } } </pre> </div>
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Lấy userName từ SecurityContextHolder
em chào anh, trong quá trình nâng từ spring 2.7.x lên 3.1.x phần Authentication em không lấy được username login, username login là namtv , username log ra lại mặc định là anonymousUser và login thành công<p> em k rõ là do cơ chế lấy userName đã thay đổi hay do không xác thực được ạ </p> <p> Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); </p> <p> String userName = authentication.getName(); </p>
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Thay thế Esapi trong spring boot 3.1.x
Trong dự án em đang sử dụng org.owasp.esapi <p> ( <a href="https://mvnrepository.com/artifact/org.owasp.esapi/esapi/2.5.2.0 " target="_blank">https://mvnrepository.com/artifact/org.owasp.esapi/esapi/2.5.2.0 </a> ) </p> <p> trong thư viện em này em sử dụng để mã hoá log, redirect url </p> <p> trong quá trình nâng cấp lên spring boot 3.1.1 thì thư viện trên chỉ hỗ trợ javax.servlet mà spring 3.1.x hỗ trợ jakatar.servlet vậy có thể thay thế thư viện trên bằng thư viện nào khách không ạ </p>
Answer
Avatar
0
devman Beginner
devman Beginner
làm sao để read/write dữ liệu từ Redis cluster mà bảo đảm consistency
chào mọi người,<p> Mình sử dụng Redis cluster trong dự án và Java spring boot với redis library là Lettuce. Theo mình biết thì mặc định khi write dữ liệu sẽ write vào node master, còn read sẽ read ở node slave. Mình gặp phải vấn đề khi chạy application theo kiểu active - active. khi instance 1 write, sau đó không lâu thì instance 2 sẽ lấy lại dữ liệu và xử lý nhưng redis chưa đồng bộ dữ liệu từ node master tới slave nên dẫn tới dữ liệu không đồng nhất. Nếu mình write/read trên master thì ảnh hưởng đến việc write và làm chậm chương trình. Mình đang tạm thời xử lý theo cách là dữ liệu sẽ chỉ xử lý trên một instance(hash theo key để biết được dữ liệu nào sẽ được xử lý bởi instance nào) và sử dụng thêm memory cache(caffeine cache) để cache lại dữ liệu. Liệu có cách nào để tốt hơn để xử lý vấn đề trên không ạ? và có best practice nào để cải thiện chương trình không? </p>
Answer
Avatar
0
Khoi Nguyen Beginner
Khoi Nguyen Beginner
Đăng nhập 2 hình thức jwt api(google authentication và basic login)
<ul> <li>Em làm đăng nhập bằng hai phương thức khi mà đăng nhập bằng basic thì không sao cho đến thi thêm oauth2 vào thì bị lỗi. Em có source code anh chị xem cho em với ạ <a href="https://gitlab.com/sep490_g55/backend/-/blob/khoint/src/main/java/com/capstone/backend/security/jwt/JwtAuthenticationFilter.java?ref_type=heads">link</a> , nó báo lỗi ở dòng số 47 (Cannot invoke "org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken.getPrincipal()" because "oAuth2AuthenticationToken" is null)</li> <li>Với còn 1 bug nữa là khi em upload file multipart sử dụng method post thì nó báo lỗi 401 ạ <a href="https://gitlab.com/sep490_g55/backend/-/blob/khoint/src/main/java/com/capstone/backend/controller/ResourceController.java?ref_type=heads">link</a></li> <li>Em mò mất mấy ngày mà nó vẫn không ra. Em cảm ơn anh chị</li></ul>
Answer
Avatar
0
Nguyen Thai Son Beginner
Khi nào thật sự cần dùng Reflection ạ
Khi nào thật sự cần dùng Reflection vậy anh, một cái nữa em thắc mắc với cả @Inteface ạ
Answer
Avatar
0
Nguyen Thai Son Beginner
check Null không dùng if object != Null
anh ơi làm sao check Null không dùng if object != Null, ý em là có thể check được bằng cách dùng reflection k ạ
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Trừu tượng trong OOP
Trong java Nếu bỏ abstract class với interface thì có còn thể hiện được được tính trừu tượng trong lập trình k ạ
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Sử lí responses trong microservice khi request được sử lí bởi nhiều service
Frontend gửi request order tới API Gateway thông qua REST API, order được điều hướng tới service A. Service A xử lý xong gửi order sang service B thông qua message queue. Service B xử lý xong là hết thúc quá trình xử lý order. Làm sao để hệ thống trả lại response cho frontend?
Answer