maven compiler

default compiler

<forceJavacCompilerUse>
compiler can now use javax.tools if available in your current jdk, you can disable this feature using -Dmaven.compiler.forceJavacCompilerUse=true or in the plugin configuration
默认会用当前jdk下面的javax.tools.JavaCompiler来编译,所谓当前的jdk就是运行maven的jdk
比如

1
2
3
4
C:\Users\lenovo>mvn -v
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)
Maven home: D:\software\apache-maven-3.6.0\bin\..
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: C:\java\jdk1.8.0_191\jre

https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#forceJavacCompilerUse

设置编译级别和运行jvm

1
2
3
4
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

Compiling Sources Using A Different JDK

1
2
3
4
5
6
7
8
9
10
11
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable><!-- path-to-javac --></executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>

总结

其实默认的javax.tools里面的编译器也够了

scala compiler

scala的编译器是通过scala.version来指定的,具体可以看.m2\repository\org\scala-lang\scala-compiler\2.11.7

1
2
3
4
5
6
<properties>
<!--specify scala compiler, 2.12 will fail-->
<!--.m2\repository\org\scala-lang\scala-compiler\2.11.7-->
<!--you can find that the jars are named with 2.11 scala, D:\software\spark-2.4.1-bin-hadoop2.7\jars\spark-core_2.11-2.4.1.jar-->
<scala.version>2.11.7</scala.version>
</properties>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.0.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xms64m</jvmArg>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
</configuration>
</plugin>

upgrade python3

https://www.rosehosting.com/blog/how-to-install-python-3-6-4-on-centos-7/

yum install -y https://repo.ius.io/ius-release-el7.rpm
yum update
yum install -y python36u python36u-libs python36u-devel python36u-pip
python3 –versoin

rm /usr/bin/python (delete this soft link)
ln -s /usr/bin/python3 /usr/bin/python
python –version

升级了python后最好用pip3,这样才可以安装package到/usr/lib/python3.6/site-packages

下面是升级后遇到的一些问题的解决办法
https://www.cnblogs.com/linkxu1989/p/6955137.html
升级了后下面两个文件的头部要修改成/usr/bin/python2.7
/usr/lib/python2.7/site-packages/urlgrabber/grabber.py
/usr/libexec/urlgrabber-ext-down
/usr/bin/yum

maven

阿里云配置

https://developer.aliyun.com/mvn/guide

put below in pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<repositories>
<repository>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<layout>default</layout>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>

</repositories>

<pluginRepositories>
<pluginRepository>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<layout>default</layout>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>

如果setting统一配置如下

1
2
3
4
5
6
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>

put below in build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
buildscript {
repositories {
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
maven {
url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
}
}
}

allprojects {
repositories {
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
maven {
url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
}
}
}

maven搜索顺序

https://cloud.tencent.com/developer/article/1532388

oauth2

  • Authentication is the process of verifying an identity (who they say they are)
  • Authorization is the process of verifying what someone is allowed to do (permissions)

这篇文章讲了outh2,比较权威
https://oauth.net/articles/authentication/

这篇讲了oauth应用于微服务
https://developer.okta.com/blog/2018/02/13/secure-spring-microservices-with-oauth

这个文章讲oauth不是用于authentication而是authorization
https://stackoverflow.com/questions/33702826/oauth-authorization-vs-authentication
OAuth authentication?
Authentication deals information about “who one is”. Authorization deals information about “who grants what permissions to whom”. Authorization flow contains authentication as its first step. It is the reason people are often confused.
There are many libraries and services that use OAuth 2.0 for authentication. It is often called “social login” and It makes people more confused. If you see “OAuth authentication” (not “OAuth authorization”), it is a solution using OAuth for authentication.

oauth2的specs也可以看看,已经明确说明oauth2不是用于认证的
OAuth 2.0 is a specification for authorization, but NOT for authentication. RFC 6749, 3.1. Authorization Endpoint explicitly says as follows:
The authorization endpoint is used to interact with the resource owner and obtain an authorization grant. The authorization server MUST first verify the identity of the resource owner. The way in which the authorization server authenticates the resource owner (e.g., username and password login, session cookies) is beyond the scope of this specification.
oauth2和oauth1的区别如下
https://stackoverflow.com/questions/4113934/how-is-oauth-2-different-from-oauth-1

OpenID Connect
OpenID 1.0 and OpenID 2.0 are old specifications for authentication. Those who made the specifications expected people to use OpenID for authentication. However, some people began to use OAuth 2.0 for authentication (not for authorization) and OAuth authentication has prevailed rapidly.
From a viewpoint of OpenID guys, authentication based on OAuth was not secure enough, but they had to admit that people preferred OAuth authentication. As a result, OpenID guys decided to define a new specification, OpenID Connect, on top of OAuth 2.0.
Yes, this has made people much more confused.

Let’s start with the biggest reason why OAuth isn’t authentication: access tokens are not intended for the client application.
https://www.scottbrady91.com/OAuth/OAuth-is-Not-Authentication

code

代码https://github.com/mengxu2018/springboot/tree/master/github-oauth2
文档https://spring.io/guides/tutorials/spring-boot-oauth2/

代码https://github.com/mengxu2018/springboot/tree/master/oauth2_test
文档https://www.javainuse.com/spring/spring-boot-oauth-access-token
https://www.aha.io/api/oauth2

https://projects.spring.io/spring-security-oauth/docs/oauth2.html
https://security.stackexchange.com/questions/37818/why-use-openid-connect-instead-of-plain-oauth2

总结

oauth是一个授权框架, 只不过授权之前需要登陆,但是这个并不代表oauth是认证框架,
但是很多人就开始用oauth2来做认证
主要这个文章https://stackoverflow.com/questions/33702826/oauth-authorization-vs-authentication
(Identity, Authentication) + OAuth 2.0 = OpenID Connect
https://medium.com/@darutk/full-scratch-implementor-of-oauth-and-openid-connect-talks-about-findings-55015f36d1c3

redis5 centos7 setup

Install redis

1
2
3
4
5
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
tar xzf redis-5.0.3.tar.gz
cd redis-5.0.3
make distclean
make

start redis server

1
src/redis-server redis.conf

test the client

1
2
3
4
5
$ src/redis-cli
redis> set foo bar ('auth 123456' command to login if has password)
OK
redis> get foo
"bar"

enable remote access

update redis.conf like below:
protected-mode no
bind 127.0.0.1
requirepass 123456

spring boot redis

https://github.com/mengxu2018/springboot/tree/master/spring-boot-crud
缓存流程:
失效:应用程序先从cache取数据,没有得到,则从数据库中取数据,成功后,放到缓存中。
命中:应用程序从cache中取数据,取到后返回。
更新:先把数据存到数据库中,成功后,再让缓存失效。(删除数据也让缓存失效)

reference

https://coolshell.cn/articles/17416.html

sprintboot docker deployment

build code

1
2
3
git clone https://github.com/mengxu2018/springboot.git
cd springboot/spring-boot-crud
mvn package # will generate spring-boot-crud.jar under target directory

build docker image

1
2
docker build -t springboot-crud-sample .
docker inspect springboot-crud-sample # you will find userful info under node "ContainerConfig"

run docker image

1
2
docker run -d -p 9080:8080 springboot-crud-sample
docker inspect 573fcd31c442 # 573fcd31c442 is the container id, can find "Mounts" here

test the client

visit http://192.168.77.140:9080/