-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
547 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
docs/spring/cs580395d2-7ea0-11ee-88e5-acde48001122.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package dolores.oauthserver.handler; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.authentication.BadCredentialsException; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.crypto.codec.Base64; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.security.oauth2.common.OAuth2AccessToken; | ||
import org.springframework.security.oauth2.common.exceptions.UnapprovedClientAuthenticationException; | ||
import org.springframework.security.oauth2.provider.*; | ||
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; | ||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
|
||
@Slf4j | ||
@Component("appLoginInSuccessHandler") | ||
public class AppLoginInSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
private PasswordEncoder passwordEncoder; | ||
|
||
@Autowired | ||
private ClientDetailsService clientDetailsService; | ||
|
||
@Autowired | ||
private AuthorizationServerTokenServices authorizationServerTokenServices; | ||
|
||
@Override | ||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { | ||
|
||
log.info("【AppLoginInSuccessHandler】 onAuthenticationSuccess authentication={}", authentication); | ||
|
||
String header = request.getHeader("Authorization"); | ||
|
||
// if (header == null || !header.startsWith("Basic ")) { | ||
// throw new UnapprovedClientAuthenticationException("请求头中无client信息"); | ||
// } | ||
String[] tokens = this.extractAndDecodeHeader(header, request); | ||
|
||
assert tokens.length == 2; | ||
|
||
String clientId = tokens[0]; | ||
String clientSecret = tokens[1]; | ||
|
||
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId); | ||
|
||
if (clientDetails == null) { | ||
throw new UnapprovedClientAuthenticationException("clientId 对应的配置信息不存在" + clientId); | ||
} else if (!passwordEncoder.matches(clientSecret, clientDetails.getClientSecret())) { | ||
throw new UnapprovedClientAuthenticationException("clientSecret 不匹配" + clientId); | ||
} | ||
|
||
TokenRequest tokenRequest = new TokenRequest(new HashMap<>(), clientId, clientDetails.getScope(), "custom"); | ||
|
||
OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails); | ||
|
||
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, authentication); | ||
|
||
OAuth2AccessToken token = authorizationServerTokenServices.createAccessToken(oAuth2Authentication); | ||
|
||
response.setContentType("application/json;charset=UTF-8"); | ||
response.getWriter().write(objectMapper.writeValueAsString(token)); | ||
log.info("token={}", token); | ||
|
||
} | ||
|
||
/** | ||
* 解码 | ||
* | ||
* @param header | ||
* @param request | ||
* @return | ||
* @throws IOException | ||
*/ | ||
private String[] extractAndDecodeHeader(String header, HttpServletRequest request) throws IOException { | ||
byte[] base64Token = header.substring(6).getBytes("UTF-8"); | ||
|
||
byte[] decoded; | ||
try { | ||
decoded = Base64.decode(base64Token); | ||
} catch (IllegalArgumentException var7) { | ||
throw new BadCredentialsException("Failed to decode basic authentication token"); | ||
} | ||
|
||
String token = new String(decoded, "UTF-8"); | ||
int delim = token.indexOf(":"); | ||
if (delim == -1) { | ||
throw new BadCredentialsException("Invalid basic authentication token"); | ||
} else { | ||
return new String[]{token.substring(0, delim), token.substring(delim + 1)}; | ||
} | ||
} | ||
} |
184 changes: 184 additions & 0 deletions
184
docs/spring/cs5847dea4-7ea0-11ee-88e5-acde48001122.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.binding; | ||
|
||
import org.apache.ibatis.annotations.*; | ||
import org.apache.ibatis.domain.blog.Author; | ||
import org.apache.ibatis.domain.blog.Post; | ||
import org.apache.ibatis.domain.blog.Section; | ||
import org.apache.ibatis.executor.BatchResult; | ||
import org.apache.ibatis.session.RowBounds; | ||
|
||
import java.util.List; | ||
|
||
@CacheNamespace(readWrite = false) | ||
public interface BoundAuthorMapper { | ||
|
||
//====================================================== | ||
|
||
List<Post> findPostsInArray(Integer[] ids); | ||
|
||
//====================================================== | ||
|
||
List<Post> findPostsInList(List<Integer> ids); | ||
|
||
//====================================================== | ||
|
||
int insertAuthor(Author author); | ||
|
||
int insertAuthorInvalidSelectKey(Author author); | ||
|
||
int insertAuthorInvalidInsert(Author author); | ||
|
||
int insertAuthorDynamic(Author author); | ||
|
||
//====================================================== | ||
|
||
@ConstructorArgs({ | ||
@Arg(column = "AUTHOR_ID", javaType = int.class) | ||
}) | ||
@Results({ | ||
@Result(property = "username", column = "AUTHOR_USERNAME"), | ||
@Result(property = "password", column = "AUTHOR_PASSWORD"), | ||
@Result(property = "email", column = "AUTHOR_EMAIL"), | ||
@Result(property = "bio", column = "AUTHOR_BIO") | ||
}) | ||
@Select({ | ||
"SELECT ", | ||
" ID as AUTHOR_ID,", | ||
" USERNAME as AUTHOR_USERNAME,", | ||
" PASSWORD as AUTHOR_PASSWORD,", | ||
" EMAIL as AUTHOR_EMAIL,", | ||
" BIO as AUTHOR_BIO", | ||
"FROM AUTHOR WHERE ID = #{id}"}) | ||
Author selectAuthor(int id); | ||
|
||
//====================================================== | ||
|
||
@Result(property = "id", column = "AUTHOR_ID", id = true) | ||
@Result(property = "username", column = "AUTHOR_USERNAME") | ||
@Result(property = "password", column = "AUTHOR_PASSWORD") | ||
@Result(property = "email", column = "AUTHOR_EMAIL") | ||
@Result(property = "bio", column = "AUTHOR_BIO") | ||
@Select({ | ||
"SELECT ", | ||
" ID as AUTHOR_ID,", | ||
" USERNAME as AUTHOR_USERNAME,", | ||
" PASSWORD as AUTHOR_PASSWORD,", | ||
" EMAIL as AUTHOR_EMAIL,", | ||
" BIO as AUTHOR_BIO", | ||
"FROM AUTHOR WHERE ID = #{id}"}) | ||
Author selectAuthorMapToPropertiesUsingRepeatable(int id); | ||
|
||
//====================================================== | ||
|
||
@ConstructorArgs({ | ||
@Arg(column = "AUTHOR_ID", javaType = Integer.class), | ||
@Arg(column = "AUTHOR_USERNAME", javaType = String.class), | ||
@Arg(column = "AUTHOR_PASSWORD", javaType = String.class), | ||
@Arg(column = "AUTHOR_EMAIL", javaType = String.class), | ||
@Arg(column = "AUTHOR_BIO", javaType = String.class), | ||
@Arg(column = "AUTHOR_SECTION", javaType = Section.class) | ||
}) | ||
@Select({ | ||
"SELECT ", | ||
" ID as AUTHOR_ID,", | ||
" USERNAME as AUTHOR_USERNAME,", | ||
" PASSWORD as AUTHOR_PASSWORD,", | ||
" EMAIL as AUTHOR_EMAIL,", | ||
" BIO as AUTHOR_BIO," + | ||
" FAVOURITE_SECTION as AUTHOR_SECTION", | ||
"FROM AUTHOR WHERE ID = #{id}"}) | ||
Author selectAuthorConstructor(int id); | ||
|
||
//====================================================== | ||
|
||
@Arg(column = "AUTHOR_ID", javaType = Integer.class, id = true) | ||
@Arg(column = "AUTHOR_USERNAME", javaType = String.class) | ||
@Arg(column = "AUTHOR_PASSWORD", javaType = String.class) | ||
@Arg(column = "AUTHOR_EMAIL", javaType = String.class) | ||
@Arg(column = "AUTHOR_BIO", javaType = String.class) | ||
@Arg(column = "AUTHOR_SECTION", javaType = Section.class) | ||
@Select({ | ||
"SELECT ", | ||
" ID as AUTHOR_ID,", | ||
" USERNAME as AUTHOR_USERNAME,", | ||
" PASSWORD as AUTHOR_PASSWORD,", | ||
" EMAIL as AUTHOR_EMAIL,", | ||
" BIO as AUTHOR_BIO," + | ||
" FAVOURITE_SECTION as AUTHOR_SECTION", | ||
"FROM AUTHOR WHERE ID = #{id}"}) | ||
Author selectAuthorMapToConstructorUsingRepeatable(int id); | ||
|
||
//====================================================== | ||
|
||
@Arg(column = "AUTHOR_ID", javaType = int.class) | ||
@Result(property = "username", column = "AUTHOR_USERNAME") | ||
@Select({ | ||
"SELECT ", | ||
" ID as AUTHOR_ID,", | ||
" USERNAME as AUTHOR_USERNAME,", | ||
" PASSWORD as AUTHOR_PASSWORD,", | ||
" EMAIL as AUTHOR_EMAIL,", | ||
" BIO as AUTHOR_BIO", | ||
"FROM AUTHOR WHERE ID = #{id}"}) | ||
Author selectAuthorUsingSingleRepeatable(int id); | ||
|
||
//====================================================== | ||
|
||
@ConstructorArgs({ | ||
@Arg(column = "AUTHOR_ID", javaType = Integer.class), | ||
@Arg(column = "AUTHOR_USERNAME", javaType = String.class), | ||
@Arg(column = "AUTHOR_PASSWORD", javaType = String.class), | ||
@Arg(column = "AUTHOR_EMAIL", javaType = String.class), | ||
@Arg(column = "AUTHOR_BIO", javaType = String.class) | ||
}) | ||
@Arg(column = "AUTHOR_SECTION", javaType = Section.class) | ||
@Select({ | ||
"SELECT ", | ||
" ID as AUTHOR_ID,", | ||
" USERNAME as AUTHOR_USERNAME,", | ||
" PASSWORD as AUTHOR_PASSWORD,", | ||
" EMAIL as AUTHOR_EMAIL,", | ||
" BIO as AUTHOR_BIO," + | ||
" FAVOURITE_SECTION as AUTHOR_SECTION", | ||
"FROM AUTHOR WHERE ID = #{id}"}) | ||
Author selectAuthorUsingBothArgAndConstructorArgs(int id); | ||
|
||
//====================================================== | ||
|
||
@Results( | ||
@Result(property = "id", column = "AUTHOR_ID") | ||
) | ||
@Result(property = "username", column = "AUTHOR_USERNAME") | ||
@Select({ | ||
"SELECT ", | ||
" ID as AUTHOR_ID,", | ||
" USERNAME as AUTHOR_USERNAME", | ||
"FROM AUTHOR WHERE ID = #{id}"}) | ||
Author selectAuthorUsingBothResultAndResults(int id); | ||
|
||
//====================================================== | ||
|
||
List<Post> findThreeSpecificPosts(@Param("one") int one, | ||
RowBounds rowBounds, | ||
@Param("two") int two, | ||
int three); | ||
|
||
@Flush | ||
List<BatchResult> flush(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.huifer.concurrence.ch2.communication; | ||
|
||
/** | ||
* <p>Title : EZdemo </p> | ||
* <p>Description : 最简单的通讯</p> | ||
* | ||
* @author huifer | ||
* @date 2019-03-27 | ||
*/ | ||
public class EZdemo { | ||
|
||
private static String message; | ||
|
||
public static void main(String[] args) { | ||
Thread thread1 = new Thread(() -> { | ||
while (message == null) { | ||
// 因为线程去启动顺序是不固定的所以需要等待复制成功 | ||
System.out.println("还没有值"); | ||
} | ||
System.out.println("获取通讯变量" + message); | ||
}); | ||
Thread thread2 = new Thread(() -> { | ||
message = " 初始化变量"; | ||
|
||
}); | ||
thread1.start(); | ||
thread2.start(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2009-2015 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.submitted.lazyload_proxyfactory_comparison; | ||
|
||
import org.apache.ibatis.annotations.Param; | ||
|
||
public interface Mapper { | ||
UserWithGetObjectWithInterface getUserWithGetObjectWithInterface(@Param("id") Integer id); | ||
|
||
UserWithGetObjectWithoutInterface getUserWithGetObjectWithoutInterface(@Param("id") Integer id); | ||
|
||
UserWithGetXxxWithInterface getUserWithGetXxxWithInterface(@Param("id") Integer id); | ||
|
||
UserWithGetXxxWithoutInterface getUserWithGetXxxWithoutInterface(@Param("id") Integer id); | ||
|
||
UserWithNothingWithInterface getUserWithNothingWithInterface(@Param("id") Integer id); | ||
|
||
UserWithNothingWithoutInterface getUserWithNothingWithoutInterface(@Param("id") Integer id); | ||
} |
Oops, something went wrong.