| | |
| | | import eu.bitwalker.useragentutils.UserAgent; |
| | | import eu.bitwalker.useragentutils.Version; |
| | | |
| | | /** |
| | | * @author Tanbin |
| | | * @date 2018-12-12 |
| | | */ |
| | | @Component("loginAction2") |
| | | public class LoginAction2 extends AbstractAction { |
| | | protected Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | /** |
| | | * The Central authentication service. |
| | | */ |
| | | @Autowired |
| | | protected CentralAuthenticationService centralAuthenticationService; |
| | | |
| | | protected ServicesManager servicesManager; |
| | | @Override |
| | | protected Event doExecute(RequestContext requestContext) throws Exception { |
| | | final TicketGrantingTicket tgt; |
| | | final Map<String, HandlerResult> successes=new HashMap<>(); |
| | | String username= requestContext.getFlowScope().get("username").toString(); |
| | | UsernamePasswordCredential credential=new UsernamePasswordCredential(username,""); |
| | | CredentialMetaData cmd= new BasicCredentialMetaData(credential); |
| | | DefaultPrincipalFactory p=new DefaultPrincipalFactory(); |
| | | Principal principal=p.createPrincipal(username); |
| | | HandlerResult hs= new DefaultHandlerResult("handler",cmd,principal,null); |
| | | successes.put("success", hs); |
| | | final Map<String, Object> authenticationAttributes = new HashMap<>(); |
| | | AuthenticationBuilder d=DefaultAuthenticationBuilder.newInstance(); |
| | | |
| | | HttpServletRequest request = WebUtils.getHttpServletRequest(); |
| | | if(null != request) { |
| | | String uaStr = request.getHeader("User-Agent"); |
| | | UserAgent ua = UserAgent.parseUserAgentString(uaStr); |
| | | if(null != ua) { |
| | | Browser browser=ua.getBrowser(); |
| | | Version broVersion=browser.getVersion(uaStr); |
| | | final String browserInfo=browser.getName()+"/"+broVersion.getVersion(); |
| | | final String clientIp = ClientInfoHolder.getClientInfo().getClientIpAddress(); |
| | | String serviceUrl = request.getParameter("service"); |
| | | logger.debug("##### client IP address is [{}], browser is [{}], serviceUrl is [{}]", clientIp, browserInfo, serviceUrl); |
| | | authenticationAttributes.put("clientIp", clientIp); |
| | | authenticationAttributes.put("browserInfo", browserInfo); |
| | | authenticationAttributes.put("serviceUrl", serviceUrl); |
| | | } |
| | | } |
| | | //接收传来的用户名 |
| | | d.setPrincipal(principal); |
| | | d.addCredential(cmd); |
| | | d.setAttributes(authenticationAttributes); |
| | | d.setAuthenticationDate(ZonedDateTime.now()); |
| | | d.setSuccesses(successes); |
| | | Authentication authentication= d.build(); |
| | | |
| | | final DefaultAuthenticationResult res = new DefaultAuthenticationResult(authentication, null); |
| | | |
| | | tgt = this.centralAuthenticationService.createTicketGrantingTicket(res);; |
| | | WebUtils.putTicketGrantingTicketInScopes(requestContext, tgt); |
| | | WebUtils.putAuthenticationResult(res, requestContext); |
| | | WebUtils.putAuthentication(tgt.getAuthentication(), requestContext); |
| | | // return new Event(this,"directsubmit"); |
| | | return new Event(this,"success"); |
| | | } |
| | | |
| | | public void setServicesManager(ServicesManager servicesManager) { this.servicesManager = servicesManager; } |
| | | protected Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | /** |
| | | * The Central authentication service. |
| | | */ |
| | | @Autowired |
| | | protected CentralAuthenticationService centralAuthenticationService; |
| | | |
| | | protected ServicesManager servicesManager; |
| | | |
| | | @Override |
| | | protected Event doExecute(RequestContext requestContext) throws Exception { |
| | | final TicketGrantingTicket tgt; |
| | | final Map<String, HandlerResult> successes = new HashMap<>(5); |
| | | String username = requestContext.getFlowScope().get("username").toString(); |
| | | UsernamePasswordCredential credential = new UsernamePasswordCredential(username, ""); |
| | | CredentialMetaData cmd = new BasicCredentialMetaData(credential); |
| | | DefaultPrincipalFactory p = new DefaultPrincipalFactory(); |
| | | Principal principal = p.createPrincipal(username); |
| | | HandlerResult hs = new DefaultHandlerResult("handler", cmd, principal, null); |
| | | successes.put("success", hs); |
| | | final Map<String, Object> authenticationAttributes = new HashMap<>(5); |
| | | AuthenticationBuilder d = DefaultAuthenticationBuilder.newInstance(); |
| | | |
| | | HttpServletRequest request = WebUtils.getHttpServletRequest(); |
| | | if (null != request) { |
| | | String uaStr = request.getHeader("User-Agent"); |
| | | UserAgent ua = UserAgent.parseUserAgentString(uaStr); |
| | | if (null != ua) { |
| | | Browser browser = ua.getBrowser(); |
| | | Version broVersion = browser.getVersion(uaStr); |
| | | final String browserInfo = browser.getName() + "/" + broVersion.getVersion(); |
| | | final String clientIp = ClientInfoHolder.getClientInfo().getClientIpAddress(); |
| | | String serviceUrl = request.getParameter("service"); |
| | | logger.debug("##### client IP address is [{}], browser is [{}], serviceUrl is [{}]", clientIp, browserInfo, serviceUrl); |
| | | authenticationAttributes.put("clientIp", clientIp); |
| | | authenticationAttributes.put("browserInfo", browserInfo); |
| | | authenticationAttributes.put("serviceUrl", serviceUrl); |
| | | } |
| | | } |
| | | //接收传来的用户名 |
| | | d.setPrincipal(principal); |
| | | d.addCredential(cmd); |
| | | d.setAttributes(authenticationAttributes); |
| | | d.setAuthenticationDate(ZonedDateTime.now()); |
| | | d.setSuccesses(successes); |
| | | Authentication authentication = d.build(); |
| | | |
| | | final DefaultAuthenticationResult res = new DefaultAuthenticationResult(authentication, null); |
| | | |
| | | tgt = this.centralAuthenticationService.createTicketGrantingTicket(res); |
| | | ; |
| | | WebUtils.putTicketGrantingTicketInScopes(requestContext, tgt); |
| | | WebUtils.putAuthenticationResult(res, requestContext); |
| | | WebUtils.putAuthentication(tgt.getAuthentication(), requestContext); |
| | | // return new Event(this,"directsubmit"); |
| | | return new Event(this, "success"); |
| | | } |
| | | |
| | | public void setServicesManager(ServicesManager servicesManager) { |
| | | this.servicesManager = servicesManager; |
| | | } |
| | | } |