0
인증 및 권한 부여가있는 Embedded Jetty로 첫 번째 Restful 웹 서비스를 만들고 있는데, 필자는 사용자 객체 (Employee)를 삽입하려는 필터를 가지고 있습니다. ResteasyProviderFactory.pushContext() @Context 어노테이션을 사용하여 서비스 빈에서 검색하지만, 객체를 항상 시도하는 것은 null입니다. 나는 어떤 종류의 도움을 주셔서 감사하겠습니다.REST-ful webservice @Context Injection은 항상 null을 반환합니다.
@PreMatching
public class AuthenticationHandler implements ContainerRequestFilter {
@Inject private PxCredentialService credentialService;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Response faultresponse = createFaultResponse();
String authorization = requestContext.getHeaderString("Authorization");
String[] parts = authorization.split(" ");
if (parts.length != 2 || !"Basic".equals(parts[0])) {
requestContext.abortWith(createFaultResponse());
return;
}
String decodedValue = null;
try {
decodedValue = new String(Base64Utility.decode(parts[1]));
} catch (Base64Exception ex) {
requestContext.abortWith(createFaultResponse());
return;
}
String[] namePassword = decodedValue.split(":");
Employee emp = credentialService.getCredentialsByLoginAndPass(namePassword[0], namePassword[1], true);
if (emp != null) {
ResteasyProviderFactory.pushContext(Employee.class, emp);
} else {
throw new NullPointerException("False Login");//requestContext.abortWith(Response.status(401).build());
}
}
@Path("/people")
public class PeopleRestService implements credentials {
@Inject private PeopleService peopleService;
@Inject private GenericUserRightsUtil genericUserRightsUtil;
@Produces({ "application/json" })
@GET
public Collection<Person> getPeople(@Context Employee emp) {
Employee emp = (Employee)crc.getProperty("Employee");
return peopleService.getPeople(page, 5);
}
} 나의 이해에