当前位置: 首页>>代码示例>>Java>>正文


Java ByteSource类代码示例

本文整理汇总了Java中org.apache.shiro.util.ByteSource的典型用法代码示例。如果您正苦于以下问题:Java ByteSource类的具体用法?Java ByteSource怎么用?Java ByteSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ByteSource类属于org.apache.shiro.util包,在下文中一共展示了ByteSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的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

示例2: genPassword

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
private String genPassword(final String psw, final String salt, final int iter) {
    try {

        final DefaultHashService hash = new DefaultHashService();
        hash.setPrivateSalt(ByteSource.Util.bytes(STATIC_SALT));
        hash.setHashIterations(iter);
        hash.setGeneratePublicSalt(false);
        hash.setHashAlgorithmName(ALG_NAME);

        final String pswEnc = hash.computeHash(new HashRequest.Builder()
                .setSource(psw).setSalt(salt).setIterations(iter).build()).toHex();

        return pswEnc;

    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:QueryAndEncodeDatabaseAuthenticationHandlerTests.java

示例3: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
/**
 * 认证
 * @param token
 * @return
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    //获取用户的输入的账号.
    String username = (String)token.getPrincipal();
    AdminUser user = adminUserService.findByUserName(username);
    if(user==null) throw new UnknownAccountException();
    if (0==user.getEnable()) {
        throw new LockedAccountException(); // 帐号锁定
    }
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            user.getId(), //用户
            user.getPassword(), //密码
            ByteSource.Util.bytes(username),
            getName() //realm name
    );
    // 把用户信息放在session里
    Session session = SecurityUtils.getSubject().getSession();
    session.setAttribute("AdminSession", user);
    session.setAttribute("AdminSessionId", user.getId());
    return authenticationInfo;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:28,代码来源:MyShiroRealm.java

示例4: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
/**
 * 对用户基本信息进行判定
 *
 * @param token
 * @return
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    String username = (String) token.getPrincipal();
    Admin admin = adminService.findByUsername(username);
    if (admin == null) {
        throw new UnknownAccountException();//没找到帐号
    }
    //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            admin.getUsername(), //用户名
            admin.getPassword(),
            ByteSource.Util.bytes(admin.getCredentialsSalt()),
            getName()  //realm name
    );
    return authenticationInfo;
}
 
开发者ID:melonlee,项目名称:LazyAdmin,代码行数:24,代码来源:UserRealm.java

示例5: passwordsMatch

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
public boolean passwordsMatch(Object submittedPlaintext, String encrypted) {
    ByteSource plaintextBytes = ByteSource.Util.bytes(submittedPlaintext);
    if (encrypted == null || encrypted.length() == 0) {
        return plaintextBytes == null || plaintextBytes.isEmpty();
    } else {
        if (plaintextBytes == null || plaintextBytes.isEmpty()) {
            return false;
        }
    }
    String plaintext = new String(plaintextBytes.getBytes());
    String[] tokens = encrypted.split("\\$");
    int iterations = Integer.parseInt(tokens[1]);
    byte[] salt = tokens[2].getBytes();
    String hash = tokens[3];

    KeySpec spec = new PBEKeySpec(plaintext.toCharArray(), salt, iterations, 256);
    try {
        String algorithmName = getAlgorithmFullName(tokens[0]);
        SecretKeyFactory f = SecretKeyFactory.getInstance(algorithmName);
        return hash.equals(Base64.encodeToString(f.generateSecret(spec).getEncoded()));
    } catch (Exception e) {
        log.error(e.getMessage());
        return false;
    }
}
 
开发者ID:ridi,项目名称:shiro-django-auth,代码行数:26,代码来源:DjangoPasswordService.java

示例6: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的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

示例7: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {


    String username = (String)token.getPrincipal();



    User user  = userService.findUserByLoginName(username);
    if(user == null) {
        throw new UnknownAccountException();//没找到帐号
    }

    UsernamePasswordToken hostToken = (UsernamePasswordToken)token;

    //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配,如果觉得不好可以自定义实现
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            new ShiroUser(user.getId(),user.getLoginName(),user.getNickname()), //用户名
            user.getPassword(), //密码
            ByteSource.Util.bytes(user.getCredentialsSalt()),//salt=username+salt
            getName()  //realm name
    );
    return authenticationInfo;
}
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:25,代码来源:UserRealm.java

示例8: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    //获取用户的输入的账号.
    String username = (String)token.getPrincipal();
    User user = userService.findByUserId(username);
    if(user==null) throw new UnknownAccountException();
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            user, //用户
            user.getPassword(), //密码
            ByteSource.Util.bytes(username),
            getName()  //realm name
    );
    // 当验证都通过后,把用户信息放在session里
    Session session = SecurityUtils.getSubject().getSession();
    session.setAttribute("userSession", user);
    session.setAttribute("userSessionId", user.getLoginId());
    return authenticationInfo;
}
 
开发者ID:ju5t1nhhh,项目名称:CMSdemo,代码行数:19,代码来源:MyShiroRealm.java

示例9: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
/**
 * 对用户基本信息进行判定
 *
 * @param token
 * @return
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    String username = (String) token.getPrincipal();
    User user = userService.findByUsername(username);
    if (user == null) {
        throw new UnknownAccountException();//没找到帐号
    }
    //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            user.getUsername(), //用户名
            user.getPasswd(),
            ByteSource.Util.bytes(user.getCredentialsSalt()),
            getName()  //realm name
    );
    return authenticationInfo;
}
 
开发者ID:melonlee,项目名称:PowerApi,代码行数:24,代码来源:UserRealm.java

示例10: testHashService

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
@Test
public void testHashService(){
    //默认也是好似用sha512
    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashAlgorithmName("SHA-512");
    //私盐
    hashService.setPrivateSalt(new SimpleByteSource("123"));
    //是否生成公盐
    hashService.setGeneratePublicSalt(true);
    //用于生成公盐,默认就这个
    hashService.setRandomNumberGenerator(new SecureRandomNumberGenerator());
    //生成hash值的迭代次数
    hashService.setHashIterations(1);

    HashRequest request = new HashRequest.Builder().setAlgorithmName("MD5")
            .setSource(ByteSource.Util.bytes("hello"))
            .setSalt(ByteSource.Util.bytes("123"))
            .setIterations(2)
            .build();

    String hex = hashService.computeHash(request).toHex();
    System.out.println(hex);
}
 
开发者ID:l81893521,项目名称:shiro-demo,代码行数:24,代码来源:CodecAndCryptoTest.java

示例11: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    String username = "liu";
    //随机数
    String salt2 = "0072273a5d87322163795118fdd7c45e";
    //加密后的密码
    String password = "be320beca57748ab9632c4121ccac0db";

    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(username, password, getName());
    authenticationInfo.setCredentialsSalt(ByteSource.Util.bytes(username + salt2));
    return authenticationInfo;
}
 
开发者ID:l81893521,项目名称:shiro-demo,代码行数:12,代码来源:MyRealm2.java

示例12: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
/**
 * 主要用于验证
 * @param token
 * @return
 * @throws AuthenticationException
 */
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

    String username = (String)token.getPrincipal();

    User user = userService.findByUsername(username);

    if(user == null) {
        throw new UnknownAccountException();//没找到帐号
    }

    if(Boolean.TRUE.equals(user.getLocked())) {
        throw new LockedAccountException(); //帐号锁定
    }

    //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配,如果觉得人家的不好可以自定义实现
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            user.getUsername(), //用户名
            user.getPassword(), //密码
            ByteSource.Util.bytes(user.getCredentialsSalt()),//salt=username+salt
            getName()  //realm name
    );
    return authenticationInfo;
}
 
