Java Code Examples for io.jsonwebtoken.lang.Collections#isEmpty()

The following examples show how to use io.jsonwebtoken.lang.Collections#isEmpty() . 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: HmacRealm.java    From jsets-shiro-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
/**
 * 授权
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
	String payload = (String) principals.getPrimaryPrincipal();
	String appId = CommonUtils.hmacPayload(payload);
	if (Objects.isNull(appId))
		return null;
	SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
	Set<String> roles = this.accountProvider.loadRoles(appId);
	Set<String> permissions = this.accountProvider.loadPermissions(appId);
	if (!Collections.isEmpty(roles))
		info.setRoles(roles);
	if (!Collections.isEmpty(permissions))
		info.setStringPermissions(permissions);
	return info;
}
 
Example 2
Source File: TrimmedStringArrayDeserializer.java    From Alpine with Apache License 2.0 6 votes vote down vote up
@Override
public String[] deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
    final List<String> list = new ArrayList<>();
    final JsonNode node = jsonParser.readValueAsTree();
    if (node.isArray()) {
        final Iterator elements = node.elements();
        while (elements.hasNext()) {
            final JsonNode childNode = (JsonNode) elements.next();
            final String value = StringUtils.trimToNull(childNode.asText());
            if (value != null) {
                list.add(value);
            }
        }
    }
    if (Collections.isEmpty(list)) {
        return null;
    } else {
        return list.toArray(new String[list.size()]);
    }
}
 
Example 3
Source File: RoleDao.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
public List<GrantedAuthority> getRolesForUser(String user) {
  List<GrantedAuthority> authorities = new ArrayList<>();
  if (authPropsConfig.isFileAuthorization()) {
      List<String > roles = simpleRolesMap.get(user);
      if (!Collections.isEmpty(roles)) {
        for (String role : roles) {
          String roleName = "ROLE_" + role;
          logger.debug("Found role '{}' for user '{}'", roleName, user);
          authorities.add(createRoleWithReadPrivilage(roleName));
        }
      } else {
        logger.warn("Not found roles for user '{}'", user);
      }
    return authorities;
  } else {
    return createDefaultAuthorities();
  }
}
 
Example 4
Source File: ForwardedUserFilter.java    From juiser with Apache License 2.0 6 votes vote down vote up
public ForwardedUserFilter(String headerName,
                           Function<HttpServletRequest, User> userFactory,
                           Collection<String> requestAttributeNames) {
    Assert.hasText(headerName, "headerName cannot be null or empty.");
    Assert.notNull(userFactory, "userFactory function cannot be null.");

    this.headerName = headerName;
    this.userFactory = userFactory;

    //always ensure that the fully qualified interface name is accessible:
    LinkedHashSet<String> set = new LinkedHashSet<>();
    set.add(User.class.getName());
    if (!Collections.isEmpty(requestAttributeNames)) {
        set.addAll(requestAttributeNames);
    }
    this.requestAttributeNames = set;
}
 
Example 5
Source File: PoliciesValidator.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
public boolean validate(EndpointPolicy policy) {
    boolean hasId = Optional.ofNullable(policy.getId()).isPresent();
    boolean hasEndpoints = Optional.ofNullable(policy.getEndpoints()).isPresent();
    boolean hasEmailNotificationTemplate = Optional.ofNullable(policy.getEmailNotificationTemplate()).isPresent();
    boolean valid = !hasId && hasEndpoints && hasEmailNotificationTemplate;
    if (hasEndpoints) {
        if (Collections.isEmpty(policy.getEndpoints())) {
            valid = false;
        } else {
            for (String e: policy.getEndpoints()) {
                if (StringUtils.isBlank(e) || !e.startsWith("/")) {
                    valid = false;
                    log.warn(ENDPOINT_REJECTED_MESSAGE, policy.toString());
                    break;
                }
            }
        }
    }
    if (hasEmailNotificationTemplate) {
        if (!policy.getEmailNotificationTemplate().isValid()) {
            valid = false;
            log.warn(EMAIL_NOTIFICATION_TEMPLATE_REJECTED_MESSAGE, policy.toString());
        }
    }
    if (valid == false) {
        log.warn(REQUIRED_PROPERTIES_REJECTED_MESSAGE, policy.toString());
    }
    return valid;
}
 
Example 6
Source File: AlpineQueryManager.java    From Alpine with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the most recent log entry for the specified Subscriber.
 * If no log entries are found, this method will return null.
 * @param clazz The LoggableSubscriber class to query on
 * @return a EventServiceLog
 * @since 1.0.0
 */
