Example usage for org.springframework.util Assert isInstanceOf

List of usage examples for org.springframework.util Assert isInstanceOf

Introduction

In this page you can find the example usage for org.springframework.util Assert isInstanceOf.

Prototype

public static void isInstanceOf(Class<?> type, @Nullable Object obj, Supplier<String> messageSupplier) 

Source Link

Document

Assert that the provided object is an instance of the provided class.

Usage

From source file:biz.c24.io.spring.oxm.C24Marshaller.java

public Object unmarshal(Source source) throws IOException, XmlMappingException {

    Assert.isInstanceOf(StreamSource.class, source, UNSUPPORTED_SOURCE);

    StreamSource streamSource = (StreamSource) source;
    XMLSource xmlSource = getXmlSourceFrom(streamSource);

    ComplexDataObject result = xmlSource.readObject(model.getRootElement());
    return C24Utils.potentiallyUnwrapDocumentRoot(result);
}

From source file:org.jtalks.common.security.acl.JtalksMutableAcService.java

/**
 * {@inheritDoc}/*from   ww w  . j  av  a  2s.c o  m*/
 */
@Override
public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException {
    Assert.notNull(objectIdentity, "Object Identity required");

    // Check this object identity hasn't already been persisted
    if (retrieveObjectIdentityPrimaryKey(objectIdentity) != null) {
        throw new AlreadyExistsException("Object identity '" + objectIdentity + "' already exists");
    }

    // Need to retrieve the current principal, in order to know who "owns" this ACL (can be changed later on)
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    Sid sid = sidFactory.createPrincipal(auth);
    createObjectIdentity(objectIdentity, sid);

    // Retrieve the ACL via superclass (ensures cache registration, proper retrieval etc)
    Acl acl = readAclById(objectIdentity);
    Assert.isInstanceOf(MutableAcl.class, acl, "MutableAcl should be been returned");

    return (MutableAcl) acl;
}

From source file:org.brekka.phalanx.webservices.SoapExceptionResolver.java

@Override
protected final boolean resolveExceptionInternal(final MessageContext messageContext, final Object endpoint,
        final Exception ex) {
    Assert.isInstanceOf(SoapMessage.class, messageContext.getResponse(),
            "SimpleSoapExceptionResolver requires a SoapMessage");

    SoapMessage response = (SoapMessage) messageContext.getResponse();
    SoapBody soapBody = response.getSoapBody();

    String message = determineMessage(ex);
    SoapFault soapFault;/*from  ww w.  j  a  v a  2  s. c  o m*/
    if (isServerFault(ex)) {
        soapFault = soapBody.addServerOrReceiverFault(message, Locale.ENGLISH);
    } else {
        soapFault = soapBody.addClientOrSenderFault(message, Locale.ENGLISH);
    }

    resolveDetail(messageContext, ex, soapFault);
    log.error(String.format("Error while invoking SOAP operation"), ex);
    return true;
}

From source file:org.codehaus.groovy.grails.plugins.searchable.compass.search.DefaultSearchableCompassQueryBuilder.java

public CompassQuery buildQuery(GrailsApplication grailsApplication, CompassSession compassSession, Map options,
        Object query) {//w  w w  . j a v a  2 s  .  com
    Assert.notNull(query, "query cannot be null");
    CompassQuery compassQuery;
    if (query instanceof String) {
        compassQuery = stringQueryBuilder.buildQuery(grailsApplication, compassSession, options, query);
    } else {
        Assert.isInstanceOf(Closure.class, query,
                "query is neither String nor Closure: must be one of these but is ["
                        + query.getClass().getName() + "]");
        Object closureQueryBuilder = InvokerHelper.invokeConstructorOf(closureQueryBuilderClass,
                compassSession.queryBuilder());
        compassQuery = (CompassQuery) InvokerHelper.invokeMethod(closureQueryBuilder, "buildQuery", query);
    }
    return applyOptions(grailsApplication, getCompass(), compassSession, compassQuery, options);
}

From source file:grails.plugin.searchable.internal.compass.search.SearchableCompassQueryBuilderSortOptionHelper.java

