當前位置: 首頁>>代碼示例>>Java>>正文


Java AuthenticationToken類代碼示例

本文整理匯總了Java中org.apache.shiro.authc.AuthenticationToken的典型用法代碼示例。如果您正苦於以下問題:Java AuthenticationToken類的具體用法?Java AuthenticationToken怎麽用?Java AuthenticationToken使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AuthenticationToken類屬於org.apache.shiro.authc包,在下文中一共展示了AuthenticationToken類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onLoginFailure

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException ae, ServletRequest request,
                                 ServletResponse response) {

    final OAuthResponse oAuthResponse;
    try {
        oAuthResponse = OAuthRSResponse.errorResponse(401)
                .setError(OAuthError.ResourceResponse.INVALID_TOKEN)
                .setErrorDescription(ae.getMessage())
                .buildJSONMessage();

        com.monkeyk.os.web.WebUtils.writeOAuthJsonResponse((HttpServletResponse) response, oAuthResponse);

    } catch (OAuthSystemException e) {
        LOGGER.error("Build JSON message error", e);
        throw new IllegalStateException(e);
    }


    return false;
}
 
開發者ID:monkeyk,項目名稱:oauth2-shiro,代碼行數:22,代碼來源:OAuth2Filter.java

示例2: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
/**
 * 認證回調函數,登錄時調用.
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken authcToken) throws AuthenticationException {
	UsernamePassword2Token token = (UsernamePassword2Token) authcToken;
	String username = token.getUsername();
	if (username == null || null == username) {
		throw new AccountException(
				"Null usernames are not allowed by this realm.");
	}
	User entity = new User();
	entity.setEmail(username);
	entity.setStatus(Constant.STATUS_ENABLED);
	entity = (User) service.iUserService.select(entity);
	if (null == entity) {
		throw new UnknownAccountException("No account found for user ["
				+ username + "]");
	}
	byte[] key = Encode.decodeHex(entity.getRandom());
	return new SimpleAuthenticationInfo(new Shiro(entity.getId(),
			entity.getEmail(), entity.getName()), entity.getPassword(),
			ByteSource.Util.bytes(key), getName());
}
 
開發者ID:jiangzongyao,項目名稱:kettle_support_kettle8.0,代碼行數:26,代碼來源:Authorizing2Realm.java

示例3: queryForAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
/**
 * Builds an {@link AuthenticationInfo} object by querying the active directory LDAP context for the
 * specified username.
 */
