privatestaticbyte[] getSalt() throws NoSuchAlgorithmException{ //Always use a SecureRandom generator SecureRandomsr= SecureRandom.getInstance("SHA1PRNG"); //Create array for salt byte[] salt = newbyte[16]; //Get a random salt sr.nextBytes(salt); //return salt return salt; }
// If not use @Param, you should be define same arguments with mapper method publicstatic String buildGetUsersByName( final String name, final String orderByColumn) { returnnewSQL(){{ SELECT("*"); FROM("users"); WHERE("name like #{name} || '%'"); ORDER_BY(orderByColumn); }}.toString(); }
// If use @Param, you can define only arguments to be used publicstatic String buildGetUsersByName(@Param("orderByColumn")final String orderByColumn) { returnnewSQL(){{ SELECT("*"); FROM("users"); WHERE("name like #{name} || '%'"); ORDER_BY(orderByColumn); }}.toString(); } }
// With conditionals (note the final parameters, required for the anonymous inner class to access them) public String selectPersonLike(final String id, final String firstName, final String lastName) { returnnewSQL() {{ SELECT("P.ID, P.USERNAME, P.PASSWORD, P.FIRST_NAME, P.LAST_NAME"); FROM("PERSON P"); if (id != null) { WHERE("P.ID like #{id}"); } if (firstName != null) { WHERE("P.FIRST_NAME like #{firstName}"); } if (lastName != null) { WHERE("P.LAST_NAME like #{lastName}"); } ORDER_BY("P.LAST_NAME"); }}.toString(); }
<selectid="findActiveBlogWithTitleLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <iftest="title != null"> AND title like #{title} </if> </select>
1 2 3 4 5 6 7 8 9 10
<selectid="findActiveBlogLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <iftest="title != null"> AND title like #{title} </if> <iftest="author != null and author.name != null"> AND author_name like #{author.name} </if> </select>
choose, when, otherwise
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<selectid="findActiveBlogLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <choose> <whentest="title != null"> AND title like #{title} </when> <whentest="author != null and author.name != null"> AND author_name like #{author.name} </when> <otherwise> AND featured = 1 </otherwise> </choose> </select>
trim, where, set
select
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<selectid="findActiveBlogLike" resultType="Blog"> SELECT * FROM BLOG <where> <iftest="state != null"> state = #{state} </if> <iftest="title != null"> AND title like #{title} </if> <iftest="author != null and author.name != null"> AND author_name like #{author.name} </if> </where> </select>
<selectid="selectPostIn"resultType="domain.blog.Post"> SELECT * FROM POST P WHERE ID in <foreachitem="item"index="index"collection="list" open="("separator=","close=")"> #{item} </foreach> </select>
bind
1 2 3 4 5
<selectid="selectBlogsLike"resultType="Blog"> <bindname="pattern"value="'%' + _parameter.getTitle() + '%'" /> SELECT * FROM BLOG WHERE title LIKE #{pattern} </select>
多数据库支持
1 2 3 4 5 6 7 8 9 10 11
<insertid="insert"> <selectKeykeyProperty="id"resultType="int"order="BEFORE"> <iftest="_databaseId == 'oracle'"> select seq_users.nextval from dual </if> <iftest="_databaseId == 'db2'"> select nextval for seq_users from sysibm.sysdummy1" </if> </selectKey> insert into users values (#{id}, #{name}) </insert>
server { listen80; server_name vermouthx.com; # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response. location / { return301 https://$host$request_uri; } } server { listen443 ssl; server_name vermouthx.com;
# certs sent to the client in SERVER HELLO are concatenated in ssl_certificate ssl_certificate /etc/nginx/ssl/vermouthx.com/cert.pem; ssl_certificate_key /etc/nginx/ssl/vermouthx.com/key.pem; ssl_session_timeout1d; ssl_session_cache shared:SSL:50m; ssl_session_ticketsoff; # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits ssl_dhparam /etc/nginx/ssl/dhparam.pem; # intermediate configuration. tweak to your needs. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; ssl_prefer_server_cipherson; # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months) add_header Strict-Transport-Security max-age=15768000; # OCSP Stapling --- # fetch OCSP records from URL in ssl_certificate and cache them ssl_staplingon; ssl_stapling_verifyon; # verify chain of trust of OCSP response using Root CA and Intermediate certs ssl_trusted_certificate /etc/nginx/ssl/vermouthx.com/ca.pem; resolver8.8.8.8; }
Shadowsocks-libev: Shadowsocks-libev is a lightweight secured SOCKS5 proxy for embedded devices and low-end boxes.
Simple-obfs: Simple-obfs is a simple obfusacting tool, designed as plugin server of shadowsocks.
Docker: Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.
When you shutdown or reboot your system, systemd tries to stop all services as fast as it can. That involves bringing down the network and terminating all processes that are still alive – usually in that order. So when systemd kills the forked SSH processes that are handling your SSH sessions, the network connection is already disabled and they have no way of closing the client connection gracefully.
Your first thought might be to just kill all SSH processes as the first step during shutdown, and there are quite a few systemd service files out there that do just that.
But there is of course a neater solution (how it’s “supposed” to be done): systemd-logind. systemd-logind keeps track of active user sessions (local and SSH ones) and assigns all processes spawned within them to so-called “slices”. That way, when the system is shut down, systemd can just SIGTERM everything inside the user slices (which includes the forked SSH process that’s handing a particular session) and then continue shutting down services and the network.
systemd-logind requires a PAM module to get notified of new user sessions and you’ll need dbus to use loginctl to check its status, so install both of those: