Search in sources :

Example 1 with BaseJwtAuthToken

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

the class PwdAuthServiceImpl 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) BusinessException(com.diboot.core.exception.BusinessException) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Example 2 with BaseJwtAuthToken

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

the class SSOAuthServiceImpl method initBaseJwtAuthToken.

/**
 * 初始化JwtAuthToken实例
 * @param credential
 * @return
 */
private BaseJwtAuthToken initBaseJwtAuthToken(AuthCredential credential) {
    // 通过CAS得到账号
    SSOCredential ssoCredential = (SSOCredential) credential;
    BaseJwtAuthToken token = new BaseJwtAuthToken(getAuthType(), ssoCredential.getUserTypeClass());
    String username = parseCasTicket(ssoCredential);
    ssoCredential.setAuthAccount(username);
    // 设置账号密码
    token.setAuthAccount(ssoCredential.getAuthAccount());
    token.setTenantId(credential.getTenantId());
    token.setRememberMe(ssoCredential.isRememberMe());
    // 生成token
    return token.generateAuthtoken(getExpiresInMinutes());
}
Also used : BaseJwtAuthToken(com.diboot.iam.jwt.BaseJwtAuthToken) SSOCredential(com.diboot.iam.dto.SSOCredential)

Example 3 with BaseJwtAuthToken

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

the class WxAuthServiceImpl method initBaseJwtAuthToken.

/**
 * 初始化JwtAuthToken实例
 * @param credential
 * @return
 */
private BaseJwtAuthToken initBaseJwtAuthToken(AuthCredential credential) {
    MobileCredential wxMpCredential = (MobileCredential) credential;
    BaseJwtAuthToken token = new BaseJwtAuthToken(getAuthType(), wxMpCredential.getUserTypeClass());
    // 设置登陆的
    token.setAuthAccount(wxMpCredential.getAuthAccount());
    token.setRememberMe(wxMpCredential.isRememberMe());
    // 生成token
    return token.generateAuthtoken(getExpiresInMinutes());
}
Also used : MobileCredential(com.diboot.mobile.dto.MobileCredential) BaseJwtAuthToken(com.diboot.iam.jwt.BaseJwtAuthToken)

Example 4 with BaseJwtAuthToken

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

the class WxAuthServiceImpl 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) BusinessException(com.diboot.core.exception.BusinessException) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Example 5 with BaseJwtAuthToken

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

the class PwdAuthServiceImpl method initBaseJwtAuthToken.

/**
 * 初始化JwtAuthToken实例
 * @param credential
 * @return
 */
private BaseJwtAuthToken initBaseJwtAuthToken(AuthCredential credential) {
    BaseJwtAuthToken token = new BaseJwtAuthToken(getAuthType(), credential.getUserTypeClass());
    // 设置账号密码
    token.setAuthAccount(credential.getAuthAccount());
    token.setAuthSecret(credential.getAuthSecret());
    token.setRememberMe(credential.isRememberMe());
    token.setTenantId(credential.getTenantId());
    token.setExtObj(credential.getExtObj());
    // 生成token
    return token.generateAuthtoken(getExpiresInMinutes());
}
Also used : BaseJwtAuthToken(com.diboot.iam.jwt.BaseJwtAuthToken)

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