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


Java SimpleByteSource类代码示例

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


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

示例1: doGetAuthenticationInfo

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
private AuthenticationInfo doGetAuthenticationInfo(String email) throws AuthenticationException {
	Preconditions.checkNotNull(email, "Email can't be null");
       LOGGER.info("Finding authentication info for " + email + " in DB");

	final User user = userRepository.findByEmailAndActive(email, true);

	SimpleAccount account = new SimpleAccount(user.getEmail(), user.getPassword().toCharArray(),
               new SimpleByteSource(email), getName());

	final int totalRoles = user.getRoles().size();
	final Set<String> roleNames = new LinkedHashSet<>(totalRoles);
	final Set<String> permissionNames = new LinkedHashSet<>();
	if (totalRoles > 0) {
		for (Role role : user.getRoles()) {
			roleNames.add(role.getName());
			for (Permission permission : role.getPermissions()) {
				permissionNames.add(permission.getName());
			}
		}
	}

	account.setRoles(roleNames);
	account.setStringPermissions(permissionNames);
	return account;
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:26,代码来源:DatabaseRealm.java

示例2: testHashService

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

示例3: doGetAuthenticationInfo

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	if (token instanceof UsernamePasswordToken) {
		String username = ((UsernamePasswordToken) token).getUsername();
		char[] password = ((UsernamePasswordToken) token).getPassword();

		if (Strings.isNullOrEmpty(username) || password == null) {
			return null;
		}

		User user = userRepository.findByUsername(username);
		if (user == null) {
			throw new UnknownAccountException();
		}

		return new SimpleAuthenticationInfo(new Principal(user.getId(), username), user.getPassword(), new SimpleByteSource(user.getUsername()),
				getName());
	}
	return null;
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:21,代码来源:DatabaseRealm.java

示例4: setupModule

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
@Override
        public void setupModule(SetupContext context) {
            context.setMixInAnnotations(Object.class, DisableGetters.class);
            context.setMixInAnnotations(Collection.class, DisableTypeInfo.class);
            context.setMixInAnnotations(Map.class, DisableTypeInfo.class);
//            context.setMixInAnnotations(Array.class, DisableTypeInfo.class);
            
            //Default types for interfaces unknown to Jackson
            context.setMixInAnnotations(Bindings.class, UseSimpleBindings.class);
            context.setMixInAnnotations(PrincipalCollection.class, UseSimplePrincipalCollection.class);
            
            //serializers and typeinfo for shiro classes
            context.setMixInAnnotations(SimpleAuthenticationInfo.class, UseTypeInfoForCredentials.class);
            context.setMixInAnnotations(SimpleHash.class, SimpleHashMixin.class);
            context.setMixInAnnotations(ByteSource.class, UseSimpleByteSource.class);
            context.setMixInAnnotations(SimpleByteSource.class, SimpleByteSourceMixin.class);
            
            //and it's safer to use public interfaces on some classes
            context.setMixInAnnotations(ConstraintViolation.class, UseDefaultAutoDetect.class);
            context.setMixInAnnotations(ConstraintDescriptor.class, UseDefaultAutoDetect.class);
            context.setMixInAnnotations(Node.class, UseDefaultAutoDetect.class);
            
            
        }
 
开发者ID:CIDARLAB,项目名称:clotho3crud,代码行数:25,代码来源:JSON.java

示例5: doGetAuthenticationInfo

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

  // Null username is invalid
  if(username == null) {
    throw new AccountException("Null usernames are not allowed by this realm.");
  }

  User user = userService.findActiveUser(username);
  if(user == null) user = userService.findActiveUserByEmail(username);
  if(user == null || !user.isEnabled() || !user.getRealm().equals(AGATE_REALM))
    throw new UnknownAccountException("No account found for user [" + username + "]");

  username = user.getName();
  UserCredentials userCredentials = userService.findUserCredentials(username);
  if(userCredentials == null) throw new UnknownAccountException("No account found for user [" + username + "]");

  SimpleAuthenticationInfo authInfo = new SimpleAuthenticationInfo(username, userCredentials.getPassword(), getName());
  authInfo.setCredentialsSalt(new SimpleByteSource(salt));
  return authInfo;
}
 
开发者ID:obiba,项目名称:agate,代码行数:24,代码来源:AgateUserRealm.java

