@Override public void init() throws Exception { super.init(); if (this.accountModelFactory == null) { this.accountModelFactory = new DefaultAccountModelFactory(); } if (this.accountStoreModelFactory == null) { this.accountStoreModelFactory = new ExternalAccountStoreModelFactory(); } if (this.errorModelFactory == null) { this.errorModelFactory = new RegisterErrorModelFactory(this.messageSource); } Assert.notNull(this.client, "client cannot be null."); Assert.notNull(this.authenticationResultSaver, "authenticationResultSaver cannot be null."); Assert.hasText(this.loginUri, "loginUri cannot be null or empty."); Assert.hasText(this.verifyViewName, "verifyViewName cannot be null or empty."); Assert.notNull(this.preRegisterHandler, "preRegisterHandler cannot be null."); Assert.notNull(this.postRegisterHandler, "postRegisterHandler cannot be null."); Assert.notNull(this.accountModelFactory, "accountModelFactory cannot be null."); Assert.notNull(this.accountStoreModelFactory, "accountStoreModelFactory cannot be null."); Assert.notNull(this.errorModelFactory, "errorModelFactory cannot be null."); Assert.notNull(this.accountStoreResolver, "accountStoreResolver cannot be null."); }
/** * Creates a new instance. * * @param nonceCache a cache to place used CSRF tokens. This is required to ensure the consumed * token is never used again, which is mandatory for CSRF protection. This cache <em>MUST</em> * have a TTL value equal to or greater than {@code ttlMillis}. Cache key: a unique token ID, * Cache value: the used token * @param signingKey a base64-encoded (and hopefully secure-random) cryptographic signing key used * to digitally sign the CSRF token to ensure it cannot be tampered with by HTTP clients. * @param ttlMillis the length of time in milliseconds for which a generated CSRF token is valid. * When a token is created, it cannot be used after this duration, even if it has not been * consumed yet. */ public CacheCsrfTokenRepository(Cache nonceCache, String signingKey, long ttlMillis) { Assert.notNull(nonceCache, "nonce cache cannot be null."); this.nonceCache = nonceCache; Assert.hasText(signingKey, "signingKey cannot be null or empty."); this.signingKey = signingKey; Assert.isTrue(ttlMillis > 0, "ttlMillis must be greater than zero."); this.ttlMillis = ttlMillis; }
public SpringSpaController( Controller delegate, String jsonView, List<MediaType> producesMediaTypes) { Assert.notNull(delegate, "Delegate controller cannot be null."); Assert.notEmpty(producesMediaTypes, "produced media types cannot be null or empty."); Assert.hasText(jsonView, "jsonView cannot be null or empty."); this.delegate = delegate; this.jsonView = jsonView; this.producesMediaTypes = producesMediaTypes; }
public DefaultIdSiteCallbackHandler( InternalDataStore dataStore, Application application, Object httpRequest) { Assert.notNull(dataStore, "datastore cannot be null or empty."); Assert.notNull(application, "application cannot be null."); Assert.notNull(httpRequest, "httpRequest cannot be null."); this.dataStore = dataStore; this.application = application; this.jwtResponse = getJwtResponse(httpRequest); this.nonceStore = new DefaultNonceStore(dataStore.getCacheResolver()); }
protected DefaultCriteria(O options) { Assert.notNull(options, "options argument cannot be null."); Assert.isInstanceOf( Expandable.class, options, "options argument is expected to implement the " + Expandable.class.getName() + " interface."); this.options = options; this.criterionEntries = new ArrayList<Criterion>(); this.orderEntries = new ArrayList<Order>(); }
@Override public CreatePhoneRequestBuilder withResponseOptions(PhoneOptions options) throws IllegalArgumentException { Assert.notNull(options, "options can't be null."); this.options = options; return this; }
public void init() { super.init(); Assert.notNull(serverUriResolver, "serverUriResolver must be configured."); IdSiteController controller = new LogoutIdSiteController(); controller.setServerUriResolver(serverUriResolver); controller.setCallbackUri(idSiteResultUri); controller.init(); this.idSiteController = controller; }
/* @since 1.0.RC5 */ private Error constructError(Map jsonMap) { Assert.isTrue(isError(jsonMap)); Map<String, Object> errorMap = getRequiredValue(jsonMap, ERROR); Error error = new DefaultErrorBuilder((Integer) getRequiredValue(errorMap, STATUS)) .code((Integer) getRequiredValue(errorMap, "code")) .developerMessage((String) getRequiredValue(errorMap, "developerMessage")) .message((String) getRequiredValue(errorMap, "message")) .moreInfo((String) getRequiredValue(errorMap, "moreInfo")) .build(); return error; }
/** * Ensures the message used for the exception (i.e. exception.getMessage()) reports the {@code * developerMessage} returned by the Stormpath API Server. The regular Stormpath response body * {@code message} field is targeted at applicadtion end-users that could very likely be * non-technical. Since an exception should be helpful to developers, it is better to show a more * technical message. * * <p>Added as a fix for <a href="https://github.com/stormpath/stormpath-sdk-java/issues/28">Issue * #28</a>. * * @param error the response Error. Cannot be null. * @return {@code error.getDeveloperMessage()} * @since 0.9.2 */ private static String buildExceptionMessage(Error error) { Assert.notNull(error, "Error argument cannot be null."); StringBuilder sb = new StringBuilder(); sb.append("HTTP ") .append(error.getStatus()) .append(", Stormpath ") .append(error.getCode()) .append(" (") .append(error.getMoreInfo()) .append("): ") .append(error.getDeveloperMessage()); return sb.toString(); }
private String getJwtResponse(Object httpRequestObject) { String jwtResponse; if (HttpRequest.class.isAssignableFrom(httpRequestObject.getClass())) { HttpRequest httpRequest = (HttpRequest) httpRequestObject; Assert.isTrue( httpRequest.getMethod() == HttpMethod.GET, "Only Http GET method is supported."); jwtResponse = httpRequest.getParameter(JWT_RESPONSE); } else { // This must never happen, if the object request is of HttpServletRequest type the // HTTP_SERVLET_REQUEST_WRAPPER_CLASS // must be already loaded and therefore cannot be null. if (HTTP_SERVLET_REQUEST_WRAPPER_CLASS == null) { throw new RuntimeException( "DefaultHttpServletRequestWrapper not loaded error occurred while handling httpRequest of type: " + httpRequestObject.getClass().getName()); } Constructor<? extends HttpServletRequestWrapper> ctor = Classes.getConstructor(HTTP_SERVLET_REQUEST_WRAPPER_CLASS, Object.class); HttpServletRequestWrapper httpServletRequestWrapper = Classes.instantiate(ctor, httpRequestObject); HttpMethod method = HttpMethod.fromName(httpServletRequestWrapper.getMethod()); Assert.isTrue(HttpMethod.GET == method, "Only Http GET method is supported."); jwtResponse = httpServletRequestWrapper.getParameter(JWT_RESPONSE); } if (!Strings.hasText(jwtResponse)) { throw new InvalidJwtException(InvalidJwtException.JWT_REQUIRED_ERROR); } return jwtResponse; }
// since 0.9.2 private Object toMapValue( final AbstractResource resource, final String propName, Object value, boolean partialUpdate) { if (resource instanceof CustomData) { // no sanitization: CustomData resources retain their values as-is: return value; } if (value instanceof CustomData || value instanceof ProviderData || value instanceof Provider) { if (partialUpdate) { Assert.isInstanceOf(AbstractResource.class, value); AbstractResource abstractResource = (AbstractResource) value; Set<String> updatedPropertyNames = abstractResource.getUpdatedPropertyNames(); LinkedHashMap<String, Object> properties = new LinkedHashMap<String, Object>(Collections.size(updatedPropertyNames)); for (String updatedCustomPropertyName : updatedPropertyNames) { Object object = abstractResource.getProperty(updatedCustomPropertyName); properties.put(updatedCustomPropertyName, object); } value = properties; } return value; } if (value instanceof Map) { // Since defaultModel is a map, the DataStore thinks it is a Resource. This causes the code to // crash later one as Resources // do need to have an href property if (resource instanceof ModeledEmailTemplate && propName.equals("defaultModel")) { return value; } else { // if the property is a reference, don't write the entire object - just the href will do: // TODO need to change this to write the entire object because this code defeats the purpose // of entity expansion // when this code gets called (returning the reference instead of the whole object that // is returned from Stormpath) return this.referenceFactory.createReference(propName, (Map) value); } } if (value instanceof Resource) { return this.referenceFactory.createReference(propName, (Resource) value); } return value; }
public T add(Criterion criterion) { Assert.notNull(criterion, "criterion cannot be null."); this.criterionEntries.add(criterion); return (T) this; }
/** * Sorts the given list of {@code MimeType} objects by specificity. * * <p>Given two mime types: * * <ol> * <li>if either mime type has a {@linkplain MimeType#isWildcardType() wildcard type}, then the * mime type without the wildcard is ordered before the other. * <li>if the two mime types have different {@linkplain MimeType#getType() types}, then they are * considered equal and remain their current order. * <li>if either mime type has a {@linkplain MimeType#isWildcardSubtype() wildcard subtype} , * then the mime type without the wildcard is sorted before the other. * <li>if the two mime types have different {@linkplain MimeType#getSubtype() subtypes}, then * they are considered equal and remain their current order. * <li>if the two mime types have a different amount of {@linkplain * MimeType#getParameter(String) parameters}, then the mime type with the most parameters is * ordered before the other. * </ol> * * <p>For example: * * <blockquote> * * audio/basic < audio/* < */* * * </blockquote> * * <blockquote> * * audio/basic;level=1 < audio/basic * * </blockquote> * * <blockquote> * * audio/basic == text/html * * </blockquote> * * <blockquote> * * audio/basic == audio/wave * * </blockquote> * * @param mimeTypes the list of mime types to be sorted * @see <a href="http://tools.ietf.org/html/rfc7231#section-5.3.2">HTTP 1.1: Semantics and * Content, section 5.3.2</a> */ public static void sortBySpecificity(List<MimeType> mimeTypes) { Assert.notNull(mimeTypes, "'mimeTypes' must not be null"); if (mimeTypes.size() > 1) { Collections.sort(mimeTypes, SPECIFICITY_COMPARATOR); } }
public DefaultResourceConverter(ReferenceFactory referenceFactory) { Assert.notNull(referenceFactory, "referenceFactory cannot be null."); this.referenceFactory = referenceFactory; }
private int ensureOrderIndex() { int i = this.currentOrderIndex; Assert.state( i >= 0, "There is no current orderBy clause to declare as ascending or descending!"); return i; }
@Override public Map<String, Object> convert(AbstractResource resource) { Assert.notNull(resource, "resource cannot be null."); return toMap(resource, true); }
public AuthenticationResultSaver(List<Saver<AuthenticationResult>> savers) { Assert.notEmpty(savers, "At least one Saver<AuthenticationResult> must be specified."); this.savers = Collections.unmodifiableList(savers); }
/* @since 1.0.RC5 */ private boolean isError(Map jsonMap) { Assert.notNull(jsonMap, "jsonMap cannot be null."); Object error = getOptionalValue(jsonMap, ERROR); return error != null; }
public T add(Order order) { Assert.notNull(order, "order cannot be null."); this.orderEntries.add(order); this.currentOrderIndex = this.orderEntries.size() - 1; return (T) this; }
@Override public IdSiteCallbackHandler setNonceStore(NonceStore nonceStore) { Assert.notNull(nonceStore); this.nonceStore = nonceStore; return this; }
public DefaultCreatePhoneRequestBuilder(Phone phone) { Assert.notNull(phone, "Phone can't be null."); this.phone = phone; }