@SuppressWarnings("unchecked")
public EventServiceLog getLatestEventServiceLog(final Class<LoggableSubscriber> clazz) {
    final Query query = pm.newQuery(EventServiceLog.class, "eventClass == :clazz");
    query.setOrdering("completed desc");
    final List<EventServiceLog> result = (List<EventServiceLog>) query.execute(clazz);
    return Collections.isEmpty(result) ? null : result.get(0);
}
 
Example 7
Source File: DefaultJwtBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JwtBuilder setHeaderParams(Map<String, Object> params) {
    if (!Collections.isEmpty(params)) {

        Header header = ensureHeader();

        for (Map.Entry<String, Object> entry : params.entrySet()) {
            header.put(entry.getKey(), entry.getValue());
        }
    }
    return this;
}
 
Example 8
Source File: UsernamePasswordRealm.java    From jsets-shiro-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * 授权
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
	
	String account = (String) principals.getPrimaryPrincipal();
	if(Objects.isNull(account)||!Strings.isNullOrEmpty(CommonUtils.jwtPayload(account))
							  ||!Strings.isNullOrEmpty(CommonUtils.hmacPayload(account))) 
		return null;
	SimpleAuthorizationInfo info =  new SimpleAuthorizationInfo();
	Set<String> roles = this.accountProvider.loadRoles(account);
	Set<String> permissions = this.accountProvider.loadPermissions(account);
	if(!Collections.isEmpty(roles)) info.setRoles(roles);
	if(!Collections.isEmpty(permissions)) info.setStringPermissions(permissions);
       return info;  
}
 
Example 9
Source File: UsernameRealm.java    From jsets-shiro-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * 授权
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {

	String account = (String) principals.getPrimaryPrincipal();
	if(Objects.isNull(account)||!Strings.isNullOrEmpty(CommonUtils.jwtPayload(account))
							  ||!Strings.isNullOrEmpty(CommonUtils.hmacPayload(account))) 
		return null;
	SimpleAuthorizationInfo info =  new SimpleAuthorizationInfo();
	Set<String> roles = this.accountProvider.loadRoles(account);
	Set<String> permissions = this.accountProvider.loadPermissions(account);
	if(!Collections.isEmpty(roles)) info.setRoles(roles);
	if(!Collections.isEmpty(permissions)) info.setStringPermissions(permissions);
       return info;  
}
 
Example 10
Source File: AlpineQueryManager.java    From Alpine with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an API key.
 * @param key the key to return
 * @return an ApiKey
 * @since 1.0.0
 */
@SuppressWarnings("unchecked")
public ApiKey getApiKey(final String key) {
    final Query query = pm.newQuery(ApiKey.class, "key == :key");
    final List<ApiKey> result = (List<ApiKey>) query.execute(key);
    return Collections.isEmpty(result) ? null : result.get(0);
}
 
Example 11
Source File: JwtRealm.java    From jsets-shiro-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/** 
    * 授权 
    */  
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
	
	String payload = (String) principals.getPrimaryPrincipal();
	String jwtPayload = CommonUtils.jwtPayload(payload);
	if(Objects.isNull(jwtPayload)) return null;
       Map<String, Object> payloadMap = CommonUtils.readJSON(jwtPayload,Map.class);
   	Set<String> roles = CommonUtils.split((String)payloadMap.get("roles"));
   	Set<String> permissions = CommonUtils.split((String)payloadMap.get("perms"));
   	SimpleAuthorizationInfo info =  new SimpleAuthorizationInfo();
	if(!Collections.isEmpty(roles)) info.setRoles(roles);
	if(!Collections.isEmpty(permissions)) info.setStringPermissions(permissions);
	return info;
}
 
Example 12
Source File: EmailNotificationTemplate.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
private static boolean areRecipientsValid(List<String> recipients) {
    boolean result = true;
    if (!Collections.isEmpty(recipients)) {
        for (String recipient: recipients) {
            if (!EmailValidator.isValid(recipient)) {
                result = false;
                break;
            }
        }
    }
    return result;
}
 
Example 13
Source File: PoliciesValidator.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
public boolean validate(QueryPolicy policy) {
    boolean hasId = Optional.ofNullable(policy.getId()).isPresent();
    boolean hasQueries = Optional.ofNullable(policy.getQueries()).isPresent();
    boolean hasEmailNotificationTemplate = Optional.ofNullable(policy.getEmailNotificationTemplate()).isPresent();
    boolean valid = !hasId && hasQueries && hasEmailNotificationTemplate;
    if (hasQueries) {
        if (Collections.isEmpty(policy.getQueries())) {
            valid = false;
        } else {
            for (Query q: policy.getQueries()) {
                if (!q.isValid()) {
                    valid = false;
                    log.warn(QUERY_REJECTED_MESSAGE, policy.toString());
                    break;
                }
            }
        }
    }
    if (hasEmailNotificationTemplate) {
        if (!policy.getEmailNotificationTemplate().isValid()) {
            valid = false;
            log.warn(EMAIL_NOTIFICATION_TEMPLATE_REJECTED_MESSAGE, policy.toString());
        }
    }
    if (valid == false) {
        log.warn(REQUIRED_PROPERTIES_REJECTED_MESSAGE, policy.toString());
    }
    return valid;
}
 
