|
@@ -17,6 +17,7 @@ import org.springframework.security.authentication.AuthenticationManager;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
|
+import org.springframework.security.core.userdetails.UserDetails;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -24,8 +25,8 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 登录校验方法
|
|
* 登录校验方法
|
|
|
- *
|
|
|
|
|
-
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+
|
|
|
*/
|
|
*/
|
|
|
@Component
|
|
@Component
|
|
|
public class CompanyLoginService
|
|
public class CompanyLoginService
|
|
@@ -39,6 +40,9 @@ public class CompanyLoginService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
private RedisCache redisCache;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UserDetailsBynameServiceImpl userDetailsBynameService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 登录验证
|
|
* 登录验证
|
|
|
*
|
|
*
|
|
@@ -89,6 +93,17 @@ public class CompanyLoginService
|
|
|
redisCache.setCacheObject("companyId:"+loginUser.getUser().getUserId(),loginUser.getUser().getCompanyId(),604800, TimeUnit.SECONDS);
|
|
redisCache.setCacheObject("companyId:"+loginUser.getUser().getUserId(),loginUser.getUser().getCompanyId(),604800, TimeUnit.SECONDS);
|
|
|
// 生成token
|
|
// 生成token
|
|
|
return tokenService.createToken(loginUser);
|
|
return tokenService.createToken(loginUser);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public String login2(String username) {
|
|
|
|
|
+ UserDetails userDetails = userDetailsBynameService.loadUserByUsername(username);
|
|
|
|
|
+ LoginUser loginUser = (LoginUser) userDetails;
|
|
|
|
|
+
|
|
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginUser.getUser().getCompanyId(), username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
|
|
+ redisCache.setCacheObject("companyId:" + loginUser.getUser().getUserId(), loginUser.getUser().getCompanyId(), 604800, TimeUnit.SECONDS);
|
|
|
|
|
+ // 生成token
|
|
|
|
|
+ return tokenService.createToken(loginUser);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|