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


Java UsernamePasswordToken.getCredentials方法代碼示例

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


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

示例1: doGetAuthenticationInfo

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

  UsernamePasswordToken userToken = (UsernamePasswordToken) token;
  UnixUser user;

  try {
    user = (new PAM(this.getService()))
        .authenticate(userToken.getUsername(), new String(userToken.getPassword()));
  } catch (PAMException e) {
    throw new AuthenticationException("Authentication failed for PAM.", e);
  }

  return new SimpleAuthenticationInfo(
      new UserPrincipal(user),
      userToken.getCredentials(),
      getName());
}
 
開發者ID:apache,項目名稱:zeppelin,代碼行數:20,代碼來源:PamRealm.java

示例2: 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

示例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

示例5: doGetAuthenticationInfo

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

	if (!(authenticationToken instanceof UsernamePasswordToken)) {
		throw new UnsupportedTokenException("Token of type " + authenticationToken.getClass().getName()
				+ " is not supported.  A " + UsernamePasswordToken.class.getName() + " is required.");
	}
	UsernamePasswordToken userPass = (UsernamePasswordToken) authenticationToken;
	String token = new String(userPass.getPassword());
	if (token.isEmpty()) {
	    LOGGER.debug(GITLAB_MSG + "token for {} is empty", userPass.getUsername());
	    return null;
	}

	try {
	    LOGGER.debug(GITLAB_MSG + "authenticating {}", userPass.getUsername());

	    LOGGER.debug(GITLAB_MSG + "null? " + (gitlab == null));
	    LOGGER.debug(GITLAB_MSG + "null? " + (gitlab.getRestClient() == null));

	    GitlabUser gitlabUser = gitlab.getRestClient().getUser(userPass.getUsername(), token);
	    User user = gitlabUser.toUser();
	    if (user.getUserId() == null || user.getUserId().isEmpty()) {
	        LOGGER.debug(GITLAB_MSG + "authentication failed {}", user);
	        throw new AuthenticationException(DEFAULT_MESSAGE + " for " + userPass.getUsername());
	    }
	    LOGGER.debug(GITLAB_MSG + "successfully authenticated {}", userPass.getUsername());
	    return new SimpleAuthenticationInfo(gitlabUser /*userPass.getPrincipal()*/,
	            userPass.getCredentials(), getName());
	} catch (Exception e) {
	    LOGGER.debug(GITLAB_MSG + "authentication failed {}", userPass.getUsername());
	    throw new AuthenticationException(DEFAULT_MESSAGE, e);
	}
}
 
開發者ID:jdamick,項目名稱:nexus-gitlab-token-auth-plugin,代碼行數:36,代碼來源:GitlabAuthenticatingRealm.java


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