get client user id(windows login id) in spring wit

2019-08-17 06:53发布

I am new to the spring framework, currently developing the web application. this application should automatically take the client's windows user id without any browser authentication(while accessing from another computer using a computer name). all the computers are connected in an intranet also using LDAP.

before I had developed the same application in PHP. there it is working without any problem. Simply i can use $_SERVER['PHP_AUTH_USER']; and i can get the clients user id .

there is no login page in this application. first, it should get the user id from the client automatically while accessing the application. based on the user id I can define the role. The application is running in my localhost.

enter image description here

I have added all the related jar files to the apache-tomcat lib folder. 1.Guvna 2.platform 3.slf4j 4.waffle jna 5.waffle jetty 6.waffle- tomcat9

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sec="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd">

    <!-- windows authentication provider -->
    <bean id="waffleWindowsAuthProvider" class="waffle.windows.auth.impl.WindowsAuthProviderImpl" />

    <!-- collection of security filters -->
    <bean id="negotiateSecurityFilterProvider" class="waffle.servlet.spi.NegotiateSecurityFilterProvider">
        <constructor-arg ref="waffleWindowsAuthProvider" />
    </bean>

    <bean id="basicSecurityFilterProvider" class="waffle.servlet.spi.BasicSecurityFilterProvider">
        <constructor-arg ref="waffleWindowsAuthProvider" />
    </bean>

    <bean id="waffleSecurityFilterProviderCollection" class="waffle.servlet.spi.SecurityFilterProviderCollection">
        <constructor-arg>
            <list>
                <ref bean="negotiateSecurityFilterProvider" />
                <ref bean="basicSecurityFilterProvider" />
            </list>
        </constructor-arg>
    </bean>


    <bean id="negotiateSecurityFilterEntryPoint" class="waffle.spring.NegotiateSecurityFilterEntryPoint">
        <property name="provider" ref="waffleSecurityFilterProviderCollection" />
    </bean>

    <!-- spring authentication provider -->
    <sec:authentication-manager alias="authenticationProvider" />


      <!-- spring filter entry point -->
    <sec:http  use-expressions="true" entry-point-ref="negotiateSecurityFilterEntryPoint">
           <sec:custom-filter ref="tmswaffleNegotiateSecurityFilter" position="BASIC_AUTH_FILTER" />
        <sec:intercept-url pattern="/users" access="hasRole('USER')" />

    </sec:http>

    <bean id="tmswaffleNegotiateSecurityFilter" class="com.javatpoint.config.tmsegotiateSecurityFilter">
        <property name="provider" ref="waffleSecurityFilterProviderCollection" />
        <property name="allowGuestLogin" value="false" />
        <property name="principalFormat" value="fqn" />
        <property name="roleFormat" value="both" />
    </bean>

</beans>

I was trying the same thing in spring. but not able to get the user id. I have tried waffle filter but the browser was asking windows authentication on the browser. but I don't want to authenticate. I need only the client's windows user id while accessing the application.

please help me on this topic.

0条回答
登录 后发表回答