@Override
protected AuthenticationInfo queryForAuthenticationInfo(
        AuthenticationToken token, LdapContextFactory ldapContextFactory) throws NamingException {

    final UsernamePasswordToken upToken = ensureUsernamePasswordToken(token);
    final String userDn = findUserDn(ldapContextFactory, upToken.getUsername());

    LdapContext ctx = null;
    try {
        // Binds using the username and password provided by the user.
        ctx = ldapContextFactory.getLdapContext(userDn, upToken.getPassword());
    } finally {
        LdapUtils.closeContext(ctx);
    }
    return buildAuthenticationInfo(upToken.getUsername(), upToken.getPassword());
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:21,代碼來源:SearchFirstActiveDirectoryRealm.java

示例4: onLoginSuccess

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
/**
 * 覆蓋默認實現,用sendRedirect直接跳出框架,以免造成js框架重複加載js出錯。
 * 
 * @param token
 * @param subject
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@Override
protected boolean onLoginSuccess(AuthenticationToken token,
		Subject subject, ServletRequest request, ServletResponse response)
		throws Exception {
	HttpServletRequest httpRequest = (HttpServletRequest) request;
	HttpServletResponse httpResponse = (HttpServletResponse) response;

	if (!"XMLHttpRequest".equalsIgnoreCase(httpRequest
			.getHeader("X-Requested-With"))) {
		httpResponse.sendRedirect(httpRequest.getContextPath()
				+ this.getSuccessUrl());
	} else {
		httpRequest.getRequestDispatcher("/CN").forward(httpRequest,
				httpResponse);
	}
	return false;
}
 
開發者ID:jiangzongyao,項目名稱:kettle_support_kettle8.0,代碼行數:28,代碼來源:FormAuthentication2Filter.java

示例5: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
		//UsernamePasswordToken對象用來存放提交的登錄信息
        UsernamePasswordToken token=(UsernamePasswordToken) authenticationToken;

        log.info("驗證當前Subject時獲取到token為:" + ReflectionToStringBuilder.toString(token, ToStringStyle.MULTI_LINE_STYLE)); 
//        return new SimpleAuthenticationInfo("hsjhsj","8e24137dee97c9bbddb9a0cd6e043be4" , getName());
        return new SimpleAuthenticationInfo("hsjhsj","" , getName());
        //查出是否有此用戶
//        TbUser user=null;
//        if(user!=null){
            // 若存在,將此用戶存放到登錄認證info中,無需自己做密碼對比,Shiro會為我們進行密碼對比校驗
//            return new SimpleAuthenticationInfo(user.getUsername(), , getName());
//        }
//        return null;
	}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:17,代碼來源:ShiroRealm.java

示例6: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException {
    String token = (String) auth.getCredentials();
    Cache<String, String> authCache = CacheController.getAuthCache();
    if (! authCache.containsKey(token)) {
        // get user info from database
        int uid = JWTUtil.getUid(token);
        UserEntity userEntity = userService.getUserByUid(uid);
        authCache.put(token, String.valueOf(userEntity.getPassword()));
    }

    String secret = authCache.get(token);
    if (!JWTUtil.decode(token, secret)) {
        throw new AuthenticationException("Token invalid");
    }

    return new SimpleAuthenticationInfo(token, token, "jwt_realm");
}
 
開發者ID:Eagle-OJ,項目名稱:eagle-oj-api,代碼行數:19,代碼來源:Realm.java

示例7: onLoginFailure

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    httpResponse.setContentType("application/json;charset=utf-8");
    try {
        //處理登錄失敗的異常
        Throwable throwable = e.getCause() == null ? e : e.getCause();
        R r = R.error(HttpStatus.SC_UNAUTHORIZED, throwable.getMessage());

        String json = new Gson().toJson(r);
        httpResponse.getWriter().print(json);
    } catch (IOException e1) {

    }

    return false;
}
 
開發者ID:zhaoqicheng,項目名稱:renren-fast,代碼行數:18,代碼來源:OAuth2Filter.java

示例8: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
/**
 * 用戶認證-驗證用戶是否登錄、用戶名密碼是否匹配
 */
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	logger.info(">>> 【用戶認證】token = {}", token);
	String userName = (String)token.getPrincipal();
	AdminUser user = getPrincipalService().getPrincipalObject(userName);
       if(user == null) {
           throw new UnknownAccountException("Unknown account: " + userName);//沒找到帳號
       }
       if(AdminUserStatusEnum.ADMIN_USER_STATUS_DISABLED.getStatusCode().equals(user.getStatus())) {
           throw new LockedAccountException("Account[" + userName + "] has been locked!"); //帳號鎖定
       }
       //交給AuthenticatingRealm使用CredentialsMatcher進行密碼匹配
       SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
               user.getUserName(), //用戶名
               user.getPassword(), //密碼
               ByteSource.Util.bytes(user.getPasswordSalt()),//salt
               getName()  //realm name
       );
       return authenticationInfo;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:23,代碼來源:AdminUserRealm.java

示例9: doCredentialsMatch

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
	String userName = (String)token.getPrincipal();
	final String key = REDIS_KEY_PREFIX + userName;
	long maxRetry = redisTemplate.opsForValue().increment(key, 1);
	if(maxRetry == 1){ //首次輸入密碼
		redisTemplate.expire(key, passwordRetryWaitMinutes, TimeUnit.MINUTES);
	}
	if(maxRetry >= passwordRetryLimit){
		throw new ExcessiveAttemptsException(passwordRetryLimit + "");
	}
	boolean matches = super.doCredentialsMatch(token, info);
       if(matches) {
       	redisTemplate.delete(key);
       }
       return matches;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:17,代碼來源:RetryLimitHashedCredentialsMatcher.java

示例10: login

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@RequestMapping(value = "/tlogin", method = RequestMethod.POST)
public String login(String username, String password, HttpServletRequest request) {

    //String validateCode = (String) ServletActionContext.getRequest().getSession().getAttribute("key");
    // if (StringUtils.isNotBlank(checkcode) && checkcode.equals(validateCode)) {
    // 使用shiri方式
    // 獲得當前對象的狀態:未認證
    Subject subject = SecurityUtils.getSubject();
    // 用戶名密碼令牌對象
    AuthenticationToken token = new UsernamePasswordToken(username,
            password);
    try {
        subject.login(token);
    } catch (Exception e) {
        e.printStackTrace();
        return "login";
    }
    User user = (User) subject.getPrincipal();
    // user放入session
    request.getSession().setAttribute("loginUser", user);
    return "index";
}
 
