cas5.3 通过接口登录,登录后可跳到任意子系统,

发布时间 2023-11-13 14:30:22作者: 青木流水
Map<String, Object> map = (Map) new MyBeanMap(systemUser);
        PrincipalFactory principalFactory = new DefaultPrincipalFactory();
        Principal principal = principalFactory.createPrincipal(systemUser.getLoginid(),map);

        AuthenticationBuilder authenticationBuilder = DefaultAuthenticationBuilder.newInstance();
        authenticationBuilder.setPrincipal(principal);
        //authenticationBuilder.setAttributes(map);
        authenticationBuilder.setAuthenticationDate(ZonedDateTime.now());
        UsernamePasswordCaptchaCredential myCredential = new UsernamePasswordCaptchaCredential();
        myCredential.setNe(systemUser.getLoginid());
        myCredential.setWd("");
        BasicCredentialMetaData basicCredentialMetaData = new BasicCredentialMetaData(myCredential);
        List<CredentialMetaData> list = new ArrayList<>();
        list.add(basicCredentialMetaData);
        authenticationBuilder.addCredentials(list);
        Authentication auth = authenticationBuilder.build();

        AbstractWebApplicationService simpleWebApplicationService = new SimpleWebApplicationServiceImpl();
        simpleWebApplicationService.setId(service);
        simpleWebApplicationService.setOriginalUrl(service);
        simpleWebApplicationService.setSource("service");
        DefaultAuthenticationResult authenticationResult = new DefaultAuthenticationResult(auth, simpleWebApplicationService);
        authenticationResult.setCredentialProvided(true);
        //生成TGT,并保存到cookie中
        TicketGrantingTicket ticketGrantingTicket = centralAuthenticationService.createTicketGrantingTicket(authenticationResult);
        ticketGrantingTicketCookieGenerator.addCookie(request, response, ticketGrantingTicket.getId());