Reputation: 4014
I am writing a plugin for nexus oss , where I need to use a new filter instead of the filter prescribed in nexus oss .
In earlier versions of nexus oss ,all filters were defined in web.xml as follows
<filter>
<filter-name>nexusFilter</filter-name>
<filter-class>org.sonatype.nexus.security.filter.NexusJSecurityFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>
[filters]
authcBasic = org.sonatype.nexus.security.filter.authc.NexusSecureHttpAuthenticationFilter
authcBasic.applicationName = Sonatype Nexus Repository Manager API
authcBasic.fakeAuthScheme = false
authcNxBasic = org.sonatype.nexus.security.filter.authc.NexusSecureHttpAuthenticationFilter
authcNxBasic.applicationName = Sonatype Nexus Repository Manager API (specialized auth)
authcNxBasic.fakeAuthScheme = true
So what we used to do is just modify this web.xml to take our filter instead of NexusSecureHttpAuthenticationFilter of nexus oss and the job was done .
But now in latest version of nexus oss they are doing all filter configiurations in a java file
@Named
public class NexusSecurityFilterModule
extends AbstractModule
{
@Override
protected void configure()
{
requireBinding( FilterChainResolver.class );
bindAuthcFilter( "authcBasic", false, "Sonatype Nexus Repository Manager API" );
bindAuthcFilter( "authcNxBasic", true, "Sonatype Nexus Repository Manager API (specialized auth)" );
.
.
.
private void bindAuthcFilter( String name, boolean fakeAuthSchem, String applicationName )
{
NexusSecureHttpAuthenticationFilter filter = new NexusSecureHttpAuthenticationFilter();
filter.setApplicationName( applicationName );
filter.setFakeAuthScheme( Boolean.toString( fakeAuthSchem ) );
bindNamedFilter( name, filter );
}
.
.
private void bindNamedFilter( String name, Filter filter )
{
Key<Filter> key = Key.get( Filter.class, Names.named( name ) );
bind( key ).toProvider( defer( filter ) ).in( Scopes.SINGLETON );
}
Full java code of the filter configuration is here NexusSecurityFilterModule.java.
so now i don't know how to make nexus oss use our filter instead of their NexusSecurityFilterModule.java. The impediment here is as it is a java file I cannot modify as easily as I did in web.xml . Is there a way that I can override the filter they have configured in the java file and make nexus oss use our custom filter.
Upvotes: 0
Views: 872
Reputation: 726
I have a solution but its not correct solution. Anyway it solve your problem.
replace that JavaFile in jar usign decompile change code what u want and againt inject in to jar
Here is the step,
1. using java decompiler decompile that class from the jar, here (NexusSecurityFilterModule.class)
and get Java file (NexusSecurityFilterModule.java)
2. change that filer that u want.
3. compile the class get NexusSecurityFilterModule.class
4. Inject to jar. jar -uvf <jar-name> <javaclass>
Done.
Happy update!!
Upvotes: 1