示例6: getHashString

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
public static String getHashString(String secret, byte[] salt) {
	return (secret == null) ? null : new SimpleHash(HASH_ALGORITHM, secret, new SimpleByteSource(salt), HASH_ITERATIONS).toHex();
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:4,代码来源:HashHelper.java

示例7: doGetAuthenticationInfo

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

    UserService service = App.get().service(UserService.class);
    User user = service.getUserForRealm(upToken.getUsername());

    if (user == null)
        throw new UnknownAccountException("User '" + Strings.maskEmail(upToken.getUsername()) + "' not found");

    return new SimpleAuthenticationInfo(user.getId(), user.getPassword(), new SimpleByteSource(user.getSalt()),
        getName());
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:14,代码来源:DefaultRealm.java

示例8: changePassword

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
/**
 * 修改密码。新用户oldPassword传入null
 * 
 * @param entity
 * @param oldPassword
 * @param newPassword
 * @return
 */
public User changePassword(User user, String oldPassword, String newPassword) {
	Assert.notNull(user.getUsername());
	Assert.notNull(newPassword);

	Object salt = new SimpleByteSource(user.getUsername());

	if (!user.isNew()) {
		Assert.isTrue(databaseRealm.doCredentialsMatch(oldPassword, new SimpleByteSource(user.getUsername()), user.getPassword()));
	}

	user.setPassword(databaseRealm.hashProvidedCredentials(newPassword, salt).toString());
	return user;
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:22,代码来源:UserService.java

示例9: doGetAuthenticationInfo

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
@Override
protected SaltedAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    String principal = (String) token.getPrincipal();

    return new SimpleAuthenticationInfo(principal, userService.getPassword(principal),
            new SimpleByteSource(Base64.decode(userService.getPasswordSalt(principal))), "JdbcSaltedRealm");
}
 
开发者ID:Zabrimus,项目名称:vdr-jonglisto,代码行数:8,代码来源:JdbcSaltedRealm.java

示例10: createPasswordService

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
/**
 * Creates the password service without registering it.
 * 
 * @param repo  the component repository, only used to register secondary items like lifecycle, not null
 * @return the password service, not null
 */
protected PasswordService createPasswordService(ComponentRepository repo) {
  DefaultHashService hashService = new DefaultHashService();
  hashService.setHashAlgorithmName(getHashAlgorithm());
  hashService.setHashIterations(getHashIterations());
  hashService.setGeneratePublicSalt(true);
  hashService.setPrivateSalt(new SimpleByteSource(getPrivateSalt()));
  DefaultPasswordService pwService = new DefaultPasswordService();
  pwService.setHashService(hashService);
  return pwService;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:ShiroSecurityComponentFactory.java

示例11: doGetAuthenticationInfo

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken authenticationToken) throws AuthenticationException {

    // DEBUG: Print Security configuration
    logger.debug("!!! CredentialsMatcher: {}", this.getCredentialsMatcher().toString());
    logger.debug("!!! HashAlgorithmName: {}", ((HashedCredentialsMatcher) getCredentialsMatcher()).getHashAlgorithmName());
    logger.debug("!!! HashIterations: {}", ((HashedCredentialsMatcher) getCredentialsMatcher()).getHashIterations());
    logger.debug("!!! StoredCredentialsHexEncoded: {}", ((HashedCredentialsMatcher) getCredentialsMatcher()).isStoredCredentialsHexEncoded());

    final UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) authenticationToken;
    if (usernamePasswordToken.getUsername() == null || usernamePasswordToken.getUsername().isEmpty()) {
        throw new UnknownAccountException("Authentication failed");
    }

    // Find the thing that stores your user's credentials. This may be the
    // same or different than
    // the thing that stores the roles.
    final UserProfile principal = lookup(UserManagementService.class).findUserByLogin(usernamePasswordToken.getUsername());
    if (principal == null) {
        logger.info("Principal not found for user with username: {}", usernamePasswordToken.getUsername());
        return null;
    } else if (principal.isBlocked()) {
        logger.info("Access for user with username {} is forbidden", usernamePasswordToken.getUsername());
        throw new LockedAccountException();
    }

    logger.info("Principal found for authenticating user with username: {}", usernamePasswordToken.getUsername());

    final ByteSource hashedCredentials = new SimpleByteSource(Base64.decode(principal.getPassword()));
    final ByteSource credentialsSalt = new SimpleByteSource(Base64.decode(principal.getPasswordSalt()));
    final SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            principal.getLogin(),
            hashedCredentials,
            credentialsSalt,
            getName());
    return authenticationInfo;
}
 
开发者ID:ExtaSoft,项目名称:extacrm,代码行数:39,代码来源:UserRealm.java

示例12: hashPassword

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
@VisibleForTesting
String hashPassword(final String plainPassword, final String userSalt) {
	final SimpleByteSource totalSalt = SaltTool.getFullSalt(userSalt);
	final int iterations = SecurityModule.NUMBER_OF_HASH_ITERATIONS;
	Sha256Hash hash = new Sha256Hash(plainPassword, totalSalt, iterations);
	return hash.toHex();
}
 
开发者ID:devhub-tud,项目名称:devhub-prototype,代码行数:8,代码来源:UserFactory.java

示例13: getCredentialsSalt

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
@Override
public ByteSource getCredentialsSalt() {
	return new SimpleByteSource(Base64.decode(salt));
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:5,代码来源:SaltedAuthInfo.java

示例14: getFullSalt

import org.apache.shiro.util.SimpleByteSource; //导入依赖的package包/类
static ByteSource getFullSalt(User user) {
	return new SimpleByteSource(user.getSalt() + APPLICATION_SALT);
}
 
开发者ID:devhub-tud,项目名称:devhub-prototype,代码行数:4,代码来源:SaltTool.java


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