橘希尔芬福特
橘希尔芬福特

Reputation: 1

How to use RESTful Service Registry in Apereo CAS7.0

I'm configuring CAS v7.0 to use RESTful Service Registry based on this documentation (https://apereo.github.io/cas/7.0.x/services/REST-Service-Management.html).

When I run CAS server source code, I got error like this.

ERROR o.a.c.u.s.AbstractJacksonBackedStringSerializer - Cannot read/parse [[{"acceptableUsagePolicy":{"enabled":true},"accessStrategy":{"caseInsensitive":false,"delegatedAuthenticationPolicy":{"exc...] to deserialize into List of type [interface org.apereo.cas.services.RegisteredService].Internal parsing error is [Unexpected token (START_OBJECT), expected VALUE_STRING: need String, Number of Boolean value that contains type id (for subtype of java.util.List)
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 2]]
ERROR o.a.c.s.RestfulServiceRegistry - Cannot invoke "java.util.List.stream()" because "services" is null
    RestfulServiceRegistry.java:load:144
    ReferencePipeline.java:accept:197
    ArrayList.java:forEachRemaining:1708

My code is like this:

By viewing the document(https://apereo.github.io/cas/7.0.x/services/REST-Service-Management.html). I found restfulApi returned need is Collection of RegisteredService objects. So, I defined a spring boot controller as below.

@Controller
public class RegistrationServiceController {
    @GetMapping ("/gtapi/getCustomServices")
    public void getCustomServices(HttpServletRequest request, HttpServletResponse response) throws IOException {

        response.setContentType("application/json;charset=UTF-8");
        response.setStatus(HttpServletResponse.SC_OK);
        response.setCharacterEncoding("UTF-8");

        Collection<RegisteredService> list2 = new ArrayList<>();
        //List<RegisteredService> list = new ArrayList<>();

        CasRegisteredService item1 = new CasRegisteredService();
        item1.setServiceId("^(https|http|imaps)://.*");
        item1.setId(10000005);
        item1.setDescription("这是一个测试授权的地址配置");
        item1.setName("Test");
        list2.add(item1);

        CasRegisteredService item2 = new CasRegisteredService();
        item2.setServiceId("^https://www.weibo.com.*");
        item2.setId(10000006);
        item2.setDescription("这是一个测试授权的地址配置");
        item2.setName("Test");
        list2.add(item2);

        String str = JSON.toJSONString(list2);
        response.getWriter().write(str);
    }
}

I can get "/gtapi/getCustomServices" in CAS7.0. it return a json string. Then I configure it in application.properties as below.

cas.service-registry.rest.url=http://localhost:8443/cas/gtapi/getCustomServices

But always fail. CAS7.0 can not load Service Registry By this url.

May I ask how to compile this controller? What type should this controller return ?

I want to compile an restfulApi in CAS or other Spring projects. And CAS can RESTful Service Registry

Upvotes: 0

Views: 62

Answers (0)

Related Questions