分类 it 中的文章

Gin Jwt Middleware

JWT in golang golang中的jwt包一般是使用 github.com/dgrijalva/jwt-go, 而且godoc中已经有些example,这里只是记录一下使用 jwt.StandardClaims的情况。 func parseToken(tokenString string) (*jwt.StandardClaims, error) { token, err := jwt.ParseWithClaims(tokenString, &jwt.StandardClaims{}, func(t *jwt.Token) (interface{}, error) { return jwtKey, nil }) if err != nil { log.Errorf("error: %v", err) return nil, fmt.Errorf("failed to parse the token string: %s", tokenString) } log.Printf("claims: %v", token.Claims) if claims, ok := token.Claims.(*jwt.StandardClaims); ok && token.Valid { return claims, nil } else { return nil, errors.Wrap(fmt.Errorf("failed to valiate the token"), "failed") } }……

阅读全文

Liberty Profile Tls V1 Gaps

Gap - TLS version 1.0/1.1 detected 如果在做security scan的时候,有这两个gap,需要修改两个地方 liberty profile server.xml add sslProtocol="TLSv1.2" to ssl <ssl id="defaultSSLConfig" sslProtocol="TLSv1.2" keyStoreRef="defaultKeyStore" securityLevel="CUSTOM" enabledCiphers="TLS_RSA_WITH_AES_128_CBC_SHA TLS_RSA_WITH_AES_128_CBC_SHA256 "/> server.env add JVM_ARGS=-Dhttps.protocols=TLSv1.2……

阅读全文

React for Beginners

Prerequesite node javascript html css es6 code editor create-react-app npm install -g create-react-app create-react-app app-name React component state class component里面管理状态使用state class Counter extends Component { state = { counter: 10, title: "this is demo", products: [ { id: 1, name: "ok", }, { id: 2, name: "bad", }, ], }; // ..... other } render jsx expression attributes list/array conditional rendering handle events binding event handlers updating state event arguments passing data to component passing children debug react app props vs state raising and handle events multiple component in sync lifting state up functional component destructure arguments lifecycle hooks……

阅读全文

添加第三方jar到Spring Boot application

背景 有时候需要添加第三方的jar包到spring boot工程中,因为不能从maven repository直接下载,所以需要包含在代码库中。 一般需要在 src/main 目录下,可以建个新目录 lib, 然后把jar文件放到这个目录下,也就是 src/main/lib下. 然后在pom.xml中需要添加 group……

阅读全文

Postgres 备份与恢复

背景 有时候我们需要备份 schema或者包括数据,然后恢复到另外一个postgres db中。 备份 可以使用 pg_dump 来备份,或者加上 –schema-only 只备份schema. pg_dump --file "/root/repo/uat-copy.tar" --host "db host name" --port "23123" --username "admin" --password --verbose --format=t --blobs --schema-only "compose" 恢复 同样的,可以使用pg_restore来恢复 pg_restore --host "hostname here" --port "31090" --username "usernamehere" --password --dbname "ibmclouddb" --verbose "/root/repo/uat-copy.tar" 不管备份还是恢复,都会要求输入密……

阅读全文

Auto Login Server Without Password

配置方法,做个小记录 server 上要配置允许 用户电脑 在 .ssh/config 文件中 Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa Host xxx HostName xx.xx.xx.xx User jerry 把pub key传到server ssh-copy-id -i ~/.ssh/id_rsa.pub xx@xx.xx.xx.x 可以了……

阅读全文

Vue File Download From Spring Boot

File download 如果spring boot的写法是我在另外一个文章, 返回的response其实是一个Blob, 这一点要记住 this.axios.get(url, { responseType: 'blob', timeout: 0 }).then(response => { // response is Blob <------- const url = window.URL.createObjectURL(response) const a = document.createElement('a') a.style.display = 'none' a.href = url a.setAttribute('download','file.xlsx') document.body.appendChild(a) a.click() document.body.removeChild(a); window.URL.revokeObjectURL(url); });……

阅读全文

Spring Boot File Download

spring boot application 提供下载的代码,可以返回一个Resource @RestController @RequiredArgsConstructor @RequestMapping("/api") public class ReportController { @GetMapping(value = "/filedownload") public ResponseEntity<InputStreamResource> downloadFile(HttpServletRequest request) { // ....................... // ....................... // ....................... ByteArrayInputStream stream = xxxxxx;// get the stream return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM) .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=file.xlsx") .body(new InputStreamResource(stream)); } }……

阅读全文

Azure AD SAML SSO with Node Application

Azure AD saml sso 代码 主要是参考文档 安装 passport-saml npm install passport-saml use passport passport.use(new SamlStrategy( { path: '/account/auth/blueid/callback', // 这个是callback需要稍后实现 entryPoint: '', // 这个是azure AD的一个配置, saml-based sso login url issuer: 'cobeedev', // basic saml configuration -> Identifier (Entity ID) cert: '', // refer later signatureAlgorithm: 'sha256' }, async function(profile, done) { // in this function, you can process profile to get necessary information console.log(profile); // lazy require const usersManagement = require('../../controllers/users/usersManagement'); const ssoUser = jsonUtil.profile2User(profile); let dbUser = await usersManagement.getUserByAzureMail(ssoUser.email); // if user was not found in db // process the scenario if (!dbUser) { await usersManagement.processAzureSSOUser(ssoUser); dbUser = await usersManagement.getUserByAzureMail(ssoUser.email); }……

阅读全文

Port Forwarding - Mac

Mac下端口转发 有时候要在本地起https,需要把443端口转发到8080或者其他的3000端口 ###设置转发 echo "rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 9443" | sudo pfctl -ef - 取消转发 sudo pfctl -s nat sudo pfctl -F all -f /etc/pf.conf……

阅读全文