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


Java UsernamePasswordToken.getPrincipal方法代碼示例

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


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

示例1: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    if (!"password".equals(new String(upToken.getPassword()))) {
        throw new AuthenticationException("Invalid password for user: " + upToken.getUsername());
    }

    return new SimpleAuthenticationInfo(upToken.getPrincipal(), upToken.getCredentials(), getName());
}
 
開發者ID:bootique,項目名稱:bootique-shiro,代碼行數:11,代碼來源:ShiroWebModuleIT.java

示例2: authenticateUser

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
private void authenticateUser(Subject currentUser, ShiroSecurityToken securityToken) {
    boolean authenticated = currentUser.isAuthenticated();
    boolean sameUser = securityToken.getUsername().equals(currentUser.getPrincipal());
    LOG.trace("Authenticated: {}, same Username: {}", authenticated, sameUser);

    if (!authenticated || !sameUser) {
        UsernamePasswordToken token = new UsernamePasswordToken(securityToken.getUsername(), securityToken.getPassword());
        if (policy.isAlwaysReauthenticate()) {
            token.setRememberMe(false);
        } else {
            token.setRememberMe(true);
        }

        try {
            currentUser.login(token);
            LOG.debug("Current user {} successfully authenticated", currentUser.getPrincipal());
        } catch (UnknownAccountException uae) {
            throw new UnknownAccountException("Authentication Failed. There is no user with username of " + token.getPrincipal(), uae.getCause());
        } catch (IncorrectCredentialsException ice) {
            throw new IncorrectCredentialsException("Authentication Failed. Password for account " + token.getPrincipal() + " was incorrect!", ice.getCause());
        } catch (LockedAccountException lae) {
            throw new LockedAccountException("Authentication Failed. The account for username " + token.getPrincipal() + " is locked."
                    + "Please contact your administrator to unlock it.", lae.getCause());
        } catch (AuthenticationException ae) {
            throw new AuthenticationException("Authentication Failed.", ae.getCause());
        }
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:29,代碼來源:ShiroSecurityProcessor.java

示例3: copy

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected SubjectContext copy(SubjectContext subjectContext) {
  // this is the only way to trick the superclass into believing subject is always authenticated
  UsernamePasswordToken token = new UsernamePasswordToken("permissive", "nopassword");
  SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), "Permissive");
  subjectContext.setAuthenticated(true);
  subjectContext.setAuthenticationToken(token);
  subjectContext.setAuthenticationInfo(info);
  return subjectContext;
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:11,代碼來源:PermissiveSecurityManager.java

示例4: copy

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected SubjectContext copy(SubjectContext subjectContext) {
  // this is the only way to trick the superclass into believing subject is always authenticated
  UsernamePasswordToken token = new UsernamePasswordToken("permissive", "nopassword");
  SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(token.getPrincipal(),
                                                               token.getCredentials(),
                                                               "Permissive");
  subjectContext.setAuthenticated(true);
  subjectContext.setAuthenticationToken(token);
  subjectContext.setAuthenticationInfo(info);
  return subjectContext;
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:13,代碼來源:DefaultLiveDataManagerTest.java


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