Example usage for org.apache.shiro.util CollectionUtils asSet

List of usage examples for org.apache.shiro.util CollectionUtils asSet

Introduction

In this page you can find the example usage for org.apache.shiro.util CollectionUtils asSet.

Prototype

public static <E> Set<E> asSet(E... elements) 

Source Link

Usage

From source file:cn.ddd.core.tools.Strings.java

License:Open Source License

/**
 * Splits the {@code delimited} string (delimited by the specified
 * {@code separator} character) and returns the delimited values as a
 * {@code Set}.//w w  w  . j av a  2 s . c o m
 * <p/>
 * If either argument is {@code null}, this method returns {@code null}.
 *
 * @param delimited
 *            the string to split
 * @param separator
 *            the character that delineates individual tokens to split
 * @return the delimited values as a {@code Set}.
 * @since 1.2
 */
public static Set<String> splitToSet(String delimited, String separator) {
    if (delimited == null || separator == null) {
        return null;
    }
    String[] split = split(delimited, separator.charAt(0));
    return CollectionUtils.asSet(split);
}

From source file:com.glaf.shiro.filter.AnyRoleAuthorizationFilter.java

License:Apache License

public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
        throws IOException {

    Subject subject = getSubject(request, response);
    String[] rolesArray = (String[]) mappedValue;

    if (rolesArray == null || rolesArray.length == 0) {
        return false;
    }//ww  w.  ja  va2 s .c  o m

    Set<String> roles = CollectionUtils.asSet(rolesArray);
    boolean isAccessAllowed = false;
    for (String role : roles) {
        if (subject.hasRole(role)) {
            isAccessAllowed = true;
            break;
        }
    }

    return isAccessAllowed;
}

From source file:com.imgeeks.utils.OneRoleAuthorizationFilter.java

License:Open Source License

@Override
@SuppressWarnings({ "unchecked" })
public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
        throws IOException {

    Subject subject = getSubject(request, response);
    String[] rolesArray = (String[]) mappedValue;

    if (rolesArray == null || rolesArray.length == 0) {
        // no roles specified, so nothing to check - allow access.
        return true;
    }/*from   w  ww .  jav a 2 s .c  om*/
    boolean flag = false;
    Set<String> roles = CollectionUtils.asSet(rolesArray);
    for (String string : roles) {
        if (subject.hasRole(string)) {
            flag = true;
        }
    }
    return flag;
}

From source file:com.stormpath.shiro.realm.DefaultGroupRoleResolver.java

License:Apache License

public DefaultGroupRoleResolver() {
    this.modes = CollectionUtils.asSet(Mode.HREF);
}

From source file:graphene.security.tomcat.preaa.PreAASecurityRealm.java

License:Apache License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken authToken)
        throws AuthenticationException {

    logger.debug("doGetAuthenticationInfo " + authToken.getPrincipal());
    // return null;
    final UsernamePasswordToken upToken = (UsernamePasswordToken) authToken;
    G_User g_User = null;//www .  j  a va  2 s. c om
    SimpleAccount account = null;
    try {
        g_User = userDataAccess.getByUsername(upToken.getUsername());
        final Set<String> roleNames = CollectionUtils.asSet((String[]) null);
        account = new SimpleAccount(g_User.getUsername(), "password", getName(), roleNames, null);
    } catch (final AvroRemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (account != null) {

        if (account.isLocked()) {
            throw new LockedAccountException("Account [" + account + "] is locked.");
        }
        if (account.isCredentialsExpired()) {
            final String msg = "The credentials for account [" + account + "] are expired";
            throw new ExpiredCredentialsException(msg);
        }

    } else {
        logger.error("user was null");
    }

    return account;
}

From source file:graphene.security.tomcat.preaa.PreAASecurityRealm.java

License:Apache License

@Override
protected AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) {

    logger.debug("doGetAuthorizationInfo " + principals.asList());
    // return null;
    final Set<String> roleNames = CollectionUtils.asSet((String[]) null);
    final SimpleAccount simpleAccount = new SimpleAccount(getUsername(principals), "password", getName(),
            roleNames, null);//ww  w.ja va2s . c  om
    return simpleAccount;
}

From source file:org.atteo.moonshine.shiro.simple.AdminSimpleAccountRealm.java

License:Apache License

public void addAccount(String username, String password, boolean isAdmin, String... roles) {
    Set<String> roleNames = CollectionUtils.asSet(roles);
    Set<Permission> permissions = null;
    if (isAdmin) {
        permissions = Sets.<Permission>newHashSet(new AllPermission());
    }//from  ww w  .  ja v  a 2 s .  co m
    SimpleAccount account = new SimpleAccount(username, password, getName(), roleNames, permissions);
    add(account);
}

From source file:org.graylog2.security.realm.GraylogSimpleAccountRealm.java

License:Open Source License

public void addRootAccount(String username, String password) {
    LOG.debug("Adding root account named {}, having all permissions", username);
    add(new SimpleAccount(username, password, getName(), CollectionUtils.asSet("root"),
            CollectionUtils.<Permission>asSet(new AllPermission())));
}

From source file:org.graylog2.security.realm.RootAccountRealm.java

License:Open Source License

private void addRootAccount(String username, String password) {
    LOG.debug("Adding root account named {}, having all permissions", username);
    add(new SimpleAccount(username, password, getName(), CollectionUtils.asSet("root"),
            CollectionUtils.<Permission>asSet(new AllPermission())));
}

From source file:org.ms123.common.permission.MyRealm.java

License:Open Source License

public void addAccount(String username, String password, String... roles) {
    Set<String> roleNames = CollectionUtils.asSet(roles);
    SimpleAccount account = new SimpleAccount(username, password, getName(), roleNames, null);
    add(account);/*from   w  ww.  j  a  va2 s .c om*/
}