I have a simple Spring.NET demo, and I'm trying to have a shared object file that would reside on a shared drive. This works if I pass in the UNC path as a resource file to the constructor, but if use an <import resource construct it interprets it as relative, which is not supported. Is there a way I can use the import statement with a UNC path?
Works:
<context>
<resource uri="config://spring/objects"/>
<resource uri="\\server\share\folder\SpringConfig.xml"/>
</context>
Doesn't work:
<import resource="\\server\share\folder\SpringConfig.xml"></import>
Error message:
System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': ConfigSectionResource does not support relative resources. Please use fully qualified resource name. ---> Spring.Objects.Factory.ObjectDefinitionStoreException: Error registering object defined in 'config [C:\Users\user\documents\visual studio 2010\Projects\SpringExample\SpringExample\bin\Debug\SpringExample.vshost.exe.Config#spring/objects] at line 1' : Failed parsing element
---> System.NotSupportedException: ConfigSectionResource does not support relative resources. Please use fully qualified resource name.
Use the fully qualified resource string and use forward slashes throughout:
<objects xmlns="http://www.springframework.net">
<import resource="file:////server/share/folder/SpringConfig.xml" />
</objects>
Note that file: protocol identifier is followed by four slashes, two belong to the protocol and two to the server location.
Worked on my machine :). This also works:
<objects xmlns="http://www.springframework.net">
<import resource="file://\\server\share\folder\SpringConfig.xml" />
</objects>
Hmmm..
This should work. What I don't understand is why ConfigSectionResource throw the exception.
FileSystemResource should be used by default in a non Web application.
What version of Spring.NET are you using ? Are you using CodeCondig extension ?
Anyway, this should work:
<resource uri="file://\\server\share\folder\SpringConfig.xml"/>
I'm honestly not certain whether UNC paths are supported or not, but if you want a fully-qualified file path, you need to use <resource uri="file://c:/folder1/folder2/MyConfig.xml" /> IIRC.
Related
Is there any way to restrict access by configuring in WildFly. I would like to know whether we can add a list of IPs that can only access the server? Is there any way to blacklist IPs in server level?
I am checking a feature like this: http://boseca.blogspot.in/2010/12/programmatically-addremove-ip-security.html
You can also implement the IP filter on JBOSS level by adding a filter-ref and expression filter as shown below
<subsystem xmlns="urn:jboss:domain:undertow:3.0" statistics-enabled="true" instance-id="instanceid">
<buffer-cache name="default"/>
<server name="default-server">
<ajp-listener name="ajp" max-connections="1200" write-timeout="600000" read-timeout="30000" allow-equals-in-cookie-value="true" record-request-start-time="true" socket-binding="ajp"/>
<http-listener name="default" allow-equals-in-cookie-value="true" socket-binding="http"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<access-log suffix=".log" prefix="access" pattern="%a %h %{i,sm_user} %u %t %r %s %b %T"/>
<filter-ref name="limit-connections"/>
<filter-ref name="ipaccess"/>
<single-sign-on/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<request-limit name="limit-connections" queue-size="100" max-concurrent-requests="1200"/>
<expression-filter module="io.undertow.core" name="ipaccess" expression="ip-access-control[default-allow=false, acl={'10.0.0.1 deny', '10.0.0.0/24 allow'}]"/>
</filters>
</subsystem>
If you're using Wildfly 8.2 (which contains Undertow 1.1.0), then you can configure IP access control via the undertow-handlers.conf file, which you put in a war's WEB-INF or a jar's META-INF folder.
You can do something like:
ip-access-control[default-allow=false, acl={'10.0.0.1 deny', '10.0.0.0/24 allow'}]
this can also be combined with predicates:
path-prefix[/internal] -> ip-access-control[acl={ '10.0.0.0/24 allow'}]
Source.
Alternatively (or if you use an earlier Wildfly version than 8.2) you can create a ServletExtension. Create a file META-INF\services\io.undertow.servlet.ServletExtension, in it there should be a fully qualified name of your extension. The extension must implement the io.undertow.servlet.ServletExtension interface. This extension then may create a io.undertow.server.handlers.IPAddressAccessControlHandler programmatically, configure it, and add it to the deployment's initial handler chain.
The above talked about adding a handler at the deployment level. To add a custom handler at the server level you need at least Wildfly 8.2. In the undertow subsystem in standalone.xml (or whatever config you use) you can add a handler (filter) like this (irrelevant configuration omitted):
<subsystem xmlns="urn:jboss:domain:undertow:1.2">
<server name="default-server">
<host name="default-host" alias="localhost">
<filter-ref name="custom-filter" />
</host>
</server>
<filters>
<filter name="custom-filter" module="io.undertow.core" />
class-name="io.undertow.server.handlers.HttpTraceHandler"
</filters>
</subsystem>
Source. The handler must be in your static server module, not in a deployment. Inherit the IPAddressAccessControlHandler, configure it in your constructor or override its methods as you need, and point the config to your custom handler.
According to WFLY-4048 text based handler configuration at the server level will be in Wildfly 10.
we need to define a different file url via simple naming bindings for every server in a JBoss domain.
e.g. we need for every server in the cluster an entry like
<subsystem xmlns="urn:jboss:domain:naming:1.4">
<bindings>
<simple name="java:/url/ServerConfigurationUrl" value="file:///c:/JBoss//server3.properties" type="java.net.URL"/>
</bindings>
</subsystem>
Can this be achieved using some variables? Expressions seem not to be valid here.
If we could just use something like value=${path to file} that would be great.
Thanks,
ralf
Using something like
<system-properties>
<property name="FILEURL" value=value="file:///c:/JBoss//server3.properties" />
</system-properties>
and then
<bindings>
<simple name="java:/url/ServerConfigurationUrl" value="${FILEURL}" type="java.net.URL"/>
</bindings>
worked for me.
Greetings,
ralf
I have a problem with NLog for logging its internal logs with this configuration
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true"
internalLogFile="${basedir}/App_Data/NLog.log"
internalLogLevel="Trace">
<targets>
<target name="debug"
xsi:type="File"
fileName="${basedir}/App_Data/Site.log" />
</targets>
<rules>
<logger name="*"
writeTo="debug" />
</rules>
</nlog>
The target "debug" is working well, but the internalLogFile is only working if I set it for exemple to "D:/NLog.log".
Any idea why this happening?
You can't use layout renderers ${...} in the internalLogFile property. They are for a target's layout only:
<target layout="${...}" />
Try to use relative path like "..\App_Data\NLog.log"
Update NLog 4.6 enables some simple layouts.
The internalLogFile attribute needs to be set to an absolute path and the executing assembly needs to have permission to write to that absolute path.
The following worked for me.
Create a folder somewhere - e.g. the route of your c: drive, e.g. c:\logs
Edit the permissions of this folder and give full control to everyone
Set your nlog config: internalLogFile="C:\logs\nlog.txt"
Remember to clean up after yourself and not leave a directory with those sorts of permissions on
NLog ver. 4.6 add support for environment-variables like %appdata% or %HOME%, and using these basic layouts in internalLogFile=:
${currentdir}
${basedir}
${tempdir}
NLog ver. 4.7 also adds this:
${processdir}
See also: https://github.com/NLog/NLog/wiki/Internal-Logging
from this link I think the path is absolute
I want to configure the spring.net in some other setting files like xml not through app.config.
Is it possible to configure the spring.net in xml not in app.config file.if yes how can i do it.
Yes, you can place your configuration in normal xml files. In the Spring.NET documentation, the following example is given:
services.xml:
<objects xmlns="http://www.springframework.net">
<object id="PetStore" type="PetStore.Services.PetStoreService, PetStore">
<property name="AccountDao" ref="AccountDao"/>
<property name="ItemDao" ref="ItemDao"/>
<!-- additional collaborators and configuration for this object go here -->
</object>
<!-- more object definitions for services go here -->
</objects>
The file daos.xml has a similar structure and contains definitions for ItemDao and AccountDao.
In code, you can create an instance of your container using the files services.xml and daos.xml as follows:
IApplicationContext context = new XmlApplicationContext("services.xml", "daos.xml")
I want to use ConfigurableActiveDirectoryMembershipProvider in my code. I have my current settings as
<add name="XXXXMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershi pProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="XXXXConnectionString"
connectionUsername="user"
connectionPassword="password"
connectionProtection="Secure" />
I have changed this to
<add connectionStringName=""
name="XXXXDomainADMembershipProvider"
type="Spring.Web.Providers.MembershipProviderAdapter, Spring.Web" />
and added in to my spring config file as
<object id="XXXXDomainADMembershipProvider"
type="Spring.Web.Providers.ConfigurableActiveDirec toryMembershipProvider">
<property name="connectionStringName" value="XXXXDomainConnectionString" />
<property name="connectionUsername" value="user" />
<property name="connectionPassword" value="password" />
</object>
But I am getting the following error
Error creating context 'spring.root': Could not load type from string value 'Spring.Web.Providers.ConfigurableActiveDirectoryM embershipProvider'.
I checked the Spring.WebQuickStart source code and the class Spring.Web.Providers.ConfigurableActiveDirectoryMembershipProvider has been commented out.
Is that the reason I am getting the above error?
Yes, I think you are correct. The error you are getting is exactly the error Spring returns when you are trying to configure an object using a type that can not be loaded. For instance if the class does not exist at all, which appears to be the case here.
You can double check if the ConfigurableActiveDirectoryMembershipProvider class exists by using the object browser to explore the Spring.Web.Providers namespace in the Spring.Web assembly you are using in your project.
You are right that the class is commented out in the current state of the trunk code. It has a small TBD note, so I think they are not sure if they want to implement this. But it could be that it wasn't commented out in the version of Spring.Web you are using, so you should still check it using the object explorer.
Strangely enough, the ConfigurableActiveDirectoryMembershipProvideris mentioned in the documentation - you might want to post this on the Spring.Net forum they're likely to help you.