Java Code Examples for cn.hutool.core.util.ArrayUtil#isNotEmpty()

The following examples show how to use cn.hutool.core.util.ArrayUtil#isNotEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthorizationServerConfiguration.java    From fw-spring-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * 配置客户端一些信息
 *
 * @param clients
 * @throws Exception
 */
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    InMemoryClientDetailsServiceBuilder build = clients.inMemory();
    if (ArrayUtil.isNotEmpty(securityProperties.getOauth().getClients())) {
        for (OAuth2ClientProperties config : securityProperties.getOauth().getClients()) {
            build.withClient(config.getClientId())
                    .secret(passwordEncoder.encode(config.getClientSecret()))
                    .accessTokenValiditySeconds(config.getAccessTokenValiditySeconds())
                    .refreshTokenValiditySeconds(config.getRefreshTokenValiditySecond())
                    .authorizedGrantTypes("refresh_token", "password", "authorization_code")//OAuth2支持的验证模式
                    .redirectUris(config.getRedirectUri())
                    .autoApprove(config.getAutoApprove())//设置自动认证
                    .scopes(config.getScope());
        }
    }
}
 
Example 2
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 发送正文中有静态资源的邮件
 *
 * @param to      收件人地址
 * @param subject 邮件主题
 * @param content 邮件内容
 * @param rscPath 静态资源地址
 * @param rscId   静态资源id
 * @param cc      抄送地址
 * @throws MessagingException 邮件发送异常
 */
@Override
public void sendResourceMail(String to, String subject, String content, String rscPath, String rscId, String... cc) throws MessagingException {
    MimeMessage message = mailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);
    helper.setText(content, true);
    if (ArrayUtil.isNotEmpty(cc)) {
        helper.setCc(cc);
    }
    FileSystemResource res = new FileSystemResource(new File(rscPath));
    helper.addInline(rscId, res);

    mailSender.send(message);
}
 
Example 3
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 发送带附件的邮件
 *
 * @param to       收件人地址
 * @param subject  邮件主题
 * @param content  邮件内容
 * @param filePath 附件地址
 * @param cc       抄送地址
 * @throws MessagingException 邮件发送异常
 */
@Override
public void sendAttachmentsMail(String to, String subject, String content, String filePath, String... cc) throws MessagingException {
    MimeMessage message = mailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);
    helper.setText(content, true);
    if (ArrayUtil.isNotEmpty(cc)) {
        helper.setCc(cc);
    }
    FileSystemResource file = new FileSystemResource(new File(filePath));
    String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
    helper.addAttachment(fileName, file);

    mailSender.send(message);
}
 
Example 4
Source File: BlackUserDetailsServiceImpl.java    From black-shop with Apache License 2.0 6 votes vote down vote up
/**
 * buildUserDails 构建用户详情
 * @param result
 * @return
 */
private UserDetails buildUserDails(ResponseResult<UserInfoDTO> result) {
	if (result == null || !result.hasBody()) {
		log.error("用户信息错误或不存在!!!");
		throw new UsernameNotFoundException("用户信息不存在");
	}
	UserInfoDTO userinfo = result.getResult();
	Set<String> dbAuthsSet = new HashSet<>();

	if(ArrayUtil.isNotEmpty(userinfo.getPermissions())){
		// 获取角色
		Arrays.stream(userinfo.getRoles()).forEach(roleId -> dbAuthsSet.add("ROLE_" + roleId));
		// 获取资源
		dbAuthsSet.addAll(Arrays.asList(userinfo.getPermissions()));
	}
	Collection<? extends GrantedAuthority> authorities
			= AuthorityUtils.createAuthorityList(dbAuthsSet.toArray(new String[0]));
	SysUserDTO sysUserDTO = userinfo.getSysUser();
	return new SecurityUserDetail(sysUserDTO.getUserId(), sysUserDTO.getUsername(), "{bcrypt}" + sysUserDTO.getPassword(),
			true, true, true, true, authorities);
}
 
Example 5
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 发送正文中有静态资源的邮件
 *
 * @param to      收件人地址
 * @param subject 邮件主题
 * @param content 邮件内容
 * @param rscPath 静态资源地址
 * @param rscId   静态资源id
 * @param cc      抄送地址
 * @throws MessagingException 邮件发送异常
 */
@Override
public void sendResourceMail(String to, String subject, String content, String rscPath, String rscId, String... cc) throws MessagingException {
    MimeMessage message = mailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);
    helper.setText(content, true);
    if (ArrayUtil.isNotEmpty(cc)) {
        helper.setCc(cc);
    }
    FileSystemResource res = new FileSystemResource(new File(rscPath));
    helper.addInline(rscId, res);

    mailSender.send(message);
}
 
