Announcement Announcement Module
Collapse
No announcement yet.
Providing authentication using spring security Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    hi amiladomingo , very thanks fr listening to me with patience, everything is working fine but when i hit url localhost:8080/spring-batch-admin/ admin page is displaying and evn i hit url localhost:8080/spring-batch-admin/batch/home also it is working bt as fr my requirement it should only work for the second url..please let me knw what to do..Thank you

    Comment


    • #17
      hi anyone, i am trying this out from few days but i am not able to find exact solution

      I am trying to pass user details for spring security file from properties file but it is not reflecting in spring security file let me paste my code:

      properties.xml:
      =============
      <code>

      <?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:context="http://www.springframework.org/schema/context"
      xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
      http://www.springframework.org/schema/util http://www.springframework.org/schem...pring-util.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


      <contextroperty-placeholder
      properties-ref="defaultProperties" />

      <utilroperties id="defaultProperties">
      <prop key="batch.id">${batch.id}</prop>
      <prop key="batch.secret">${batch.secret}</prop>
      </utilroperties>

      </beans>

      </code>


      And here is my security file:

      <code>

      <beans:beans xmlns="http://www.springframework.org/schema/security"
      xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schem...ring-beans.xsd
      http://www.springframework.org/schema/security
      http://www.springframework.org/schem...g-security.xsd
      http://www.springframework.org/schema/util http://www.springframework.org/schem...pring-util.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

      <beans:import resource="/classes/properties.xml" />

      <authentication-manager>
      <authentication-provider>
      <user-service>

      <user name="${batch.id}" password="${batch.secret}"
      authorities="ROLE_USER" />

      </user-service>
      </authentication-provider>
      </authentication-manager>

      </beans:beans>

      </code>



      Please help me out i am not able to solve why security file is not taking the values at runtime.

      Comment


      • #18
        simple config

        Code:
        <security:http auto-config="false" entry-point-ref="digest-entry-point" use-expressions="true" create-session="never" authentication-manager-ref="authentication-manager">
        		<security:intercept-url pattern="/**" access="isFullyAuthenticated()" />
        		<security:custom-filter ref="digest-filter" position="BASIC_AUTH_FILTER" />
        		<security:anonymous enabled="false"/>
        	</security:http>
        
        	<security:authentication-manager id="authentication-manager" >
        		<security:authentication-provider user-service-ref="user-service"/>
        	</security:authentication-manager>
        
        	<security:user-service id="user-service">
        		<security:user name="batch-admin" password="ndola" authorities="ROLE_BATCH_ADMIN"/>
        	</security:user-service>
        
        	<bean id="digest-filter"
        		class="org.springframework.security.web.authentication.www.DigestAuthenticationFilter"
        		p:userDetailsService-ref="user-service"
        		p:authenticationEntryPoint-ref="digest-entry-point" 
        		/>
        
        	<bean id="digest-entry-point"
        		class="org.springframework.security.web.authentication.www.DigestAuthenticationEntryPoint"
        		p:realmName="batch-admin" p:key="batch-admin" p:nonceValiditySeconds="10" />

        Comment


        • #19
          hello wims.tijd, i am sorry, i didnt get wat ur saying can you please eloberate. Thank you

          Comment


          • #20
            for your particular problem : move the
            Code:
            <context:property-placeholder
            to the security configuration

            Comment


            • #21
              hi wims.tijd, as you said i have included

              <code>

              <contextroperty-placeholder
              properties-ref="defaultProperties" />

              </code>

              into security file but a small problem where i need to configure "defaultProperties" in security file if i do as below way

              <code>

              <utilroperties id="defaultProperties">

              <authentication-manager>
              <authentication-provider>
              <user-service>

              <user name="${batch.id}" password="${batch.secret}"
              authorities="ROLE_USER" />

              </user-service>
              </authentication-provider>
              </authentication-manager>

              </utilroperties>


              But this is aint working. Please help me out

              Comment


              • #22
                should'nt this be :

                Code:
                <util:properties id="defaultProperties">
                <prop key="batch.id" value=""/>
                <prop key="batch.secre" value=""/>
                </util:properties>
                
                <authentication-manager>
                <authentication-provider>
                <user-service>
                
                <user name="${batch.id}" password="${batch.secret}"
                authorities="ROLE_USER" />
                
                </user-service>
                </authentication-provider>
                </authentication-manager>

                Comment


                • #23
                  with this config :
                  Code:
                  <context:property-placeholder properties-ref="access-properties" ignore-unresolvable="true"/>
                      
                      <util:properties id="access-properties">
                      	<prop key="admin.usr">admin</prop>
                      	<prop key="admin.psw">admin</prop>
                      	<prop key="admin.roles">ROLE_ADMIN</prop>
                      </util:properties>
                       
                      <security:authentication-manager>
                      	<security:authentication-provider user-service-ref="user-service"/>
                      </security:authentication-manager>
                  	
                  	<security:user-service id="user-service">
                  		<security:user name="${admin.usr}" password="${admin.psw}" authorities="${admin.roles}"/>
                  	</security:user-service>
                  you should be able to call :

                  Code:
                  Authentication auth = am.authenticate(new UsernamePasswordAuthenticationToken("admin", "admin"));
                  and get :

                  Code:
                  org.springframework.security.authentication.UsernamePasswordAuthenticationToken@4525caad: Principal: org.springframework.security.core.userdetails.User@586034f: Username: admin; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_ADMIN

                  Comment

                  Working...
                  X