Example 14
Source File: DefaultJwtBuilder.java    From jjwt with Apache License 2.0 5 votes vote down vote up
@Override
public JwtBuilder setHeaderParams(Map<String, Object> params) {
    if (!Collections.isEmpty(params)) {

        Header header = ensureHeader();

        for (Map.Entry<String, Object> entry : params.entrySet()) {
            header.put(entry.getKey(), entry.getValue());
        }
    }
    return this;
}
 
Example 15
Source File: AlpineQueryManager.java    From Alpine with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieves an OidcUser containing the specified username. If the username
 * does not exist, returns null.
 * @param username The username to retrieve
 * @return an OidcUser
 * @since 1.8.0
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public OidcUser getOidcUser(final String username) {
    final Query query = pm.newQuery(OidcUser.class, "username == :username");
    final List<OidcUser> result = (List<OidcUser>) query.execute(username);
    return Collections.isEmpty(result) ? null : result.get(0);
}
 
Example 16
Source File: AlpineQueryManager.java    From Alpine with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an OidcGroup containing the specified name. If the name
 * does not exist, returns null.
 * @param name Name of the group to retrieve
 * @return an OidcGroup
 * @since 1.8.0
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public OidcGroup getOidcGroup(final String name) {
    final Query query = pm.newQuery(OidcGroup.class, "name == :name");
    final List<OidcGroup> result = (List<OidcGroup>) query.execute(name);
    return Collections.isEmpty(result) ? null : result.get(0);
}
 
Example 17
Source File: AlpineQueryManager.java    From Alpine with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieves an LdapUser containing the specified username. If the username
 * does not exist, returns null.
 * @param username The username to retrieve
 * @return an LdapUser
 * @since 1.0.0
 */
@SuppressWarnings("unchecked")
public LdapUser getLdapUser(final String username) {
    final Query query = pm.newQuery(LdapUser.class, "username == :username");
    final List<LdapUser> result = (List<LdapUser>) query.execute(username);
    return Collections.isEmpty(result) ? null : result.get(0);
}
 
Example 18
Source File: AbstractAlpineQueryManager.java    From Alpine with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieves an object by its UUID.
 * @param <T> A type parameter. This type will be returned
 * @param clazz the persistence class to retrive the ID for
 * @param uuid the uuid of the object to retrieve
 * @return an object of the specified type
 * @since 1.0.0
 */
@SuppressWarnings("unchecked")
public <T> T getObjectByUuid(Class<T> clazz, UUID uuid) {
    final Query query = pm.newQuery(clazz, "uuid == :uuid");
    final List<T> result = (List<T>) query.execute(uuid);
    return Collections.isEmpty(result) ? null : result.get(0);
}
 
Example 19
Source File: AlpineQueryManager.java    From Alpine with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieves a MappedOidcGroup object for the specified Team and OIDC group.
 * @param team a Team object
 * @param group a OidcGroup object
 * @return a MappedOidcGroup if found, or null if no mapping exists
 * @since 1.8.0
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public MappedOidcGroup getMappedOidcGroup(final Team team, final OidcGroup group) {
    final Query query = pm.newQuery(MappedOidcGroup.class, "team == :team && group == :group");
    final List<MappedOidcGroup> result = (List<MappedOidcGroup>) query.execute(team, group);
    return Collections.isEmpty(result) ? null : result.get(0);
}
 
Example 20
Source File: AlpineQueryManager.java    From Alpine with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a ConfigProperty with the specified groupName and propertyName.
 * @param groupName the group name of the config property
 * @param propertyName the name of the property
 * @return a ConfigProperty object
 * @since 1.3.0
 */
@SuppressWarnings("unchecked")
public ConfigProperty getConfigProperty(final String groupName, final String propertyName) {
    final Query query = pm.newQuery(ConfigProperty.class, "groupName == :groupName && propertyName == :propertyName");
    final List<ConfigProperty> result = (List<ConfigProperty>) query.execute(groupName, propertyName);
    return Collections.isEmpty(result) ? null : result.get(0);
}