Example 6
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 发送带附件的邮件
 *
 * @param to       收件人地址
 * @param subject  邮件主题
 * @param content  邮件内容
 * @param filePath 附件地址
 * @param cc       抄送地址
 * @throws MessagingException 邮件发送异常
 */
@Override
public void sendAttachmentsMail(String to, String subject, String content, String filePath, String... cc) throws MessagingException {
    MimeMessage message = mailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);
    helper.setText(content, true);
    if (ArrayUtil.isNotEmpty(cc)) {
        helper.setCc(cc);
    }
    FileSystemResource file = new FileSystemResource(new File(filePath));
    String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
    helper.addAttachment(fileName, file);

    mailSender.send(message);
}
 
Example 7
Source File: CloudUserDetailsServiceImpl.java    From smaker with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 构建userdetails
 *
 * @param result 用户信息
 * @return
 */
private UserDetails getUserDetails(SmakerResult<UserInfo> result) {
	if (result == null || result.getData() == null) {
		throw new UsernameNotFoundException("用户不存在");
	}

	UserInfo info = result.getData();
	Set<String> dbAuthsSet = new HashSet<>();
	if (ArrayUtil.isNotEmpty(info.getRoles())) {
		// 获取角色
		Arrays.stream(info.getRoles()).forEach(role -> dbAuthsSet.add(SecurityConstants.ROLE + role));
		// 获取资源
		dbAuthsSet.addAll(Arrays.asList(info.getPermissions()));

	}
	Collection<? extends GrantedAuthority> authorities
		= AuthorityUtils.createAuthorityList(dbAuthsSet.toArray(new String[0]));
	SysUser user = info.getSysUser();

	// 构造security用户
	return new CloudUser(user.getUserId(), user.getDeptId(), user.getUsername(), SecurityConstants.BCRYPT + user.getPassword(),
		StrUtil.equals(user.getLockFlag(), CommonConstants.STATUS_NORMAL), true, true, true, authorities);
}
 
Example 8
Source File: AuthorizationServerConfiguration.java    From fw-spring-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * 配置客户端一些信息
 *
 * @param clients
 * @throws Exception
 */
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    InMemoryClientDetailsServiceBuilder build = clients.inMemory();
    if (ArrayUtil.isNotEmpty(securityProperties.getOauth().getClients())) {
        for (OAuth2ClientProperties config : securityProperties.getOauth().getClients()) {
            build.withClient(config.getClientId())
                    .secret(passwordEncoder.encode(config.getClientSecret()))
                    .accessTokenValiditySeconds(config.getAccessTokenValiditySeconds())
                    .refreshTokenValiditySeconds(60 * 60 * 24 * 15)
                    .authorizedGrantTypes("refresh_token", "password", "authorization_code")//OAuth2支持的验证模式
                    .redirectUris("http://www.baidu.com")
                    .scopes("all");
        }
    }
}
 
Example 9
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 发送带附件的邮件
 *
 * @param to       收件人地址
 * @param subject  邮件主题
 * @param content  邮件内容
 * @param filePath 附件地址
 * @param cc       抄送地址
 * @throws MessagingException 邮件发送异常
 */
@Override
public void sendAttachmentsMail(String to, String subject, String content, String filePath, String... cc) throws MessagingException {
    MimeMessage message = mailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);
    helper.setText(content, true);
    if (ArrayUtil.isNotEmpty(cc)) {
        helper.setCc(cc);
    }
    FileSystemResource file = new FileSystemResource(new File(filePath));
    String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
    helper.addAttachment(fileName, file);

    mailSender.send(message);
}
 
Example 10
Source File: LoginProcessSetTenantFilter.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
    try {
        DefaultSavedRequest savedRequest = (DefaultSavedRequest)request.getSession().getAttribute(SAVED_REQUEST);
        if (savedRequest != null) {
            String[] clientIds = savedRequest.getParameterValues("client_id");
            if (ArrayUtil.isNotEmpty(clientIds)) {
                //保存租户id
                TenantContextHolder.setTenant(clientIds[0]);
            }
        }
        chain.doFilter(request, response);
    } finally {
        TenantContextHolder.clear();
    }
}
 
Example 11
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 发送文本邮件
 *
 * @param to      收件人地址
 * @param subject 邮件主题
 * @param content 邮件内容
 * @param cc      抄送地址
 */
@Override
public void sendSimpleMail(String to, String subject, String content, String... cc) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    if (ArrayUtil.isNotEmpty(cc)) {
        message.setCc(cc);
    }
    mailSender.send(message);
}
 
