| | |
| | | .antMatchers( |
| | | "/actuator/**", |
| | | "/oauth/captcha", |
| | | "/oauth/passwordFreeLogin", |
| | | "/oauth/logout", |
| | | "/oauth/clear-cache", |
| | | "/oauth/render/**", |
| | |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.core.tool.utils.WebUtil; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.security.authentication.InsufficientAuthenticationException; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.oauth2.common.OAuth2AccessToken; |
| | | import org.springframework.security.oauth2.common.OAuth2RefreshToken; |
| | | import org.springframework.security.oauth2.common.exceptions.InvalidClientException; |
| | | import org.springframework.security.oauth2.common.exceptions.InvalidGrantException; |
| | | import org.springframework.security.oauth2.common.exceptions.InvalidRequestException; |
| | | import org.springframework.security.oauth2.common.exceptions.UnsupportedGrantTypeException; |
| | | import org.springframework.security.oauth2.common.util.OAuth2Utils; |
| | | import org.springframework.security.oauth2.provider.AuthorizationRequest; |
| | | import org.springframework.security.oauth2.provider.ClientDetails; |
| | | import org.springframework.security.oauth2.provider.ClientDetailsService; |
| | | import org.springframework.security.oauth2.provider.TokenRequest; |
| | | import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint; |
| | | import org.springframework.security.oauth2.provider.token.TokenStore; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.HttpRequestMethodNotSupportedException; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | import java.security.Principal; |
| | | import java.util.Collections; |
| | | import java.util.Map; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import java.time.Duration; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | /* |
| | | package com.vci.ubcs.auth.endpoint; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.oauth2.common.OAuth2AccessToken; |
| | | import org.springframework.security.oauth2.provider.ClientDetailsService; |
| | | import org.springframework.security.oauth2.provider.OAuth2RequestFactory; |
| | | import org.springframework.security.oauth2.provider.TokenGranter; |
| | | import org.springframework.security.oauth2.provider.TokenRequest; |
| | | import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint; |
| | | import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.HttpRequestMethodNotSupportedException; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | import java.util.Map; |
| | | |
| | | */ |
| | | /** |
| | | * å
å¯ç»å½ |
| | | * @author ludc |
| | | * @date 2023/9/12 18:03 |
| | | *//* |
| | | |
| | | @Component |
| | | public class PwdFreeLoginEndpoint extends TokenEndpoint { |
| | | |
| | | |
| | | @Autowired |
| | | private AuthorizationServerTokenServices tokenServices; |
| | | |
| | | @Autowired |
| | | private ClientDetailsService clientDetailsService; |
| | | |
| | | @Autowired |
| | | private OAuth2RequestFactory requestFactory; |
| | | |
| | | @Autowired |
| | | private TokenGranter tokenGranter; |
| | | |
| | | @RequestMapping(value = "/oauth/password-free-login",method = RequestMethod.GET) |
| | | public ResponseEntity<OAuth2AccessToken> getPasswordFreeLogin(@RequestParam Map<String, String> parameters) throws HttpRequestMethodNotSupportedException { |
| | | return postPasswordFreeLogin(parameters); |
| | | } |
| | | |
| | | @RequestMapping(value = "/oauth/password-free-login",method = RequestMethod.POST) |
| | | public ResponseEntity<OAuth2AccessToken> postPasswordFreeLogin(@RequestParam Map<String, String> parameters) throws HttpRequestMethodNotSupportedException { |
| | | // 夿æ¯å¦æ»¡è¶³å
å¯ç»å½çæ¡ä»¶ |
| | | if (isSkipLogin(parameters)) { |
| | | // çæè®¿é®ä»¤ç |
| | | OAuth2AccessToken accessToken = createAccessToken(parameters); |
| | | // è¿å访é®ä»¤ç |
| | | return ResponseEntity.ok(accessToken); |
| | | } |
| | | |
| | | // 䏿»¡è¶³å
å¯ç»å½æ¡ä»¶ï¼è¿åéè¯¯ä¿¡æ¯ |
| | | return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); |
| | | } |
| | | |
| | | private boolean isSkipLogin(Map<String, String> parameters) { |
| | | // æ ¹æ®å
·ä½éæ±å¤ææ¯å¦æ»¡è¶³å
å¯ç»å½çæ¡ä»¶ |
| | | // ä¾å¦ï¼å¤æè¯·æ±åæ°ä¸æ¯å¦å
å«æä¸ªç¹å®çæ è¯ç¬¦ |
| | | return parameters.containsKey("skipLogin"); |
| | | } |
| | | |
| | | private OAuth2AccessToken createAccessToken(Map<String, String> parameters) throws HttpRequestMethodNotSupportedException { |
| | | // æé 请æ±åæ° |
| | | MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); |
| | | for (Map.Entry<String, String> entry : parameters.entrySet()) { |
| | | params.add(entry.getKey(), entry.getValue()); |
| | | } |
| | | |
| | | // è°ç¨TokenEndpointçpostAccessTokenæ¹æ³çæè®¿é®ä»¤ç |
| | | return postAccessToken(PrincipalUtils.getPrincipal(), params).getBody(); |
| | | } |
| | | |
| | | private ResponseEntity<OAuth2AccessToken> postAccessToken(Authentication authentication, MultiValueMap<String, String> parameters) throws HttpRequestMethodNotSupportedException { |
| | | // æé è¯·æ± |
| | | TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters, clientDetailsService.loadClientByClientId("your-client-id")); |
| | | |
| | | // çæè®¿é®ä»¤ç |
| | | OAuth2AccessToken accessToken = tokenGranter.grant("password", tokenRequest); |
| | | |
| | | // è¿å访é®ä»¤ç |
| | | return ResponseEntity.ok(accessToken); |
| | | } |
| | | |
| | | } |
| | | */ |
| | |
| | | /** |
| | | * åç±»ç æ®µä¸»é®æ¾ç¤ºææ¬ |
| | | */ |
| | | private String codeclassifysecoidName; |
| | | private String codeClassifySecOidName; |
| | | |
| | | /** |
| | | * ç å¼åºå· |
| | |
| | | /** |
| | | * è·ååç±»ç æ®µä¸»é®æ¾ç¤ºææ¬ |
| | | */ |
| | | public String getCodeclassifysecoidName (){ |
| | | return codeclassifysecoidName; |
| | | public String getCodeClassifySecOidName (){ |
| | | return codeClassifySecOidName; |
| | | } |
| | | |
| | | /** |
| | | * 设置åç±»ç æ®µä¸»é®æ¾ç¤ºææ¬ |
| | | */ |
| | | public void setCodeclassifysecoidName (String codeclassifysecoidName){ |
| | | this.codeclassifysecoidName = codeclassifysecoidName; |
| | | public void setCodeClassifySecOidName (String codeclassifysecoidName){ |
| | | this.codeClassifySecOidName = codeclassifysecoidName; |
| | | } |
| | | /** |
| | | * è·å ç å¼åºå· |
| | |
| | | this.name = name; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "CodeClassifyValueVO{" + |
| | | "codeClassifySecOid='" + codeClassifySecOid + '\'' + |
| | | ", codeclassifysecoidName='" + codeclassifysecoidName + '\'' + |
| | | ", codeClassifySecOidName='" + codeClassifySecOidName + '\'' + |
| | | ", orderNum=" + orderNum + |
| | | ", parentClassifyValueOid='" + parentClassifyValueOid + '\'' + |
| | | ", id='" + id + '\'' + |
| | | ", name='" + name + '\'' + |
| | | "} " + super.toString(); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "Tree{oid='" + this.oid + '\'' + ", text='" + this.text + '\'' + ", leaf=" + this.leaf + ", showCheckbox=" + this.showCheckbox + ", checked=" + this.checked + ", children=" + this.children + ", icon='" + this.icon + '\'' + ", iconCls='" + this.iconCls + '\'' + ", parentId='" + this.parentId + '\'' + ", parentName='" + this.parentName + '\'' + ", parentBtmName='" + this.parentBtmName + '\'' + ", expanded=" + this.expanded + ", href='" + this.href + '\'' + ", index='" + this.index + '\'' + ", attributes=" + this.attributes + '}'; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.code.config; |
| | | |
| | | import org.springframework.web.servlet.HandlerInterceptor; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * @author ludc |
| | | * @date 2023/9/12 11:49 |
| | | */ |
| | | public class AuthenticationInterceptor implements HandlerInterceptor { |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| | | return HandlerInterceptor.super.preHandle(request, response, handler); |
| | | } |
| | | |
| | | @Override |
| | | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { |
| | | HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); |
| | | } |
| | | |
| | | @Override |
| | | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { |
| | | HandlerInterceptor.super.afterCompletion(request, response, handler, ex); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.code.config; |
| | | |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| | | |
| | | /** |
| | | * webserviceæ¥å£æ¦æªå¨ |
| | | * @author ludc |
| | | * @date 2023/9/12 11:16 |
| | | */ |
| | | @Configuration |
| | | public class WebConfig implements WebMvcConfigurer { |
| | | |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | | registry.addInterceptor(new AuthenticationInterceptor()) |
| | | .addPathPatterns("/api/protected/**"); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.code.controller; |
| | | |
| | | 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 javax.annotation.Resource; |
| | | |
| | | /** |
| | | * @author ludc |
| | | * @date 2023/9/12 9:07 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/passwordFree") |
| | | @Api(value = "å
å¯ç»å½æ¥å£", tags = "å
å¯ç»å½æ¥å£") |
| | | public class PasswordFreeLoginController { |
| | | |
| | | @Resource |
| | | private IPasswordFreeLoginService passwordFreeLoginService; |
| | | |
| | | @GetMapping("/login") |
| | | public R passwordFreeLogin(String account) { |
| | | boolean resBoolean = passwordFreeLoginService.passwordFreeLogin(account); |
| | | return R.status(resBoolean); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | treeWrapperOptions.copyFromTreeQuery(treeQueryObject); |
| | | return revisionModelUtil.doList2Trees(voList,treeWrapperOptions,(CodeClassifyValueVO s) ->{ |
| | | //å¯ä»¥å¨è¿éå¤çæ èç¹çæ¾ç¤º |
| | | return s.getId() + " " + s.getName() + (FrameworkDataLCStatus.DISABLED.getValue().equalsIgnoreCase(s |
| | | return s.getId() + " " + (Func.isNotEmpty(s.getName()) ? s.getName():"") + (FrameworkDataLCStatus.DISABLED.getValue().equalsIgnoreCase(s |
| | | .getLcStatus()) ? (" ãåç¨ã ") : ""); |
| | | }); |
| | | } |
| | |
| | | @Resource |
| | | private ICodeFixedValueService codeFixedValueService; |
| | | |
| | | @Resource |
| | | private ICodeClassifyValueService codeClassifyValueService; |
| | | |
| | | /** |
| | | * å页æ¥è¯¢ |
| | | * @param query |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<CodeRuleVO> gridCodeRule(Query query, Map<String,Object> conidtionMap) { |
| | | public IPage<CodeRuleVO> gridCodeRule(Query query, Map<String,Object> conidtionMap) throws VciBaseException { |
| | | //妿çäºèªå·±é
ç½®ç管çç»ç§æ·idå管çç»è¶
管账å·ï¼å°±ä¸éè¦æç
§è§åææè
æ¥è¿è¡æ¥è¯¢ |
| | | if(!(AuthUtil.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId()) |
| | | && AuthUtil.getUserId().toString().equals(nacosConfigCache.getAdminUserInfo().getUserId().toString())) |
| | |
| | | * @return è¿åfalse表示æªéå¤ |
| | | */ |
| | | @Override |
| | | public boolean checkCodeRuleRepeat(CodeRuleDTO codeRuleDTO){ |
| | | public boolean checkCodeRuleRepeat(CodeRuleDTO codeRuleDTO)throws VciBaseException { |
| | | LambdaQueryWrapper<CodeRule> wrapper = Wrappers.<CodeRule>query() |
| | | .lambda().eq(CodeRule::getId, codeRuleDTO.getId()); |
| | | if(AuthUtil.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId())){ |
| | |
| | | * @return true表示已ç»ä½¿ç¨ï¼false表示æªè¢«ä½¿ç¨ |
| | | */ |
| | | @Override |
| | | public boolean isAlreadyInUse(String oid) { |
| | | public boolean isAlreadyInUse(String oid) throws VciBaseException { |
| | | Collection<CodeClassifyVO> codeClassifyVOS = listUseRangeInCodeClassify(oid); |
| | | if (codeClassifyVOS.size() > 0) { |
| | | return true; |
| | |
| | | * @return 主é¢åºå类使ç¨å°è¯¥ç¼ç è§åçææéå |
| | | */ |
| | | @Override |
| | | public Collection<CodeClassifyVO> listUseRangeInCodeClassify(String oid) { |
| | | public Collection<CodeClassifyVO> listUseRangeInCodeClassify(String oid) throws VciBaseException { |
| | | List<CodeClassify> codeClassifies = codeClassifyServcie.selectByWrapper(Wrappers.<CodeClassify>query().lambda().eq(CodeClassify::getCodeRuleOid, oid)); |
| | | return CodeClassifyWrapper.build().listVO(codeClassifies); |
| | | } |
| | |
| | | * @param oidCollections 主é®çéå |
| | | * @return æ°æ®å¯¹è±¡å表 |
| | | */ |
| | | private List<CodeRule> listCodeRuleDOByOidCollections(Collection<String> oidCollections) { |
| | | private List<CodeRule> listCodeRuleDOByOidCollections(Collection<String> oidCollections) throws VciBaseException { |
| | | List<CodeRule> codeRuleDOList = new ArrayList<CodeRule>(); |
| | | if (!CollectionUtils.isEmpty(oidCollections)) { |
| | | Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); |
| | |
| | | * @return æ§è¡ç»æ |
| | | */ |
| | | @Override |
| | | public R updateStatus(String oid, String update) { |
| | | public R updateStatus(String oid, String update) throws VciBaseException { |
| | | int count = 0; |
| | | //å
æ¥è¯¢å¯¹è±¡ |
| | | CodeRule codeRuleDO = selectByOid(oid); |
| | |
| | | * @return è§åçæ¾ç¤ºå¯¹è±¡ |
| | | */ |
| | | @Override |
| | | public CodeRuleVO getObjectHasSecByOid(String oid) { |
| | | public CodeRuleVO getObjectHasSecByOid(String oid) throws VciBaseException { |
| | | CodeRule ruleDO = selectByOid(oid); |
| | | return codeRuleDO2VO(ruleDO, true); |
| | | } |
| | |
| | | return phaseAttrService.listAttrByTemplateOidAndPhaseId(templateVO.getOid(), phase); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * è·¯å¾ä¸å
å«å½ååç±»çææåç±»ä¿¡æ¯ |
| | | * |
| | |
| | | CodeSecTypeEnum.CODE_FIXED_SEC.getValue(), |
| | | CodeSecTypeEnum.CODE_VARIABLE_SEC.getValue(), |
| | | CodeSecTypeEnum.CODE_CLASSIFY_SEC.getValue(), |
| | | CodeSecTypeEnum.CODE_REFER_SEC.getValue() |
| | | CodeSecTypeEnum.CODE_REFER_SEC.getValue(), |
| | | CodeSecTypeEnum.CODE_DATE_SEC.getValue() |
| | | ); |
| | | // åªè¯»ç 段类å |
| | | List<String> readOnlyTypes = Arrays.asList( |
| | | CodeSecTypeEnum.CODE_LEVEL_SEC.getValue(), |
| | | CodeSecTypeEnum.CODE_ATTR_SEC.getValue(), |
| | | CodeSecTypeEnum.CODE_DATE_SEC.getValue() |
| | | CodeSecTypeEnum.CODE_ATTR_SEC.getValue() |
| | | ); |
| | | // éèç æ®µç±»å |
| | | /*List<String> hideType = Arrays.asList( |
| | |
| | | package com.vci.ubcs.code.service.impl; |
| | | |
| | | import com.vci.ubcs.code.service.IPasswordFreeLoginService; |
| | | import com.vci.ubcs.code.util.HttpUtils; |
| | | import org.apache.commons.collections4.MultiValuedMap; |
| | | import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cloud.client.ServiceInstance; |
| | | import org.springframework.cloud.client.discovery.DiscoveryClient; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å
å¯ç»å½æå¡ |
| | | * @author ludc |
| | |
| | | @Service |
| | | public class PasswordFreeLoginServiceImpl implements IPasswordFreeLoginService { |
| | | |
| | | private RestTemplate restTemplate; |
| | | // éè¿æå¡æ³¨åä¸å¿è·åç½å
³ç端å£å· |
| | | @Autowired |
| | | private DiscoveryClient discoveryClient; |
| | | |
| | | /** |
| | | * è·åç½å
³ç«¯å£ |
| | | * @return |
| | | */ |
| | | public String getGatewayPort() { |
| | | List<ServiceInstance> instances = discoveryClient.getInstances("ubcs-gateway"); |
| | | if (!instances.isEmpty()) { |
| | | ServiceInstance gatewayInstance = instances.get(0); |
| | | return String.valueOf(gatewayInstance.getPort()); |
| | | } |
| | | return "80"; |
| | | } |
| | | |
| | | /** |
| | | * å
å¯ç»å½ |
| | |
| | | @Override |
| | | public boolean passwordFreeLogin(String account) { |
| | | // å
å¯ç»å½æ¥å£å°å |
| | | String loginUrl = "http://ubcs-auth/auth/login"; |
| | | String loginUrl = "http://localhost:"+this.getGatewayPort()+"/ubcs-auth/oauth/passwordFreeLogin?username=admin&grant_type=captcha&scope=all&type=account"; |
| | | |
| | | // 设置请æ±å¤´ |
| | | HttpHeaders headers = new HttpHeaders(); |
| | |
| | | MultiValueMap<String,String> bodyParams = new LinkedMultiValueMap<String,String>(); |
| | | bodyParams.add("account",account); |
| | | |
| | | // å建请æ±å®ä½ |
| | | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(bodyParams, headers); |
| | | |
| | | // åéPOSTè¯·æ± |
| | | ResponseEntity<String> responseEntity = restTemplate.exchange(loginUrl, HttpMethod.POST, requestEntity, String.class); |
| | | String responseBody = responseEntity.getBody(); |
| | | |
| | | String responseBody = HttpUtils.post(loginUrl, bodyParams); |
| | | System.out.println(responseBody); |
| | | //æ¿å°ååºä½å°tokenåå
¥å°redisä¸ï¼ä»¥accountä½ä¸ºåå¨çkey |
| | | |
| | | // è§£æååºä½è·å令ç |