List of usage examples for org.springframework.util Assert hasLength
public static void hasLength(@Nullable String text, Supplier<String> messageSupplier)
From source file:jails.http.MediaType.java
private void checkParameters(String attribute, String value) { Assert.hasLength(attribute, "parameter attribute must not be empty"); Assert.hasLength(value, "parameter value must not be empty"); checkToken(attribute);/*from ww w. j ava 2 s .c o m*/ if (PARAM_QUALITY_FACTOR.equals(attribute)) { value = unquote(value); double d = Double.parseDouble(value); Assert.isTrue(d >= 0D && d <= 1D, "Invalid quality value \"" + value + "\": should be between 0.0 and 1.0"); } else if (PARAM_CHARSET.equals(attribute)) { value = unquote(value); Charset.forName(value); } else if (!isQuotedString(value)) { checkToken(value); } }
From source file:org.jdbcluster.privilege.PrivilegeCheckerImpl.java
/** * intersects required privileges against given privileges * //from w w w .j a v a 2 s . co m * @param serviceObject service object to check * @param serviceMethodName method name to check * @param args array of parameter * @param argTypes array of parameter class objects * @return true if the privileges are sufficient */ public boolean checkAccess(IUser user, PrivilegedService serviceObject, String serviceMethodName, Object[] args, Class[] argTypes) { Assert.notNull(serviceObject, "serviceObject may not be null"); Assert.hasLength(serviceMethodName, "serviceMethodName may not be null or \"\""); Method calledMethod = JDBClusterUtil.getMethod(serviceObject.getClass(), serviceMethodName, argTypes); return userPrivilegeIntersect(user, serviceObject, calledMethod, args); }
From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.HibernateUserRoleDao.java
public IRole getRole(String name) throws UncategorizedUserRoleDaoException { Assert.hasLength(name, Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0006_ROLE_NAME_CANNOT_BE_BLANK")); //$NON-NLS-1$ try {/*from ww w .jav a 2s . c om*/ return (CustomRole) getHibernateTemplate().get(CustomRole.class, name); } catch (DataAccessException e) { throw new UncategorizedUserRoleDaoException( Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0004_DATA_ACCESS_EXCEPTION"), e); //$NON-NLS-1$ } }
From source file:org.jdbcluster.JDBClusterUtil.java
/** * returns Filed object for Properties. Iterates over all superclasses Find * a Field with the given Field name and the given parameter types, declared * on the given class or one of its superclasses. Prefers public Field, but * will return a protected, package access, or private Field too. * <p>/*from w w w. j a v a 2 s . c om*/ * Checks <code>Class.getField</code> first, falling back to * <code>getDeclaredField</code>. * * @param propName * path to property * @param c * Class object * @return Field instance */ static public Field getField(String propName, Class clazz) { Assert.notNull(clazz, "clazz may not be null"); Assert.hasLength(propName, "obj may not be null or \"\""); Field f = null; try { f = clazz.getField(propName); } catch (SecurityException e) { throw new ConfigurationException( "cant get field for property [" + propName + "] with the specified name for " + clazz.getName(), e); } catch (NoSuchFieldException e) { return JDBClusterUtil.getDeclaredField(propName, clazz); } return f; }
From source file:org.jdbcluster.JDBClusterUtil.java
/** * returns Field object for Properties. Iterates over all superclasses Find * a Field with the given Field name and the given parameter types, declared * on the given class or one of its superclasses. Will return a protected, * package access, or private Field too. * <p>// w w w.j a va 2 s.c o m * Checks <code>getDeclaredField</code>. * * @param propName * path to property * @param c * Class object * @return Field instance */ static public Field getDeclaredField(String propName, Class clazz) { Assert.notNull(clazz, "clazz may not be null"); Assert.hasLength(propName, "obj may not be null or \"\""); Field f = null; try { f = clazz.getDeclaredField(propName); } catch (SecurityException e) { throw new ConfigurationException( "cant get field for property [" + propName + "] with the specified name for " + clazz.getName(), e); } catch (NoSuchFieldException e) { if (clazz.getSuperclass() != null) { return JDBClusterUtil.getDeclaredField(propName, clazz.getSuperclass()); } throw new ConfigurationException("cant get field for property [" + propName + "] with the specified name for " + clazz.getName(), e); } return f; }
From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.HibernateUserRoleDao.java
/** * This method is more complex because this is the inverse end of a bidirectional many-to-many relationship. See * Hibernate documentation section 6.3.2. Bidirectional associations. Basically, this means that the users set of this * role must be managed manually./*from w ww . ja v a 2s. co m*/ */ @SuppressWarnings("unchecked") public void updateRole(IRole roleToUpdate) throws NotFoundException, UncategorizedUserRoleDaoException { Assert.notNull(roleToUpdate, Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0005_ROLE_CANNOT_BE_NULL")); //$NON-NLS-1$ Assert.hasLength(roleToUpdate.getName(), Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0006_ROLE_NAME_CANNOT_BE_BLANK")); //$NON-NLS-1$ IRole originalRole = getRole(roleToUpdate.getName()); // make a copy of originalRole's users since the merge call below will change the users Set<IUser> originalRoleUsers = new HashSet<IUser>(originalRole.getUsers()); if (originalRole != null) { try { getHibernateTemplate().update(getHibernateTemplate().merge(roleToUpdate)); } catch (DataAccessException e) { throw new UncategorizedUserRoleDaoException( Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0004_DATA_ACCESS_EXCEPTION"), //$NON-NLS-1$ e); } } else { throw new NotFoundException(roleToUpdate.getName()); } // manually manage users set // use relative complement (aka set-theoretic difference, aka subtraction) to get the users to add and users to // remove Set<IUser> usersToAdd = new HashSet<IUser>( CollectionUtils.subtract(roleToUpdate.getUsers(), originalRoleUsers)); Set<IUser> usersToRemove = new HashSet<IUser>( CollectionUtils.subtract(originalRoleUsers, roleToUpdate.getUsers())); for (IUser user : usersToAdd) { addUser(roleToUpdate, user.getUsername()); } for (IUser user : usersToRemove) { removeUser(roleToUpdate, user.getUsername()); } }
From source file:org.jdbcluster.domain.DomainCheckerImpl.java
/** * IMPLEMENTATION calculates set of valid domain values (master or slave) * //w ww. ja v a 2 s . c o m * @param cluster Cluster object to use * @param propPath path to the master or slave property * @return ValidDomainEntries<String> with the valid domain values */ public ValidDomainEntries<String> getValidDomainEntries(ICluster cluster, String propPath) { Assert.notNull(cluster, "Cluster may not be null"); Assert.hasLength(propPath, "propPath may not be null"); if (logger.isDebugEnabled()) logger.debug("getValidDomainEntries for Cluster [" + cluster.getClass().getName() + "]" + " and property path [" + propPath + "]"); String masterDomainId; String masterValue; String slaveDomainId; Field fMaster; Field fSlave; fSlave = JDBClusterUtil.getField(propPath, cluster); DomainDependancy dd = fSlave.getAnnotation(DomainDependancy.class); if (dd == null) { Domain d = fSlave.getAnnotation(Domain.class); if (d == null) throw new ConfigurationException( "no annotation @DomainDependancy or @Domain found on: " + propPath); if (logger.isDebugEnabled()) logger.debug("getValidDomainEntries doing rightsIntersection for domain id[" + d.domainId() + "]" + " and Field [" + fSlave.getName() + "]"); return rightsIntersection(cluster.getUser(), getPossibleDomainEntries(d.domainId()), d.domainId(), fSlave); } slaveDomainId = dd.domainId(); String propMasterPath = dd.dependsFromProperty(); fMaster = JDBClusterUtil.getField(propMasterPath, cluster); masterDomainId = getDomainIdFromField(fMaster, false); masterValue = (String) JDBClusterUtil.invokeGetPropertyMethod(dd.dependsFromProperty(), cluster); if (!fSlave.isAnnotationPresent(AddDomainDependancy.class)) { if (logger.isDebugEnabled()) logger.debug("getValidDomainEntries doing rightsIntersection for master domain id[" + masterDomainId + "]" + " and masterValue [" + masterValue + "]" + " and slaveDomainId [" + slaveDomainId + "] and Field [" + fSlave.getName() + "]"); return rightsIntersection(cluster.getUser(), getValidDomainEntries(masterDomainId, masterValue, slaveDomainId), slaveDomainId, fSlave); } AddDomainDependancy aDD = fSlave.getAnnotation(AddDomainDependancy.class); String[] addDomIdArr = new String[aDD.addDepFromProp().length]; String[] addDomValArr = new String[aDD.addDepFromProp().length]; for (int i = 0; i < aDD.addDepFromProp().length; i++) { Field faddMaster = JDBClusterUtil.getField(aDD.addDepFromProp()[i], cluster); String addMasterDomainId = getDomainIdFromField(faddMaster, false); addDomIdArr[i] = addMasterDomainId; addDomValArr[i] = (String) JDBClusterUtil.invokeGetPropertyMethod(aDD.addDepFromProp()[i], cluster); } if (logger.isDebugEnabled()) logger.debug("getValidDomainEntries (additional master) doing rightsIntersection for master domain id[" + masterDomainId + "]" + " and masterValue [" + masterValue + "]" + " and slaveDomainId [" + slaveDomainId + "] and Field [" + fSlave.getName() + "]"); return rightsIntersection(cluster.getUser(), getValidDomainEntries(masterDomainId, masterValue, slaveDomainId, addDomIdArr, addDomValArr), slaveDomainId, fSlave); }
From source file:org.jdbcluster.privilege.PrivilegeCheckerImpl.java
/** * intersects a specific domain value with the needed rights for this value * /*from w w w . j a v a 2 s .c o m*/ * @param domainId configured domain id * @param value the value of the domain * @return true if the user rights are sufficient */ public boolean userPrivilegeIntersectDomain(IUser user, String domainId, String value) { Assert.hasLength(domainId, "domainId may not be null or \"\""); DomainChecker dc = DomainCheckerImpl.getInstance(); DomainPrivilegeList dpl; try { dpl = (DomainPrivilegeList) dc.getDomainListInstance(domainId); } catch (ClassCastException e) { throw new ConfigurationException( "[" + domainId + "] must be a privileged domain and needs a implemented DomainPrivilegeList Interface", e); } Set<String> neededRights = dpl.getDomainEntryPivilegeList(domainId, value); return userPrivilegeIntersect(user, neededRights); }
From source file:org.codhaus.groovy.grails.validation.ext.ConstrainedPropertyGunn.java
public static void removeConstraint(String name, Class<?> constraintClass) { Assert.hasLength(name, "Argument [name] cannot be null"); List<Object> objects = getOrInitializeConstraint(name); objects.remove(constraintClass);//from w ww. j a va 2 s. com List<Object> toRemove = new ArrayList<Object>(); for (Object object : objects) { if (constraintClass.isInstance(object)) { toRemove.add(object); } } objects.removeAll(toRemove); }
From source file:org.codhaus.groovy.grails.validation.ext.ConstrainedPropertyGunn.java
public static void removeConstraint(String name) { Assert.hasLength(name, "Argument [name] cannot be null"); List<Object> objects = getOrInitializeConstraint(name); objects.clear();//ww w . java 2 s.c o m }