authentication - Spring security WSO2 IS integration - Figure out how to assign authorities/customize wso2 token -
i stuck issue couple of days.
so trying assign roles spring security framework. goal decode token wso2 identity server 5.0 through openid , assign role can authorize request based on roles (authorities)
this securityconfig class in simple spring boot app
@profile("oauth")
@configuration
@enableresourceserver
public class securityconfig {}
so, configuration, able decode token.
however, in debug mode, when made request id_token simple spring boot app, received error:
java.lang.classcastexception
java.lang.string cannot cast java.util.collection
and happens in defaultaccesstokenconverter class, particularly in line of code when map object converted string [] roles
public oauth2authentication extractauthentication(map<string, ?> map) { ... if (user==null && map.containskey(authorities)) { @suppresswarnings("unchecked") string[] roles = ((collection<string>)map.get(authorities)).toarray(new string[0]); authorities = authorityutils.createauthoritylist(roles); } oauth2request request = new oauth2request(parameters, clientid, authorities, true, scope, resourceids, null, null, null); return new oauth2authentication(request, user); }
this wso2 decoded token
{
"auth_time": 1464819792, "exp": 1464823490,
"azp": "u1pxsuyv_tdbermziohhnqogkwia",
"authorities": "[\"role_admin\",\"approver\",\"internal\/everyone\"]",
"at_hash": "hh2luzl3bp6ydqyzt4r6gg",
"aud": [
"u1pxsuyv_tdbermziohhnqogkwia"
],
"iss": "https://localhost:9443/oauth2/token", "locality": "[\"role_admin\"]", "iat": 1464819890 }
it seems spring expects array of string, not string object (there double quote @ beginning , end of value in authorities.
the aud format seems spring expects.
so, there 2 options can think o
1. write configuration in spring oauth2 (i have not figured out yet)
2. configure wso2 identity server (this i've been trying do).
there resources saying can implement our own jwttokengenerator in wso2 carbon. looking @ code, seems double quotes generated in claim.
org.wso2.carbon.identity.oauth2.authcontext.jwttokengenerator
i hope there else has been going through this.
thank much.
please find default implementation here [1]. better if can go 5.1.0 5.1.0 refer [2]. after building custom jwttokengenerator copy repository/components/lib. change
<tokengeneratorimplclass>
element in identity.xml according custom implementation.