Example 12
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 发送HTML邮件
 *
 * @param to      收件人地址
 * @param subject 邮件主题
 * @param content 邮件内容
 * @param cc      抄送地址
 * @throws MessagingException 邮件发送异常
 */
@Override
public void sendHtmlMail(String to, String subject, String content, String... cc) throws MessagingException {
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);
    helper.setText(content, true);
    if (ArrayUtil.isNotEmpty(cc)) {
        helper.setCc(cc);
    }
    mailSender.send(message);
}
 
Example 13
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 发送文本邮件
 *
 * @param to      收件人地址
 * @param subject 邮件主题
 * @param content 邮件内容
 * @param cc      抄送地址
 */
@Override
public void sendSimpleMail(String to, String subject, String content, String... cc) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    if (ArrayUtil.isNotEmpty(cc)) {
        message.setCc(cc);
    }
    mailSender.send(message);
}
 
Example 14
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 发送HTML邮件
 *
 * @param to      收件人地址
 * @param subject 邮件主题
 * @param content 邮件内容
 * @param cc      抄送地址
 * @throws MessagingException 邮件发送异常
 */
@Override
public void sendHtmlMail(String to, String subject, String content, String... cc) throws MessagingException {
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);
    helper.setText(content, true);
    if (ArrayUtil.isNotEmpty(cc)) {
        helper.setCc(cc);
    }
    mailSender.send(message);
}
 
Example 15
Source File: SearchBuilder.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 设置查询路由
 * @param routing 路由数组
 */
public SearchBuilder setRouting(String... routing) {
    if (ArrayUtil.isNotEmpty(routing)) {
        searchRequest.routing(routing);
    }
    return this;
}
 
Example 16
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 发送文本邮件
 *
 * @param to      收件人地址
 * @param subject 邮件主题
 * @param content 邮件内容
 * @param cc      抄送地址
 */
@Override
public void sendSimpleMail(String to, String subject, String content, String... cc) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    if (ArrayUtil.isNotEmpty(cc)) {
        message.setCc(cc);
    }
    mailSender.send(message);
}
 
Example 17
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 发送HTML邮件
 *
 * @param to      收件人地址
 * @param subject 邮件主题
 * @param content 邮件内容
 * @param cc      抄送地址
 * @throws MessagingException 邮件发送异常
 */
@Override
public void sendHtmlMail(String to, String subject, String content, String... cc) throws MessagingException {
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);
    helper.setText(content, true);
    if (ArrayUtil.isNotEmpty(cc)) {
        helper.setCc(cc);
    }
    mailSender.send(message);
}
 
Example 18
Source File: SearchBuilder.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 设置索引名
 * @param indices 索引名数组
 */
public SearchBuilder setIndices(String... indices) {
    if (ArrayUtil.isNotEmpty(indices)) {
        searchRequest.indices(indices);
    }
    return this;
}
 
Example 19
Source File: DbBase.java    From yue-library with Apache License 2.0 3 votes vote down vote up
/**
    * <b>绝对条件查询参数whereSql化</b>
    * <p>
    * <i>已对 NULL 值进行特殊处理(IS NULL)</i><br><br>
    * <i>已对 {@linkplain List} 类型值进行特殊处理(IN (?, ?))</i><br><br>
    * 
    * <b>结果示例:</b><br>
    * <blockquote>
    * <pre>
    * <code>WHERE 1 = 1</code><br>
    * <code>AND</code><br>
    * <code>param1 = :param1</code><br>
    * <code>AND</code><br>
    * <code>param2 IS NULL :param2</code><br>
    * <code>AND</code><br>
    * <code>param3 IN :param3</code><br>
    * <code>AND ...</code>
    * </pre>
    * </blockquote>
    * 
    * @param paramJson 参数
    * @param conditions where条件(对应paramJson key)
    * @return whereSql
    */
protected String paramToWhereSql(JSONObject paramJson, String... conditions) {
	StringBuffer whereSql = new StringBuffer();
	whereSql.append(" WHERE 1 = 1 ");
	if (ArrayUtil.isNotEmpty(conditions)) {
		for (String condition : conditions) {
			paramToWhereSql(whereSql, paramJson, condition);
		}
	}
	
	return whereSql.toString();
}
 
Example 20
Source File: CollUtil.java    From magic-starter with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 数组中是否包含元素
 *
 * @param <T>   数组元素类型
 * @param array 数组
 * @param value 被检查的元素
 * @return 是否包含
 */
public static <T> boolean contains(@Nullable T[] array, T value) {
	return ArrayUtil.isNotEmpty(array) && ArrayUtil.contains(array, value);
}