/** * Return a potentially adapted variant of this {@link ResourcePropertySource}, * overriding the previously given name (if any) with the original resource name * (equivalent to the name generated by the name-less constructor variants). * @since 4.1 */ public ResourcePropertySource withResourceName() { if (this.resourceName == null) { return this; } return new ResourcePropertySource(this.resourceName, null, this.source); }
/** * Create a PropertySource based on Properties loaded from the given resource. * The name of the PropertySource will be generated based on the * {@link Resource#getDescription() description} of the given resource. */ public ResourcePropertySource(Resource resource) throws IOException { super(getNameForResource(resource), PropertiesLoaderUtils.loadProperties(new EncodedResource(resource))); this.resourceName = null; }
if (existing != null) { PropertySource<?> newSource = (propertySource instanceof ResourcePropertySource ? ((ResourcePropertySource) propertySource).withResourceName() : propertySource); if (existing instanceof CompositePropertySource) { ((CompositePropertySource) existing).addFirstPropertySource(newSource); existing = ((ResourcePropertySource) existing).withResourceName();
public static void main(String[] args) { // 调用工具类 PropertySourceUtils 获取 ResourcePropertySource ResourcePropertySource propertySource = PropertySourceUtils.getResourcePropertySource( "https://raw.githubusercontent.com/mercyblitz/tmp/master/remote.properties"); // 输出 Properties 内容 Stream.of(propertySource.getPropertyNames()) // 将 String 转化为 Stream 对象 .map(name -> name + " = " + propertySource.getProperty(name)) // 将 key 转化为 key = value 的形式 .forEach(System.out::println); } }
@RequestMapping(value="/force_password_change", method = POST) public String handleForcePasswordChange(Model model, @RequestParam("password") String password, @RequestParam("password_confirmation") String passwordConfirmation, HttpServletResponse response) throws IOException { UaaAuthentication authentication = ((UaaAuthentication)SecurityContextHolder.getContext().getAuthentication()); UaaPrincipal principal = authentication.getPrincipal(); String email = principal.getEmail(); PasswordConfirmationValidation validation = new PasswordConfirmationValidation(email, password, passwordConfirmation); if(!validation.valid()) { return handleUnprocessableEntity(model, response, email, resourcePropertySource.getProperty("force_password_change.form_error").toString()); } logger.debug("Processing handleForcePasswordChange for user: "+ email); try { resetPasswordService.resetUserPassword(principal.getId(), password); } catch(InvalidPasswordException exception) { return handleUnprocessableEntity(model, response, email, exception.getMessagesAsOneString()); } logger.debug(String.format("Successful password change for username:%s in zone:%s ",principal.getName(), IdentityZoneHolder.get().getId())); authentication.setRequiresPasswordChange(false); authentication.setAuthenticatedTime(System.currentTimeMillis()); return "redirect:/force_password_change_completed"; }
@Override public void resetUserPassword(String userId, String password) { if (scimUserProvisioning.checkPasswordMatches(userId, password, IdentityZoneHolder.get().getId())) { throw new InvalidPasswordException(resourcePropertySource.getProperty("force_password_change.same_as_old").toString(), UNPROCESSABLE_ENTITY); } passwordValidator.validate(password); ScimUser user = scimUserProvisioning.retrieve(userId, IdentityZoneHolder.get().getId()); UaaUser uaaUser = getUaaUser(user); Authentication authentication = constructAuthentication(uaaUser); updatePasswordAndPublishEvent(scimUserProvisioning, uaaUser, authentication, password); }
@Override public PropertySource<?> createPropertySource(@Nullable String name, EncodedResource resource) throws IOException { return (name != null ? new ResourcePropertySource(name, resource) : new ResourcePropertySource(resource)); }
/** * Create a PropertySource having the given name based on Properties * loaded from the given encoded resource. */ public ResourcePropertySource(String name, EncodedResource resource) throws IOException { super(name, PropertiesLoaderUtils.loadProperties(resource)); this.resourceName = getNameForResource(resource.getResource()); }
if (existing != null) { PropertySource<?> newSource = (propertySource instanceof ResourcePropertySource ? ((ResourcePropertySource) propertySource).withResourceName() : propertySource); if (existing instanceof CompositePropertySource) { ((CompositePropertySource) existing).addFirstPropertySource(newSource); existing = ((ResourcePropertySource) existing).withResourceName();
@Test public void testPasswordAndConfirmAreDifferent() throws Exception { setAuthentication(); when(resourcePropertySource.getProperty("force_password_change.form_error")).thenReturn("Passwords must match and not be empty."); mockMvc.perform( post("/force_password_change") .param("password","pwd") .param("password_confirmation", "nopwd")) .andExpect(status().isUnprocessableEntity()); }
/** * Return a potentially adapted variant of this {@link ResourcePropertySource}, * overriding the previously given name (if any) with the original resource name * (equivalent to the name generated by the name-less constructor variants). * @since 4.1 */ public ResourcePropertySource withResourceName() { if (this.resourceName == null) { return this; } return new ResourcePropertySource(this.resourceName, null, this.source); }
/** * Create a PropertySource based on Properties loaded from the given resource. * The name of the PropertySource will be generated based on the * {@link Resource#getDescription() description} of the given resource. */ public ResourcePropertySource(EncodedResource resource) throws IOException { super(getNameForResource(resource.getResource()), PropertiesLoaderUtils.loadProperties(resource)); this.resourceName = null; }
if (existing != null) { PropertySource<?> newSource = (propertySource instanceof ResourcePropertySource ? ((ResourcePropertySource) propertySource).withResourceName() : propertySource); if (existing instanceof CompositePropertySource) { ((CompositePropertySource) existing).addFirstPropertySource(newSource); existing = ((ResourcePropertySource) existing).withResourceName();
/** * Return a potentially adapted variant of this {@link ResourcePropertySource}, * overriding the previously given (or derived) name with the specified name. * @since 4.0.4 */ public ResourcePropertySource withName(String name) { if (this.name.equals(name)) { return this; } // Store the original resource name if necessary... if (this.resourceName != null) { if (this.resourceName.equals(name)) { return new ResourcePropertySource(this.resourceName, null, this.source); } else { return new ResourcePropertySource(name, this.resourceName, this.source); } } else { // Current name is resource name -> preserve it in the extra field... return new ResourcePropertySource(name, this.name, this.source); } }
/** * Create a PropertySource having the given name based on Properties * loaded from the given encoded resource. */ public ResourcePropertySource(String name, Resource resource) throws IOException { super(name, PropertiesLoaderUtils.loadProperties(new EncodedResource(resource))); this.resourceName = getNameForResource(resource); }
@Override public PropertySource<?> createPropertySource(@Nullable String name, EncodedResource resource) throws IOException { return (name != null ? new ResourcePropertySource(name, resource) : new ResourcePropertySource(resource)); }
/** * Create a PropertySource based on Properties loaded from the given resource. * The name of the PropertySource will be generated based on the * {@link Resource#getDescription() description} of the given resource. */ public ResourcePropertySource(Resource resource) throws IOException { super(getNameForResource(resource), PropertiesLoaderUtils.loadProperties(new EncodedResource(resource))); this.resourceName = null; }
/** * Return a potentially adapted variant of this {@link ResourcePropertySource}, * overriding the previously given (or derived) name with the specified name. * @since 4.0.4 */ public ResourcePropertySource withName(String name) { if (this.name.equals(name)) { return this; } // Store the original resource name if necessary... if (this.resourceName != null) { if (this.resourceName.equals(name)) { return new ResourcePropertySource(this.resourceName, null, this.source); } else { return new ResourcePropertySource(name, this.resourceName, this.source); } } else { // Current name is resource name -> preserve it in the extra field... return new ResourcePropertySource(name, this.name, this.source); } }
/** * Create a PropertySource based on Properties loaded from the given resource. * The name of the PropertySource will be generated based on the * {@link Resource#getDescription() description} of the given resource. */ public ResourcePropertySource(EncodedResource resource) throws IOException { super(getNameForResource(resource.getResource()), PropertiesLoaderUtils.loadProperties(resource)); this.resourceName = null; }
String resolvedLocation = environment.resolveRequiredPlaceholders(location); Resource resource = resourceLoader.getResource(resolvedLocation); environment.getPropertySources().addFirst(new ResourcePropertySource(resource));