開發者ID:mmdsyl,項目名稱:BLOG-Microservice,代碼行數:23,代碼來源:TestController.java

示例11: createToken

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {

    HttpServletRequest httpRequest = (HttpServletRequest) request;

    final String accessToken = getAccessToken(httpRequest);
    final AccessToken token = rsService.loadAccessTokenByTokenId(accessToken);

    String username = null;
    if (token != null) {
        LOGGER.debug("Set username and clientId from AccessToken: {}", token);
        username = token.username();
        httpRequest.setAttribute(OAuth.OAUTH_CLIENT_ID, token.clientId());
    } else {
        LOGGER.debug("Not found AccessToken by access_token: {}", accessToken);
    }

    return new OAuth2Token(accessToken, resourceId)
            .setUserId(username);
}
 
開發者ID:monkeyk,項目名稱:oauth2-shiro,代碼行數:21,代碼來源:OAuth2Filter.java

示例12: createSubject

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@Override
public Subject createSubject(SubjectContext context) {


    boolean authenticated = context.isAuthenticated();

    if (authenticated) {

        AuthenticationToken token = context.getAuthenticationToken();

        if (token != null && token instanceof OAuth2Token) {
            OAuth2Token oAuth2Token = (OAuth2Token) token;
            if (oAuth2Token.isRememberMe()) {
                context.setAuthenticated(false);
            }
        }
    }

    return super.createSubject(context);
}
 
開發者ID:monkeyk,項目名稱:oauth2-shiro,代碼行數:21,代碼來源:OAuth2SubjectFactory.java

示例13: onLoginSuccess

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@Override
protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception {
    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    HttpServletResponse httpServletResponse = (HttpServletResponse) response;

    if (!httpServletRequest.getRequestURL().toString().endsWith(".json")) {
        issueSuccessRedirect(request, response);
    } else {

        httpServletResponse.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter out = httpServletResponse.getWriter();
        out.println("{\"code\":200,\"info\":\"登入成功\"}");
        out.flush();
        out.close();
    }

    return true;
}
 
開發者ID:liaojiacan,項目名稱:zkAdmin,代碼行數:20,代碼來源:LoginFilter.java

示例14: onLoginFailure

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
    if (!((HttpServletRequest)request).getRequestURL().toString().endsWith(".json")) {
        setFailureAttribute(request, e);
        return true;
    }
    try {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter out = response.getWriter();
        String message = e.getClass().getSimpleName();
        if ("IncorrectCredentialsException".equals(message)
                || "UnknownAccountException".equals(message)
                ) {
            out.println("{\"code\":-100010,\"info\":\"賬號或密碼錯誤\"}");
        }else if("ExcessiveAttemptsException".equals(message)){
            out.println("{\"code\":-100020,\"info\":\"密碼錯誤次數超過限製,請10分鍾後重試!\"}");
        }else if("LockedAccountException".equals(message)){
            out.println("{\"code\":-100030,\"info\":\"賬號已停用!\"}");
        } else {
            out.println("{\"code\":-100500,\"info\":\"未知錯誤\"}");
        }
        out.flush();
        out.close();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    return false;
}
 
開發者ID:liaojiacan,項目名稱:zkAdmin,代碼行數:31,代碼來源:LoginFilter.java

示例15: createToken

import org.apache.shiro.authc.AuthenticationToken; //導入依賴的package包/類
@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {

    HttpServletRequest httpRequest = (HttpServletRequest) request;

    final String accessToken = httpRequest.getParameter(OAuth.OAUTH_ACCESS_TOKEN);
    final AccessToken token = rsService.loadAccessTokenByTokenId(accessToken);

    String username = null;
    if (token != null) {
        username = token.username();
        logger.debug("Set username[{}] and clientId[{}] to request that from AccessToken: {}", username, token.clientId(), token);
        httpRequest.setAttribute(OAuth.OAUTH_CLIENT_ID, token.clientId());
    } else {
        logger.debug("Not found AccessToken by access_token: {}", accessToken);
    }

    return new OAuth2Token(accessToken, resourceId)
            .setUserId(username);
}
 
開發者ID:monkeyk,項目名稱:oauth2-shiro-redis,代碼行數:21,代碼來源:OAuth2Filter.java


注:本文中的org.apache.shiro.authc.AuthenticationToken類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。