public CompassQuery addSort(CompassQuery compassQuery, Map options) {
    String sort = (String) options.get("sort");
    if (sort == null) {
        return compassQuery;
    }//from  www.j a va  2  s . c o m
    Object sortProperty = getSortProperty(sort);
    CompassQuery.SortDirection direction = getSortDirection(sortProperty, options);

    if (sortProperty instanceof CompassQuery.SortImplicitType) {
        compassQuery = compassQuery.addSort((CompassQuery.SortImplicitType) sortProperty, direction);
    } else {
        Assert.isInstanceOf(String.class, sortProperty, "Expected string");
        compassQuery = compassQuery.addSort((String) sortProperty, direction);
    }

    return compassQuery;
}

From source file:gov.nih.nci.cabig.ctms.acegi.acls.dao.impl.MutableAclDaoImpl.java

public MutableAcl createAcl(ObjectIdentity oid) throws AlreadyExistsException {

    if (findAclObjectIdentityBeanByObjectIdentity(oid) != null) {
        throw new AlreadyExistsException("Object identity '" + oid + "' already exists");
    }//from w  w w  .  ja va2 s  .  c o m

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    PrincipalSid sid = new PrincipalSid(auth);

    // Create the acl_object_identity row
    createObjectIdentity(oid, sid);

    // Retrieve the ACL via superclass (ensures cache registration, proper
    // retrieval etc)
    Acl acl = readAclById(oid);
    Assert.isInstanceOf(MutableAcl.class, acl, "MutableAcl should be been returned");

    return (MutableAcl) acl;
}

From source file:fr.mby.portal.coreimpl.auth.DbPortalUserAuthenticationProvider.java

@Override
public IAuthentication authenticate(final IAuthentication authentication) throws AuthenticationException {
    Assert.notNull(authentication, "No authentication supplied !");
    Assert.isInstanceOf(PortalUserAuthentication.class, authentication,
            "IAuthentication shoud be a PortalUserAuthentication type !");

    if (authentication.isAuthenticated()) {
        throw new AuthenticationException(authentication,
                "Already authenticated IAuthentication token supplied !");
    }//from ww  w  . java  2 s  . c o  m

    final PortalUserAuthentication auth = (PortalUserAuthentication) authentication;

    IAuthentication resultingAuth = null;

    final String login = authentication.getName();
    final EntityManager portalUserEm = this.portalUserEmf.createEntityManager();
    final PortalUser portalUser = this.findPortalUserByLogin(portalUserEm, login);
    portalUserEm.close();

    if (portalUser != null) {
        // We found the user in the DB => we can authenticate him
        resultingAuth = this.performAuthentication(auth, portalUser);
    }

    if (resultingAuth == null) {
        // throw new AuthenticationException(authentication, "Unable to authenticate supplied authentication !");
    }

    return resultingAuth;
}

From source file:net.projectmonkey.spring.acl.enhancement.identity.strategy.ConfigurableObjectIdentityRetrievalStrategy.java

@Override
public ObjectIdentity getObjectIdentity(final SecureObjectMapping mapping) {
    Assert.notNull(mapping, "mapping cannot be null");

    Class<?> identityType = mapping.getSecuredClass();
    Object id = mapping.getDomainObject();
    Assert.notNull(identityType, "identity type cannot be null");
    Assert.notNull(id, "domain object cannot be null");

    if (StringUtils.hasText(identifierMethod)) {
        try {// w w  w.  ja va2 s .c o  m
            id = MethodUtil.invoke(id, identifierMethod);
        } catch (Exception e) {
            throw new IdentityUnavailableException("Could not extract identity from object " + id, e);
        }
        Assert.notNull(id, identifierMethod + "() is required to return a non-null value");
    }

    Assert.isInstanceOf(Serializable.class, id, "Getter must provide a return value of type Serializable");
    return new ObjectIdentityImpl(identityType, (Serializable) id);
}

From source file:org.openregistry.core.domain.jpa.JpaLeaveImpl.java

public void setReason(final Type type) {
    Assert.isInstanceOf(JpaRoleImpl.class, type, "Must be of class JpaTypeImpl");
    this.reason = (JpaTypeImpl) type;
}