Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/config/BladeResourceServerConfiguration.java
@@ -38,7 +38,6 @@ .antMatchers( "/actuator/**", "/oauth/captcha", "/oauth/passwordFreeLogin", "/oauth/logout", "/oauth/clear-cache", "/oauth/render/**", Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/endpoint/BladeTokenEndPoint.java
@@ -32,7 +32,9 @@ import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.WebUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.InsufficientAuthenticationException; import org.springframework.security.core.Authentication; @@ -59,6 +61,7 @@ import java.security.Principal; import java.util.Collections; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpSession; Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/endpoint/PwdFreeLoginEndpoint.java
ÎļþÒÑɾ³ý Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/granter/BladeTokenGranter.java
@@ -45,6 +45,8 @@ granters.add(new CaptchaTokenGranter(authenticationManager, endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory(), bladeRedis)); // å¢å ç¬¬ä¸æ¹ç»éæ¨¡å¼ granters.add(new SocialTokenGranter(endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory(), userClient, socialProperties)); // å¢å å å¯ç»éæ¨¡å¼ //granters.add(new PwdFreeLoginTokenGranter(endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory(), userClient, socialProperties)); // ç»åtokenGranteréå return new CompositeTokenGranter(granters); } Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/granter/PwdFreeLoginTokenGranter.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,116 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill åºéª (smallchill@163.com) */ package com.vci.ubcs.auth.granter; import com.vci.ubcs.auth.constant.AuthConstant; import com.vci.ubcs.auth.service.BladeUserDetails; import com.vci.ubcs.auth.utils.TokenUtil; import com.vci.ubcs.system.user.entity.User; import com.vci.ubcs.system.user.entity.UserInfo; import com.vci.ubcs.system.user.entity.UserOauth; import com.vci.ubcs.system.user.feign.IUserClient; import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.AuthRequest; import org.springblade.core.social.props.SocialProperties; import org.springblade.core.social.utils.SocialUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.WebUtil; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.oauth2.common.exceptions.InvalidGrantException; import org.springframework.security.oauth2.provider.*; import org.springframework.security.oauth2.provider.token.AbstractTokenGranter; import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; /** * ç¬¬ä¸æ¹ç»å½è®¤è¯ç±» * * @author Chill */ public class PwdFreeLoginTokenGranter extends AbstractTokenGranter { private static final String GRANT_TYPE = "passwordfree"; private static final Integer AUTH_SUCCESS_CODE = 2000; private final AuthenticationManager authenticationManager; public PwdFreeLoginTokenGranter(AuthenticationManager authenticationManager, AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory) { super(tokenServices, clientDetailsService, requestFactory, GRANT_TYPE); this.authenticationManager = authenticationManager; } @Override protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) { // 请æ±å¤´ç§æ·ä¿¡æ¯ HttpServletRequest request = WebUtil.getRequest(); String tenantId = Func.toStr(request.getHeader(TokenUtil.TENANT_HEADER_KEY), TokenUtil.DEFAULT_TENANT_ID); // è·å请æ±åæ° Map<String, String> parameters = new LinkedHashMap<>(tokenRequest.getRequestParameters()); // æ ¹æ®åæ°è¿è¡èªå®ä¹çææé»è¾ // 示ä¾ä¸ä½¿ç¨äºç¡¬ç¼ç çæ¹å¼éªè¯è´¦å·åçæææä¿¡æ¯ String userName = parameters.get("username"); String password = parameters.get("password"); // ç»è£ æ°æ® //UserOauth userOauth = Objects.requireNonNull(BeanUtil.copy(authUser, UserOauth.class)); //userOauth.setTenantId(tenantId); //userOauth.setUuid(authUser.getUuid()); // è¿ç¨è°ç¨ï¼è·å认è¯ä¿¡æ¯ //R<UserInfo> result = userClient.userAuthInfo(userOauth); BladeUserDetails bladeUserDetails = null; // é ç½®çå¯ç ï¼ææèµ°å 坿¥å£çé½è®¾ç½®ç»ä¸çå¯ç if ("password".equals(password)) { // æå»ºææä¿¡æ¯ //User user = result.getData().getUser(); //Kv detail = result.getData().getDetail(); // if (user == null || user.getId() == null) { // throw new InvalidGrantException("social grant failure, user is null"); // } // bladeUserDetails = new BladeUserDetails(user.getId(), // tenantId, result.getData().getOauthId(), userName, "webserviceå å¯ç»å½", "0", "0", "0", "0", Func.toStr(userOauth.getAvatar(), TokenUtil.DEFAULT_AVATAR), // userName, AuthConstant.ENCRYPT + password, detail, true, true, true, true, // AuthorityUtils.commaSeparatedStringToAuthorityList(Func.join(result.getData().getRoles()))); } else { throw new InvalidGrantException("passwordfree grant failure, auth response is not success"); } // ç»è£ è®¤è¯æ°æ®ï¼å ³éå¯ç æ ¡éª Authentication userAuth = new UsernamePasswordAuthenticationToken(bladeUserDetails, null, bladeUserDetails.getAuthorities()); ((AbstractAuthenticationToken) userAuth).setDetails(parameters); OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest); // è¿å OAuth2Authentication return new OAuth2Authentication(storedOAuth2Request, userAuth); } } Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/granter/SocialTokenGranter.java
@@ -42,6 +42,7 @@ import org.springframework.security.oauth2.provider.*; import org.springframework.security.oauth2.provider.token.AbstractTokenGranter; import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import java.util.LinkedHashMap; Source/UBCS/ubcs-gateway/src/main/java/com/vci/ubcs/gateway/provider/AuthProvider.java
@@ -34,6 +34,7 @@ static { DEFAULT_SKIP_URL.add("/example"); DEFAULT_SKIP_URL.add("/oauth/token/**"); DEFAULT_SKIP_URL.add("/oauth/password-free-login/**"); DEFAULT_SKIP_URL.add("/oauth/captcha/**"); DEFAULT_SKIP_URL.add("/oauth/clear-cache/**"); DEFAULT_SKIP_URL.add("/oauth/user-info"); Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/PasswordFreeLoginController.java
@@ -3,9 +3,7 @@ import com.vci.ubcs.code.service.IPasswordFreeLoginService; import io.swagger.annotations.Api; import org.springblade.core.tool.api.R; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -21,9 +19,9 @@ @Resource private IPasswordFreeLoginService passwordFreeLoginService; @GetMapping("/login") public R passwordFreeLogin(String account) { boolean resBoolean = passwordFreeLoginService.passwordFreeLogin(account); @PostMapping("/login") public R passwordFreeLogin(@RequestParam String username) { boolean resBoolean = passwordFreeLoginService.passwordFreeLogin(username); return R.status(resBoolean); } Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/IPasswordFreeLoginService.java
@@ -9,10 +9,10 @@ /** * å å¯ç»å½æ¹æ³ * @param account è´¦å· * @param username è´¦å· * @return */ boolean passwordFreeLogin(String account); boolean passwordFreeLogin(String username); } Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
@@ -3724,6 +3724,7 @@ if (listR.getData().isEmpty()) { throw new VciBaseException("ä¼ å ¥ä¸å¡ç±»åæªæ¥è¯¢å°ç¸åºè¡¨åï¼è¯·æ£æ¥ï¼"); } // TODO:åç §é ç½®çæ¨¡ç³æ¥è¯¢è¿æ»¤æ¡ä»¶ææªå¤ç String namesql = ""; if (StringUtils.isNotBlank(baseQueryObject.getConditionMap().get("name"))) { String s = baseQueryObject.getConditionMap().get("name"); Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/PasswordFreeLoginServiceImpl.java
@@ -47,24 +47,29 @@ /** * å å¯ç»å½ * @param account è´¦å· * @param username è´¦å· * @return */ @Override public boolean passwordFreeLogin(String account) { public boolean passwordFreeLogin(String username) { // å å¯ç»å½æ¥å£å°å String loginUrl = "http://localhost:"+this.getGatewayPort()+"/ubcs-auth/oauth/passwordFreeLogin?username=admin&grant_type=captcha&scope=all&type=account"; String loginUrl = "http://localhost:"+this.getGatewayPort()+"/ubcs-auth/oauth/password-free-login"; // 设置请æ±å¤´ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.set("Authorization", "Basic c3dvcmQ6c3dvcmRfc2VjcmV0"); headers.set("Tenant-Id", "000000"); //设置请æ±ä½åæ° MultiValueMap<String,String> bodyParams = new LinkedMultiValueMap<String,String>(); bodyParams.add("account",account); MultiValueMap<String,String> parameters = new LinkedMultiValueMap<String,String>(); parameters.add("username",username); parameters.add("grant_type", "captcha"); parameters.add("scope", "all"); parameters.add("type", "account"); // åéPOSTè¯·æ± String responseBody = HttpUtils.post(loginUrl, bodyParams); String responseBody = HttpUtils.post(loginUrl, parameters,headers); System.out.println(responseBody); //æ¿å°ååºä½å°tokenåå ¥å°redisä¸ï¼ä»¥accountä½ä¸ºåå¨çkey