WSO2 ESB unable to remove ws-security header in the response before DSS call - ws-security

I have a proxy service which needs to call a exernal service with ws security. I have to
call the service, and based on the response, I need to extract some information
and then call a data service to update the database. As I get the response and create the
payload to call the data service it is also having the ws security header which ends up in an exception.
I have used
<header action="remove" name="wsse:Security" scope="default"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" />
while creating and calling the data service but end up with no luck.
Below is my proxy service.
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="EDI_Test_Proxy_2" startOnLoad="true" trace="disable"
transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<header name="Action" scope="default" value="get_mcash_data" />
<property name="Content-Type" scope="transport" type="STRING"
value="application/soap+xml; charset=UTF-8; action=get_mcash_data" />
<call>
<endpoint>
<address trace="disable"
uri="http://localhost:9770/services/my_fetch_data_service" />
</endpoint>
</call>
<property expression="//mc:mcash/mc:tran_id/text()" name="tran_id"
scope="default" type="STRING" xmlns:mc="http://ws.wso2.org/dataservice"
xmlns:ns="http://org.apache.synapse/xsd" />
<log level="custom">
<property expression="$ctx:tran_id" name="tran_id" />
</log>
<filter xmlns:mc="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd"
xpath="boolean(//mc:mcash/mc:mobile_no)">
<then>
<property expression="//mc:mcash/mc:tran_id/text()" name="tran_id"
scope="default" type="STRING" />
<property expression="//mc:mcash/mc:mobile_no/text()"
name="mobile_no" scope="default" type="STRING" />
<property expression="//mc:mcash/mc:tran_amt/text()" name="tran_amt"
scope="default" type="STRING" />
<property expression="//mc:mcash/mc:tran_date/text()"
name="tran_date" scope="default" type="STRING" />
<property expression="//mc:mcash/mc:tran_time/text()"
name="tran_time" scope="default" type="STRING" />
<property expression="//mc:mcash/mc:part_tran_srl_num/text()"
name="part_tran_srl_num" scope="default" type="STRING" />
<log level="custom">
<property expression="$ctx:tran_id" name="tran_id" />
<property expression="$ctx:mobile_no" name="mobile_no" />
<property expression="$ctx:tran_amt" name="tran_amt" />
<property expression="$ctx:tran_date" name="tran_date" />
<property expression="$ctx:tran_time" name="tran_time" />
<property expression="$ctx:part_tran_srl_num" name="tran_time" />
</log>
<payloadFactory description="pf_mcash" media-type="xml">
<format>
<flw:purchaceFromMMR xmlns:flw="http://flw.mwt.mobitel.com/">
<!--Optional: -->
<bankPurchaseRequest xmlns="">
<amount>$1</amount>
<!--Optional: -->
<bankCode>XXX</bankCode>
<!--Optional: -->
<date>$2</date>
<!--Optional: -->
<mobile>$3</mobile>
<!--Optional: -->
<time>$4</time>
<!--Optional: -->
<transactionId>$5</transactionId>
</bankPurchaseRequest>
</flw:purchaceFromMMR>
</format>
<args>
<arg evaluator="xml" expression="$ctx:tran_amt" />
<arg evaluator="xml" expression="$ctx:tran_date" />
<arg evaluator="xml" expression="$ctx:mobile_no" />
<arg evaluator="xml" expression="$ctx:tran_time" />
<arg evaluator="xml" expression="$ctx:tran_id" />
</args>
</payloadFactory>
<call>
<endpoint>
<address trace="disable"
uri="https://my_external_web_service/to_be/called?wsdl">
<enableSec policy="gov:ws-policy/sample_policy.xml" />
</address>
</endpoint>
</call>
<loopback />
</then>
<else>
<log>
<property name="STATUS" value="*****No data available*****" />
</log>
</else>
</filter>
</inSequence>
<outSequence>
<header action="remove" name="wsse:Security" scope="default"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" />
<header action="remove" name="To" scope="default" />
<property expression="//return/mobile/text()" name="mobile"
scope="default" type="STRING" />
<property expression="//return/date/text()" name="date"
scope="default" type="STRING" />
<property expression="//return/recipetNo/text()" name="recipetNo"
scope="default" type="STRING" />
<property expression="//return/resultCode/text()" name="resultCode"
scope="default" type="STRING" />
<property expression="//return/resultDesc/text()" name="resultDesc"
scope="default" type="STRING" />
<payloadFactory description="pf_mcash_update"
media-type="xml">
<format>
<p:TestUpdate xmlns:p="http://ws.wso2.org/dataservice">
<!--Exactly 1 occurrence -->
<p:trf_status>$1</p:trf_status>
<!--Exactly 1 occurrence -->
<p:resp_code>$2</p:resp_code>
<!--Exactly 1 occurrence -->
<p:receipt>$3</p:receipt>
<!--Exactly 1 occurrence -->
<p:rsp_message>$4</p:rsp_message>
<!--Exactly 1 occurrence -->
<p:tran_id>$5</p:tran_id>
<!--Exactly 1 occurrence -->
<p:part_tran_srl_num>$6</p:part_tran_srl_num>
</p:TestUpdate>
</format>
<args>
<arg value="10" />
<arg evaluator="xml" expression="$ctx:resultCode" />
<arg evaluator="xml" expression="$ctx:recipetNo" />
<arg evaluator="xml" expression="$ctx:resultDesc" />
<arg value="SDC311521" />
<arg evaluator="xml" expression="$ctx:part_tran_srl_num" />
</args>
</payloadFactory>
<header name="Action" scope="default" value="TestUpdate" />
<property name="Content-Type" scope="transport" type="STRING"
value="application/soap+xml; charset=UTF-8; action=TestUpdate" />
<call>
<endpoint>
<address trace="disable"
uri="http://my_internal_data_service/which_ends_up_with/ws_sec_header" />
</endpoint>
</call>
</outSequence>
<faultSequence />
</target>
</proxy>
Any advice is very much appreciated.