开发者ID:l81893521,项目名称:shiro-demo,代码行数:30,代码来源:UserRealm.java

示例13: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
      UsernamePasswordToken upToken = (UsernamePasswordToken) token;

     /* if (Strings.isBlank(upToken.getCaptcha()))
          throw new AuthenticationException("验证码不能为空");
      String _captcha = Strings.sBlank(SecurityUtils.getSubject().getSession(true).getAttribute(Toolkit.captcha_attr));
      if (!upToken.getCaptcha().equalsIgnoreCase(_captcha))
          throw new AuthenticationException("验证码错误");*/

      User user = dao().fetch(User.class, Cnd.where("name", "=", upToken.getUsername()));
      if (user == null)
          return null;
      if (user.isLocked()) 
          throw new LockedAccountException("Account [" + upToken.getUsername() + "] is locked.");
      ByteSource salt = ByteSource.Util.bytes(user.getSalt());
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getPassword(), getName());
info.setCredentialsSalt(salt);
return info;
  }
 
开发者ID:strictnerd,项目名称:windows-file-change,代码行数:20,代码来源:NutDaoRealm.java

示例14: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	String phoneNumber = (String)token.getPrincipal();
       if(StringUtils.trimToNull(phoneNumber) == null){
           throw new IncorrectCredentialsException();//账号或密码错误
       }
	CdMember query = new CdMember();
	query.setPhoneNumber(phoneNumber);
       CdMember member = memberService.findMember(query);
       if(member == null) {
           throw new UnknownAccountException();//没找到帐号
       }
       SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
               phoneNumber, //用户名
               member.getPassword(), //密码
               ByteSource.Util.bytes(AppConstants.PC_PASSWORD_SALT),//salt=phoneNumber
               getName()  //realm name
       );
       return authenticationInfo;
}
 
开发者ID:xmomen,项目名称:dms-webapp,代码行数:21,代码来源:MemberRealm.java

示例15: doGetAuthenticationInfo

import org.apache.shiro.util.ByteSource; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

    String username = (String)token.getPrincipal();

    SysUsers user = userService.findByUsername(username);

    if(user == null) {
        throw new UnknownAccountException();//没找到帐号
    }

    if(Boolean.TRUE.equals(user.getLocked())) {
        throw new LockedAccountException(); //帐号锁定
    }

    //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配,如果觉得人家的不好可以自定义实现
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            username, //用户名
            user.getPassword(), //密码
            ByteSource.Util.bytes(user.getSalt()),//salt=salt
            getName()  //realm name
    );
    return authenticationInfo;
}
 
开发者ID:xmomen,项目名称:dms-webapp,代码行数:25,代码来源:UserRealm.java


注:本文中的org.apache.shiro.util.ByteSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。