Can i compare the username field value with one string value(like Administrator) in login.jsp?

Hi,

Can i compare the username field value with one string value(like Administrator) in login.jsp? How can i compare the username value with one string in this code?

If its equal means pass the value for authentication

else i have to set username value with null.

Can anyone help me?

Here is the code for username field in login.jsp

<tr>
<td class=“login_label”>
<label for=“username”>

&lt;fmt:message bundle="${messages}" key="label.login.username" /><br>

</label>
</td>
<td>
<input class=“login_input” type=“text” name=“user_name” id=“username” size=“22”>
</td>
</tr>

Thanks Veera

0 votes

1 answers

2537 views

ANSWER

What do you want to do exactly ?
03/19/2012

Hi,

There are so many groups and users we can create in nuxeo. After that i login in nuxeo,

I need to test that username with one constant value(Administrator).

How can i compare username value with one string in the above code in login.jsp

If (username == "Administrator") then use default logic for login(pass the username, password values for authentication) else login should fail. thats why i have to set a null value for username field, then only login will fail.

How can i use this logic in login.jsp?

Don't worry about other users. Administrator only login in nuxeo.

03/19/2012



I don't really understand your need. Why don't you use a local user management that stores only your administrator? Anyway I give my answer to your specific question :)

The better way is not to attach your logic to the login page, but on the authentication filter. For multiple raison but the main is that you can login to Nuxeo with other way than the login page. So must work on a central point: Authentication layer.

You need to have a little knowledge about development to do that. Here is the guide line:

  • install Nuxeo IDE
  • declare an authenticator that filters users except administrator
  • add it to the authentication chain
  • deploy your contribution into the server.

You just have to contribute a new Authenticator that fail for other username than Administrator, else do the default behavior. So my piece of advice will be to create a authenticator that extends the default one:

public class AdministratorFilterAuthenticator extends ApplicationFormAuthenticator {

@Override
public UserIdentificationInfo handleRetrieveIdentity(
        HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
            String userName = httpRequest.getParameter(usernameKey);
            if ("Administrator".equals(username)) {
                return super.handleRetrieveIdentity(httpRequest, httpResponse);
            }
            return null;
}

Finally you will have to add your authenticator to the authentication chain and declare your authenticator

  <extension
      target="org.nuxeo.ecm.platform.ui.web.auth.service.PluggableAuthenticationService"
      point="authenticators">

    <authenticationPlugin name="ADMINSITRATOR_FILTER_AUTH" enabled="true"
        class="org.nuxeo.ecm.mobile.filter.ApplicationFormAuthenticator">
      <needStartingURLSaving>true</needStartingURLSaving>
    </authenticationPlugin>
  </extension>
  <extension
      target="org.nuxeo.ecm.platform.ui.web.auth.service.PluggableAuthenticationService"
      point="chain">
    <authenticationChain>
      <plugins>
        <plugin>ADMINSITRATOR_FILTER_AUTH</plugin>
        <plugin>WEBSERVICES_AUTH</plugin>
      </plugins>
    </authenticationChain>
  </extension>

Hope this will help you.

1 votes



Hi,

Thanks a lot. This is what i want. Thanks once again.

I can create authenticator but i don't know about authentication chain. where it ll be in nuxeo? I am new to nuxeo.

Thanks.

03/19/2012

This is in my answer, the part :

 target=&quot;org.nuxeo.ecm.platform.ui.web.auth.service.PluggableAuthenticationService&quot; point=&quot;chain&quot;
03/19/2012

I create an authenticator plugin and put into..nuxeo/../server/nuxeo.ear/plugin folder.

I add authenticator into the authentication chain(I modify in authentication-framework.xml in nuxeo-platform-web-common-5.3.1.jar what you told above).

Restart server.

Its not working..Login sucessful for all users. Its not filtering.

Anything i missed? Please help me.

Thanks.

03/20/2012

You must not fork our code. This is evil. :)

You just have to contribute to the extension point and add a required to a component you want to override. And that's it.

You are on jjboss or tomcat ? Please use the bundle directory instead plugin.

We can't help you more, without more investigation from you in logs (there is an answer that explain how to do that : http://answers.nuxeo.com/questions/953/i-have-a-trouble-in-my-application-how-do-investigate-to-localize-my-trouble). Maybe you can check your component (XML file) that declares the authenticator is declared into the manifest, check the component name is unique, that you used Nuxeo IDE for creating your bundle (jar). That's a good start.

03/20/2012

Sorry for that wrong work…

I am using nuxeo-jboss-5.3.1.

There is no error in my logger.

I can create authenticator plugin. After that

How and where should i add it to authenticator chain?

where should i place my plugin? I am new to nuxeo..

Give some brief idea.

Thanks…

03/20/2012

You will need to have development skills for that.

I'll give you some reading for the night:

If you understood all things above you are ready to create your bundle:

  • Create your development environment: http://doc.nuxeo.com/x/aoKE
  • Create then your component (XML File) into the OSGI-INF file that contains your chain definition and authenticator definition
  • Deploy with Nuxeo IDE feature (look the documentation)

Hope this will help.

03/20/2012

Hi,

Thanks for sending such a wonderful documentations.

I created authenticator plugin. I follow the above docs for creating project. After that,

I add the authenticator plugin to the authentication chain(Create a xml file and paste it into $JBOSS_HOME/server/default/deploy/nuxeo.ear/config folder).

After restart nuxeo-jboss-5.3.1,

The Logs shows

14:26:59,077 ERROR [NuxeoAuthenticationFilter] Auth plugin ADMINSITRATOR_FILTER_AUTH can not be retrieved from service 14:26:59,116 ERROR [DefaultNuxeoExceptionHandler] java.lang.NullPointerException

at org.nuxeo.ecm.platform.ui.web.auth.NuxeoAuthenticationFilter.initUnAuthenticatedURLPrefix(NuxeoAuthenticationFilter.java:736)
at org.nuxeo.ecm.platform.ui.web.auth.NuxeoAuthenticationFilter.bypassAuth(NuxeoAuthenticationFilter.java:746)
at org.nuxeo.ecm.platform.ui.web.auth.NuxeoAuthenticationFilter.doFilter(NuxeoAuthenticationFilter.java:385)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.nuxeo.ecm.platform.web.common.requestcontroller.filter.NuxeoRequestControllerFilter.doFilter(NuxeoRequestControllerFilter.java:132)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.nuxeo.ecm.platform.web.common.exceptionhandling.NuxeoExceptionFilter.doFilter(NuxeoExceptionFilter.java:80)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)

14:26:59,150 ERROR [nuxeo-error-log] Request Attributes:

NuxeoExceptionHandlerMarker : true securityError : false user_message : an unexpected error occurred

Can you give some more guidence to complete this task?

Thanks

03/23/2012

Hi bjalon, Julien Carsique & Anahide Tchertchian,

Thanks for your guidance. I solved this issue with the help of your previous comments and documents.

Thanks a lot…

04/12/2012