Search in sources :

Example 6 with BaseJwtAuthToken

use of com.diboot.iam.jwt.BaseJwtAuthToken in project diboot by dibo-software.

the class SSOAuthServiceImpl method applyToken.

@Override
public String applyToken(AuthCredential credential) {
    BaseJwtAuthToken authToken = initBaseJwtAuthToken(credential);
    try {
        Subject subject = SecurityUtils.getSubject();
        subject.login(authToken);
        if (subject.isAuthenticated()) {
            log.debug("申请token成功!authtoken={}", authToken.getCredentials());
            saveLoginTrace(authToken, true);
            // 跳转到首页
            return (String) authToken.getCredentials();
        } else {
            log.error("认证失败");
            saveLoginTrace(authToken, false);
            throw new BusinessException(Status.FAIL_OPERATION, "认证失败");
        }
    } catch (Exception e) {
        log.error("登录异常", e);
        saveLoginTrace(authToken, false);
        throw new BusinessException(Status.FAIL_OPERATION, e.getMessage());
    }
}
Also used : BaseJwtAuthToken(com.diboot.iam.jwt.BaseJwtAuthToken) BusinessException(com.diboot.core.exception.BusinessException) Subject(org.apache.shiro.subject.Subject) InvalidUsageException(com.diboot.core.exception.InvalidUsageException) BusinessException(com.diboot.core.exception.BusinessException) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Aggregations

BaseJwtAuthToken (com.diboot.iam.jwt.BaseJwtAuthToken)6 BusinessException (com.diboot.core.exception.BusinessException)3 AuthenticationException (org.apache.shiro.authc.AuthenticationException)3 Subject (org.apache.shiro.subject.Subject)3 InvalidUsageException (com.diboot.core.exception.InvalidUsageException)1 SSOCredential (com.diboot.iam.dto.SSOCredential)1 MobileCredential (com.diboot.mobile.dto.MobileCredential)1