Can you add the following log mediator before the call mediator in the outsequence and update this with the output logs.
it will help us to identify the issue.
<log level="full">
<property name="OutSequence" value="==== OUTSEQ ===="/>
</log>

The issue was I have engaged rampart module <module ref="rampart" /> in the axis2.xml found in <ESB_HOME>repository/conf/axis2/ . After commenting out this line the exception was gone and the dss call worked. The reason I believe, if this line of code is enabled, ws-securiy is engaged globally and all the service calls will look for ws-security header. Please correct me if I'm wrong in anyway.

Related

oAuth2 with spring mvc and mongo db integration spring security

My secuirity-config
<?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:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd ">
<!-- #author Soeng kanel (soengkanel#gmail.com) -->
<!-- This is default url to get a token from OAuth -->
<http pattern="/oauth/token" create-session="stateless"
authentication-manager-ref="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<!-- include this only if you need to authenticate clients via request
parameters -->
<custom-filter ref="clientCredentialsTokenEndpointFilter"
after="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<!-- This is where we tells spring security what URL should be protected
and what roles have access to them -->
<http pattern="/api/**" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint"
access-decision-manager-ref="accessDecisionManager"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/api/**" access="ROLE_ADMIN" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<bean id="oauthAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="test" />
</bean>
<bean id="clientAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="test/client" />
<property name="typeName" value="Basic" />
</bean>
<bean id="oauthAccessDeniedHandler"
class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" />
<bean id="clientCredentialsTokenEndpointFilter"
class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="clientAuthenticationManager" />
</bean>
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased"
xmlns="http://www.springframework.org/schema/beans">
<constructor-arg>
<list>
<bean class="org.springframework.security.oauth2.provider.vote.ScopeVoter" />
<bean class="org.springframework.security.access.vote.RoleVoter" />
<bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
</list>
</constructor-arg>
</bean>
<authentication-manager id="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService" />
</authentication-manager>
<!-- This is simple authentication manager, with a hardcoded user/password
combination. We can replace this with a user defined service to get few users
credentials from DB -->
<authentication-manager alias="authenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="mongoUserDetailsService">
<password-encoder hash="plaintext" />
</authentication-provider>
</authentication-manager>
<bean id="clientDetailsUserService"
class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetails" />
</bean>
<!-- This defined token store, we have used inmemory tokenstore for now
but this can be changed to a user defined one -->
<bean id="tokenStore"
class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore" />
<!-- This is where we defined token based configurations, token validity
and other things -->
<bean id="tokenServices"
class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<property name="tokenStore" ref="tokenStore" />
<property name="supportRefreshToken" value="true" />
<property name="accessTokenValiditySeconds" value="120" />
<property name="clientDetailsService" ref="clientDetails" />
</bean>
<bean id="userApprovalHandler"
class="org.springframework.security.oauth2.provider.approval.TokenServicesUserApprovalHandler">
<property name="tokenServices" ref="tokenServices" />
</bean>
<oauth:authorization-server
client-details-service-ref="clientDetails" token-services-ref="tokenServices"
user-approval-handler-ref="userApprovalHandler">
<oauth:authorization-code />
<oauth:implicit />
<oauth:refresh-token />
<oauth:client-credentials />
<oauth:password />
</oauth:authorization-server>
<oauth:resource-server id="resourceServerFilter"
resource-id="test" token-services-ref="tokenServices" />
<oauth:client-details-service id="clientDetails">
<!-- client -->
<oauth:client client-id="restapp"
authorized-grant-types="authorization_code,client_credentials"
authorities="ROLE_ADMIN" scope="read,write,trust" secret="secret" />
<oauth:client client-id="restapp"
authorized-grant-types="password,authorization_code,refresh_token,implicit"
secret="restapp" authorities="ROLE_ADMIN" />
</oauth:client-details-service>
<sec:global-method-security
pre-post-annotations="enabled" proxy-target-class="true">
<!--you could also wire in the expression handler up at the layer of the
http filters. See https://jira.springsource.org/browse/SEC-1452 -->
<sec:expression-handler ref="oauthExpressionHandler" />
</sec:global-method-security>
<oauth:expression-handler id="oauthExpressionHandler" />
<oauth:web-expression-handler id="oauthWebExpressionHandler" />
</beans>
above security-config works just fine, But when I added this above block of code
<global-method-security pre-post-annotations="enabled" />
<http pattern="/resources/**" security="none"/>
<!-- secure the application's urls with the specific Role -->
<http auto-config="false" use-expressions="true" access-denied-page="/accessdenied">
<intercept-url pattern="/login" access="permitAll" />
<intercept-url pattern="/logout" access="permitAll" />
<intercept-url pattern="/accessdenied" access="permitAll" />
<intercept-url pattern="/campaigns" access="hasAnyRole('ROLE_ADMIN','ROLE_MASTER')" />
<intercept-url pattern="/users" access="hasAnyRole('ROLE_ADMIN')" />
<intercept-url pattern="/dashboard" access="hasAnyRole('ROLE_ADMIN','ROLE_MASTER')" />
<form-login login-page="/login" default-target-url="/dashboard" authentication-failure-url="/accessdenied" />
<logout logout-success-url="/logout" />
</http>
I get error in eclipse.
cvc-complex-type.2.4.a: Invalid content was found starting with element 'http'. One of '{"http://www.springframework.org/schema/beans":description,
"http://www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, "http://www.springframework.org/schema/
beans":bean, WC[##other:"http://www.springframework.org/schema/beans"], "http://www.springframework.org/schema/beans":beans}' is expected.
[UPDATED] Finally, I can solve the problem, here good security-config,spring mvc,mongodb,
<?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:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd ">
<!-- #author Soeng kanel (soengkanel#gmail.com) -->
<!-- This is default url to get a token from OAuth -->
<sec:http pattern="/oauth/token" create-session="stateless"
authentication-manager-ref="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<!-- include this only if you need to authenticate clients via request
parameters -->
<custom-filter ref="clientCredentialsTokenEndpointFilter"
after="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</sec:http>
<!-- This is where we tells spring security what URL should be protected
and what roles have access to them -->
<sec:http pattern="/api/**" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint"
access-decision-manager-ref="accessDecisionManager"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/api/**" access="ROLE_ADMIN" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</sec:http>
<bean id="oauthAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="test" />
</bean>
<bean id="clientAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="test/client" />
<property name="typeName" value="Basic" />
</bean>
<bean id="oauthAccessDeniedHandler"
class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" />
<bean id="clientCredentialsTokenEndpointFilter"
class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="clientAuthenticationManager" />
</bean>
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased"
xmlns="http://www.springframework.org/schema/beans">
<constructor-arg>
<list>
<bean class="org.springframework.security.oauth2.provider.vote.ScopeVoter" />
<bean class="org.springframework.security.access.vote.RoleVoter" />
<bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
</list>
</constructor-arg>
</bean>
<authentication-manager id="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService" />
</authentication-manager>
<!-- This is simple authentication manager, with a hardcoded user/password
combination. We can replace this with a user defined service to get few users
credentials from DB -->
<authentication-manager alias="authenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="mongoUserDetailsService">
<password-encoder hash="plaintext" />
</authentication-provider>
</authentication-manager>
<bean id="clientDetailsUserService"
class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetails" />
</bean>
<!-- This defined token store, we have used inmemory tokenstore for now
but this can be changed to a user defined one -->
<bean id="tokenStore"
class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore" />
<!-- This is where we defined token based configurations, token validity
and other things -->
<bean id="tokenServices"
class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<property name="tokenStore" ref="tokenStore" />
<property name="supportRefreshToken" value="true" />
<property name="accessTokenValiditySeconds" value="120" />
<property name="clientDetailsService" ref="clientDetails" />
</bean>
<bean id="userApprovalHandler"
class="org.springframework.security.oauth2.provider.approval.TokenServicesUserApprovalHandler">
<property name="tokenServices" ref="tokenServices" />
</bean>
<oauth:authorization-server
client-details-service-ref="clientDetails" token-services-ref="tokenServices"
user-approval-handler-ref="userApprovalHandler">
<oauth:authorization-code />
<oauth:implicit />
<oauth:refresh-token />
<oauth:client-credentials />
<oauth:password />
</oauth:authorization-server>
<oauth:resource-server id="resourceServerFilter"
resource-id="test" token-services-ref="tokenServices" />
<oauth:client-details-service id="clientDetails">
<!-- client -->
<oauth:client client-id="restapp"
authorized-grant-types="authorization_code,client_credentials"
authorities="ROLE_ADMIN" scope="read,write,trust" secret="secret" />
<oauth:client client-id="restapp"
authorized-grant-types="password,authorization_code,refresh_token,implicit"
secret="restapp" authorities="ROLE_ADMIN" />
</oauth:client-details-service>
<sec:global-method-security
pre-post-annotations="enabled" proxy-target-class="true">
<!--you could also wire in the expression handler up at the layer of the
http filters. See https://jira.springsource.org/browse/SEC-1452 -->
<sec:expression-handler ref="oauthExpressionHandler" />
</sec:global-method-security>
<sec:http pattern="/resources/**" security="none"/>
<sec:http auto-config="false" use-expressions="true" access-denied-page="/accessdenied">
<sec:intercept-url pattern="/login" access="permitAll" />
<sec:intercept-url pattern="/logout" access="permitAll" />
<sec:intercept-url pattern="/accessdenied" access="permitAll" />
<sec:intercept-url pattern="/campaigns" access="hasAnyRole('ROLE_ADMIN','ROLE_MASTER')" />
<sec:intercept-url pattern="/users" access="hasAnyRole('ROLE_ADMIN')" />
<sec:intercept-url pattern="/dashboard" access="hasAnyRole('ROLE_ADMIN','ROLE_MASTER')" />
<sec:form-login login-page="/login" default-target-url="/dashboard" authentication-failure-url="/accessdenied" />
<sec:logout logout-success-url="/logout" />
</sec:http>
<oauth:expression-handler id="oauthExpressionHandler" />
<oauth:web-expression-handler id="oauthWebExpressionHandler" />
</beans>

Custom URI Oauth2 + Spring security - REST API

i need help to make a custom URI using Oauth2, i implemented one using something like this.
oauth/token?grant_type=password&client_id=restapp&client_secret=restapp&username=user123&password=pass123
but i want to pass all the data using headers, but i didn't found any example to how to do it.
is it possible? or recommendable?
thank you very much.
EDIT: add my spring-security.xml
<import resource="/spring-config.xml" />
<!-- This is default url to get a token from OAuth -->
<http pattern="/oauth/token" create-session="stateless"
authentication-manager-ref="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<!-- include this only if you need to authenticate clients via request
parameters -->
<custom-filter ref="clientCredentialsTokenEndpointFilter"
after="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<!-- This is where we tells spring security what URL should be protected
and what roles have access to them -->
<http pattern="/api/prod/**" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint"
access-decision-manager-ref="accessDecisionManager"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/api/prod/**" access="ROLE_APP" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<bean id="oauthAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="test" />
</bean>
<bean id="clientAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="test/client" />
<property name="typeName" value="Basic" />
</bean>
<bean id="oauthAccessDeniedHandler"
class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" />
<bean id="clientCredentialsTokenEndpointFilter"
class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="clientAuthenticationManager" />
</bean>
<!-- Custom User details service which is provide the user data -->
<bean id="customAuthenticationProvider"
class="com.system.rest.natura.resources.security.CustomAuthenticationProvider" />
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased"
xmlns="http://www.springframework.org/schema/beans">
<constructor-arg>
<list>
<bean class="org.springframework.security.oauth2.provider.vote.ScopeVoter" />
<bean class="org.springframework.security.access.vote.RoleVoter" />
<bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
</list>
</constructor-arg>
</bean>
<authentication-manager id="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService" />
</authentication-manager>
<authentication-manager alias="authenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider ref="customAuthenticationProvider" />
</authentication-manager>
<bean id="clientDetailsUserService"
class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetails" />
</bean>
<bean id="tokenStore"
class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore" />
<bean id="tokenServices"
class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<property name="tokenStore" ref="tokenStore" />
<property name="supportRefreshToken" value="true" />
<property name="accessTokenValiditySeconds" value="1200" />
<property name="clientDetailsService" ref="clientDetails" />
</bean>
<bean id="userApprovalHandler"
class="org.springframework.security.oauth2.provider.approval.TokenServicesUserApprovalHandler">
<property name="tokenServices" ref="tokenServices" />
</bean>
<oauth:authorization-server
client-details-service-ref="clientDetails" token-services-ref="tokenServices"
user-approval-handler-ref="userApprovalHandler">
<oauth:authorization-code />
<oauth:implicit />
<oauth:refresh-token />
<oauth:client-credentials />
<oauth:password />
</oauth:authorization-server>
<oauth:resource-server id="resourceServerFilter"
resource-id="test" token-services-ref="tokenServices" />
<oauth:client-details-service id="clientDetails">
<!-- client -->
<clientAuthenticationScheme>
</clientAuthenticationScheme>
<oauth:client client-id="restapp"
authorized-grant-types="authorization_code,client_credentials"
authorities="ROLE_APP" scope="read,write,trust" secret="secret" />
<oauth:client client-id="restapp"
authorized-grant-types="password,authorization_code,refresh_token,implicit"
secret="restapp" authorities="ROLE_APP" />
</oauth:client-details-service>
<sec:global-method-security
pre-post-annotations="enabled" proxy-target-class="true">
<sec:expression-handler ref="oauthExpressionHandler" />
</sec:global-method-security>
<oauth:expression-handler id="oauthExpressionHandler" />
<oauth:web-expression-handler id="oauthWebExpressionHandler" />
Did you try to put this line in src/main/application.yml ?
security:
oauth2:
client:
clientAuthenticationScheme: header
EDIT 1 :
According to https://github.com/jirutka/spring-security-oauth-samples/blob/master/tonr/src/main/webapp/WEB-INF/spring/security.xml, in XML you must have something like this :
<oauth:resource id="facebook"
type="authorization_code"
client-id="233668646673605"
client-secret="33b17e044ee6a4fa383f46ec6e28ea1d"
authentication-scheme="query"
access-token-uri="https://graph.facebook.com/oauth/access_token"
user-authorization-uri="https://www.facebook.com/dialog/oauth"
token-name="oauth_token"
client-authentication-scheme="form" />
where client-authentication-scheme value is header.

Format="soap11" throwing an error in wso2 Esb and Dss

Am working with wso2esb 4.7.0 and wso2dss 3.0.0.
I generally use Format="soap11" in the endpoint url in all my services
I have created a proxy and its sequences were it inserts data into the tables as shown below
Proxy service
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TicketInsertionMobileNew2.0"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence onError="fault">
<property name="messageType" value="application/json" scope="axis2"/>
<property name="ClientId"
expression="//ClientId/text()"
scope="default"
type="STRING"/>
<property name="uuid"
expression="//uuid/text()"
scope="default"
type="STRING"/>
<property name="deviceid"
expression="//deviceid/text()"
scope="default"
type="STRING"/>
<property name="todoname"
expression="//TicketSubject/text()"
scope="default"
type="STRING"/>
<property name="tododetails"
expression="//TicketText/text()"
scope="default"
type="STRING"/>
<property name="PartyBranchId"
expression="//PartyBranchId/text()"
scope="default"
type="STRING"/>
<property name="AssignedtoRoleId"
expression="//AssignedtoRoleID/text()"
scope="default"
type="STRING"/>
<property name="AssignedtoUserId"
expression="//AssignedtoUserID/text()"
scope="default"
type="STRING"/>
<property name="AssignedtoUsergroupId"
expression="//AssignedtoUsergroupID/text()"
scope="default"
type="STRING"/>
<property name="Tags"
expression="//tags/text()"
scope="default"
type="STRING"/>
<property name="CreatedById"
expression="//TicketCreator/text()"
scope="default"
type="STRING"/>
<property name="Time"
expression="get-property('SYSTEM_TIME')"
scope="default"
type="STRING"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property name="username" expression="get-property('transport', 'username')"/>
<property name="password" expression="get-property('transport', 'password')"/>
<property name="PartyBranchID"
expression="//FieldValue/text()"
scope="default"
type="STRING"/>
<property name="usercode"
expression="fn:substring-before(get-property('username'),'|')"
scope="default"
type="STRING"/>
<property name="clientid"
expression="fn:substring-after(get-property('username'),'|')"
scope="default"
type="STRING"/>
<log level="custom">
<property name="LogLocation" value="TicketInsertionMobileNew2.0"/>
</log>
<payloadFactory>
<format>
<send xmlns="">
<username>$1</username>
<password>$2</password>
</send>
</format>
<args>
<arg evaluator="xml" expression="get-property('username')"/>
<arg evaluator="xml" expression="get-property('password')"/>
</args>
</payloadFactory>
<send receive="TicketInsertionMobile_Seq2.0">
<endpoint>
<address uri="http://localhost:8282/services/Login2.0" format="soap11">
<suspendOnFailure>
<errorCodes>101500,101501,101506,101507,101508,101503,50000</errorCodes>
<initialDuration>30</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>300</maximumDuration>
</suspendOnFailure>
</address>
</endpoint>
</send>
</inSequence>
<outSequence/>
</target>
</proxy>
Sequence1:
<sequence xmlns="http://ws.apache.org/ns/synapse"
name="TicketInsertionMobile_Seq31.0"
onError="fault">
<property name="messageType" value="application/json" scope="axis2"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Authentication"
expression="//Authentication/text()"/>
<switch xmlns:ns="http://org.apache.synapse/xsd"
source="boolean(get-property('Authentication'))">
<case regex="get-property(&apos;Authentication&apos;)=&apos;TRUE&apos;"/>
</switch>
<log level="custom">
<property name="LogLocation" value="TicketInsertionMobile_Seq3.0"/>
<property name="ProxyName" value="TicketInsertionMobileNew3.0"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Authentication"
expression="get-property('Authentication')"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Clientid"
expression="get-property('clientid')"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="requestMsgId"
expression="get-property('requestMsgId')"/>
</log>
<filter xmlns:ns="http://org.apache.synapse/xsd"
xpath="get-property('Authentication')='false'">
<then>
<payloadFactory>
<format>
<ResponseJSON xmlns="">
<Exception>Authentication Failed</Exception>
<Status>101503</Status>
</ResponseJSON>
</format>
<args/>
</payloadFactory>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<send/>
</then>
<else>
<payloadFactory media-type="xml">
<format>
<p:select_objectid_op xmlns:p="http://ws.wso2.org/dataservice">
<p:uuid>$1</p:uuid>
</p:select_objectid_op>
</format>
<args>
<arg evaluator="xml" expression="get-property('uuid')"/>
</args>
</payloadFactory>
<send receive="TicketInsertionMobile_Seq33.0">
<endpoint>
<address uri="http://localhost:9764/services/ttodo_DataServiceNew3.0/"
format="soap11">
<suspendOnFailure>
<errorCodes>101500,101501,101506,101507,101508,101503,50000</errorCodes>
<initialDuration>30</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>300</maximumDuration>
</suspendOnFailure>
</address>
</endpoint>
</send>
</else>
</filter>
</sequence>
Sequence2:
<sequence xmlns="http://ws.apache.org/ns/synapse"
name="TicketInsertionMobile_Seq33.0"
onError="fault">
<property name="messageType" value="application/json" scope="axis2"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property xmlns:f="http://ws.wso2.org/dataservice"
xmlns:ns="http://org.apache.synapse/xsd"
name="objectid"
expression="//f:Entry/f:objectid/text()"/>
<log level="custom">
<property name="LogLocation" value="TicketInsertionMobile_Seq3.0"/>
<property name="ProxyName" value="TicketInsertionMobileNew3.0"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="objectid"
expression="get-property('objectid')"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Clientid"
expression="get-property('clientid')"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="requestMsgId"
expression="get-property('requestMsgId')"/>
</log>
<filter xmlns:ns="http://org.apache.synapse/xsd"
xpath="get-property('objectid')=''">
<then>
<payloadFactory media-type="xml">
<format>
<p:insert_into_ttodo_seenuuid_op xmlns:p="http://ws.wso2.org/dataservice">
<p:clientid>$1</p:clientid>
<p:referencenumber>-1</p:referencenumber>
<p:referencedate>$2</p:referencedate>
<p:todoname>-$3</p:todoname>
<p:tododetails>$4</p:tododetails>
<p:activityid>-1</p:activityid>
<p:ouid>-1</p:ouid>
<p:partybranchid>$5</p:partybranchid>
<p:assetactivityid>-1</p:assetactivityid>
<p:todoplandate>$6</p:todoplandate>
<p:todoplanduration>-1</p:todoplanduration>
<p:assignedtoroleid>$7</p:assignedtoroleid>
<p:assignedtouserid>$8</p:assignedtouserid>
<p:assignedtousergroupid>$9</p:assignedtousergroupid>
<p:tags>$10</p:tags>
<p:createdbyid>$11</p:createdbyid>
<p:modifiedbyid>$12</p:modifiedbyid>
<p:todotype>1</p:todotype>
<p:todostatus>5</p:todostatus>
<p:uuid>$13</p:uuid>
<p:deviceid>$14</p:deviceid>
</p:insert_into_ttodo_seenuuid_op>
</format>
<args>
<arg evaluator="xml" expression="get-property('ClientId')"/>
<arg evaluator="xml" expression="get-property('Time')"/>
<arg evaluator="xml" expression="get-property('todoname')"/>
<arg evaluator="xml" expression="get-property('tododetails')"/>
<arg evaluator="xml" expression="get-property('PartyBranchId')"/>
<arg evaluator="xml" expression="get-property('Time')"/>
<arg evaluator="xml" expression="get-property('AssignedtoRoleId')"/>
<arg evaluator="xml" expression="get-property('AssignedtoUserId')"/>
<arg evaluator="xml" expression="get-property('AssignedtoUsergroupId')"/>
<arg evaluator="xml" expression="get-property('Tags')"/>
<arg evaluator="xml" expression="get-property('CreatedById')"/>
<arg evaluator="xml" expression="get-property('CreatedById')"/>
<arg evaluator="xml" expression="get-property('uuid')"/>
<arg evaluator="xml" expression="get-property('deviceid')"/>
</args>
</payloadFactory>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<send receive="TicketInsertionMobile_Seq32.0">
<endpoint>
<address uri="http://localhost:9764/services/ttodo_DataServiceNew3.0/" format="soap11">
<suspendOnFailure>
<errorCodes>101500,101501,101506,101507,101508,101503,50000</errorCodes>
<initialDuration>30</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>300</maximumDuration>
</suspendOnFailure>
</address>
</endpoint>
</send>
</then>
<else>
<payloadFactory media-type="xml">
<format>
<ResponseJSON xmlns="">
<Exception>Data Insertion Failed Due To Objectid Already Existing</Exception>
<Status>101503</Status>
</ResponseJSON>
</format>
<args/>
</payloadFactory>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<send/>
</else>
so when i call this proxy the insertion is not happening and my ESB is showing the following error
SequenceMediator Error while building message
org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag </body>; expected </HR>.
at [row,col {unknown-source}]: [20,187]
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
at org.apache.axiom.om.impl.llom.OMSerializableImpl.build(OMSerializableImpl.java:78)
at org.apache.axiom.om.impl.llom.OMElementImpl.build(OMElementImpl.java:722)
at org.apache.axiom.om.impl.llom.OMElementImpl.detach(OMElementImpl.java:700)
at org.apache.axiom.om.impl.llom.OMNodeImpl.setParent(OMNodeImpl.java:105)
at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:296)
at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:212)
at org.apache.axiom.soap.impl.llom.SOAPBodyImpl.addChild(SOAPBodyImpl.java:231)
at org.apache.axis2.transport.TransportUtils.createSOAPEnvelope(TransportUtils.java:161)
at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:121)
at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:91)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:62)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:114)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:232)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:443)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:166)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:222)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:701)
Caused by: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag </body>; expected </HR>.
at [row,col {unknown-source}]: [20,187]
at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:464)
at com.ctc.wstx.sr.BasicStreamReader.reportWrongEndElem(BasicStreamReader.java:3260)
at com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3187)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2806)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1062)
at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
at org.apache.axiom.util.stax.dialect.DisallowDoctypeDeclStreamReaderWrapper.next(DisallowDoctypeDeclStreamReaderWrapper.java:34)
at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)
... 21 more
And in wso2 dss as shown below
PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [bridgeservlet] in context with path [/] threw exception
java.lang.NullPointerException
at org.wso2.carbon.tracer.module.handler.AbstractTracingHandler.storeMessage(AbstractTracingHandler.java:81)
at org.wso2.carbon.tracer.module.handler.TracingMessageOutObservationHandler. invoke(TracingMessageOutObservationHandler.java:73)
at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340)
at org.apache.axis2.engine.Phase.invoke(Phase.java:313)
at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262)
at org.apache.axis2.engine.AxisEngine.sendFault(AxisEngine.java:516)
at org.apache.axis2.transport.http.AxisServlet.handleFault(AxisServlet.java:433)
at org.apache.axis2.transport.http.AxisServlet.processAxisFault(AxisServlet.java:398)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:188)
at org.wso2.carbon.core.transports.CarbonServlet.doPost(CarbonServlet.java:231)
But if i remove the format="soap11" from the addressurl in sequence2 then the process get successful an data is inserted into the table.
Please help me know why this error is occurring why exactly this Format="soap11" causing a problem.

org.springframework.security.oauth2.provider.endpoint.TokenEndpoint handleException

I'm using "Spring OAuth2 REST" code from http://www.e-zest.net/blog/rest-authentication-using-oauth-2-0-resource-owner-password-flow-protocol/#comment-5993 and developing to work with the latest version of Spring-Security-OAuth2 (which is v 2.0.7.RELEASE), but note that original code is works only for latest lower versions (which is 1.0.5.RELEASE) and not for latest. To use latest version's of dependencies I've modified below two files, remaining code from mentioned site / URL using as it is.
I'm using the following configuration:
<?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:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:sec="http://www.springframework.org/schema/security" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
<http pattern="/oauth/token" create-session="stateless" authentication-manager-ref="authenticationManager"
xmlns="http://www.springframework.org/schema/security" >
<intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<http pattern="/resources/**" create-session="never" entry-point-ref="oauthAuthenticationEntryPoint"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/resources/**" method="GET" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<http pattern="/logout" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/logout" method="GET" />
<sec:logout invalidate-session="true" logout-url="/logout" success-handler-ref="logoutSuccessHandler" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<bean id="logoutSuccessHandler" class="demo.oauth2.authentication.security.LogoutImpl" >
<property name="tokenstore" ref="tokenStore"></property>
</bean>
<bean id="oauthAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
</bean>
<bean id="clientAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="springsec/client" />
<property name="typeName" value="Basic" />
</bean>
<bean id="oauthAccessDeniedHandler"
class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler">
</bean>
<bean id="clientCredentialsTokenEndpointFilter"
class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<authentication-manager alias="authenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService" />
</authentication-manager>
<bean id="clientDetailsUserService"
class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetails" />
</bean>
<bean id="clientDetails" class="demo.oauth2.authentication.security.ClientDetailsServiceImpl"/>
<authentication-manager id="userAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider ref="customUserAuthenticationProvider">
</authentication-provider>
</authentication-manager>
<bean id="customUserAuthenticationProvider"
class="demo.oauth2.authentication.security.CustomUserAuthenticationProvider">
</bean>
<oauth:authorization-server
client-details-service-ref="clientDetails" token-services-ref="tokenServices">
<oauth:authorization-code />
<oauth:implicit/>
<oauth:refresh-token/>
<oauth:client-credentials />
<oauth:password authentication-manager-ref="userAuthenticationManager"/>
</oauth:authorization-server>
<oauth:resource-server id="resourceServerFilter"
resource-id="springsec" token-services-ref="tokenServices" />
<bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore" />
<bean id="tokenServices"
class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<property name="tokenStore" ref="tokenStore" />
<property name="supportRefreshToken" value="true" />
<property name="accessTokenValiditySeconds" value="300000"></property>
<property name="clientDetailsService" ref="clientDetails" />
</bean>
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<bean id="MyResource" class="demo.oauth2.authentication.resources.MyResource"></bean>
</beans>
and
package demo.oauth2.authentication.security;
import java.util.ArrayList;
import java.util.List;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.NoSuchClientException;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.stereotype.Service;
#Service
public class ClientDetailsServiceImpl implements ClientDetailsService {
private static final String CLIENT_CREDENTIALS = "client_credentials";
private static final String REFRESH_TOKEN = "refresh_token";
private static final String PASSWORD = "password";
#Override
public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
List<String> authorizedGrantTypes = new ArrayList<>();
authorizedGrantTypes.add(PASSWORD);
authorizedGrantTypes.add(REFRESH_TOKEN);
authorizedGrantTypes.add(CLIENT_CREDENTIALS);
if (clientId.equals("client1")) {
BaseClientDetails clientDetails = new BaseClientDetails();
clientDetails.setClientId("client1");
clientDetails.setClientSecret("client1");
clientDetails.setAuthorizedGrantTypes(authorizedGrantTypes);
return clientDetails;
}
else if(clientId.equals("client2")){
BaseClientDetails clientDetails = new BaseClientDetails();
clientDetails.setClientId("client2");
clientDetails.setClientSecret("client2");
clientDetails.setAuthorizedGrantTypes(authorizedGrantTypes);
return clientDetails;
}
else{
throw new NoSuchClientException("No client with requested id: " + clientId);
}
}
The code is giving error at above class. Also when I tried to execute following command from POSTMAN Rest Client
http://localhost:8080/demo.rest.springsecurity.oauth2.0.authentication/oauth/token?username=user1&password=user1&client_id=client1&client_secret=client1&grant_type=password
it give me the following errors. The main error on console:
Mar 26, 2015 4:57:40 PM org.springframework.security.oauth2.provider.endpoint.TokenEndpoint handleException
INFO: Handling error: InvalidScopeException, Empty scope (either the client or the user is not allowed the requested scopes)
This is the message from Postman Rest Client:
{
"error": "invalid_scope",
"error_description": "Empty scope (either the client or the user is not allowed the requested scopes)"
}
I got the solution to this problem. You need to specify the value for the scope like read,write,trust. For Ex:
http://localhost:8080/demo.rest.springsecurity.oauth2.0.authentication/oauth/token?username=user1&password=user1&client_id=client1&client_secret=client1&grant_type=password&scope=read,write,trust
Here is what I can access protected resources as well by providing access token
http://localhost:8080/demo.rest.springsecurity.oauth2.0.authentication/resources/MyResource/getMyInfo?access_token=27e28c65-5b18-4a0f-b55b-cfs2c5f6997b
This is really working very nice !!

How to skip batch step when condition is false

I have one basis job with one basic step. This jobs is executing every x second (I am using quartz for this). Then in my config class I also have variable "runStep". Where should I add this attribute and run my step only if runStep is true ?
<batch:job id="export1" parent="baseJob">
<batch:step id="registruj" parent="baseStep">
<tasklet>
<chunk reader="registrujReader" processor="registrujProcessor" writer="registrujWriter"
commit-interval="1" />
</tasklet>
</batch:step>
</batch:job>
<bean id="baseJob" class="org.springframework.batch.core.job.SimpleJob" abstract="true">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="baseStep" class="org.springframework.batch.core.step.factory.SimpleStepFactoryBean" abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="jobRepository" ref="jobRepository" />
<property name="startLimit" value="100" />
<property name="commitInterval" value="1" />
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
p:dataSource-ref="expDataSource" p:transactionManager-ref="transactionManager" />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry" />
</bean>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
<bean id="registrujWriter" class="cz.isvs.reg.rob.util.export.batch.RegistrujItemWriter" scope="step" />
<bean id="registrujReader" class="cz.isvs.reg.rob.util.export.batch.RegistrujItemReader" scope="step" />
<bean id="registrujProcessor" class="cz.isvs.reg.rob.util.export.batch.RegistrujItemProcessor" scope="step" />
<!-- run every 10 seconds -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<property name="cronExpression" value="*/10 * * * * ?" />
</bean>
</property>
</bean>
<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="cz.isvs.reg.rob.util.export.batch.JobLauncherDetails" />
<property name="group" value="quartz-batch" />
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="export1" />
<entry key="jobLocator" value-ref="jobRegistry" />
<entry key="jobLauncher" value-ref="jobLauncher" />
</map>
</property>
</bean>
Use a JobExecutionDecider
public class RunStepDecider implements JobExecutionDecider {
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
final String runStep = jobExecution.getJobParameters().getString("runStep");
//Depending on the above condition you can return Completed or Failed.
return new FlowExecutionStatus.COMPLETED;
}
}
<batch:job id="export1" parent="baseJob">
<decision id="decision" decider="decider">
<next on="COMPLETED" to="registruj" />
</decision>
<batch:step id="registruj" parent="baseStep">
<tasklet>
<chunk reader="registrujReader" processor="registrujProcessor" writer="registrujWriter" commit-interval="1" />
</tasklet>
</batch:step>
</batch:job>
<bean id="decider" class="RunStepDecider" />
and pass runStep as JobParameter.
Hope can help to solve your problem.