Skip to content

Commit

Permalink
Merge pull request #16 from victornoel/issue-15-config-http-action-ad…
Browse files Browse the repository at this point in the history
…apter

Exploit Config's HttpActionAdapter
  • Loading branch information
victornoel authored Jan 30, 2017
2 parents 730b12d + 4cf9b46 commit 7ebf777
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/org/pac4j/jax/rs/filters/AbstractFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,23 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
filter(context);
}

/**
* Prefer to set a specific {@link HttpActionAdapter} on the {@link Config} instead of overriding this method.
*
* @return an {@link HttpActionAdapter}
*/
protected HttpActionAdapter<Object, JaxRsContext> adapter() {

final HttpActionAdapter adapter;
if (this.config.getHttpActionAdapter() != null) {
adapter = this.config.getHttpActionAdapter();
} else {
adapter = JaxRsHttpActionAdapter.INSTANCE;
}

return (code, context) -> {
if (skipResponse == null || !skipResponse) {
context.getRequestContext().abortWith(context.getAbortBuilder().build());
adapter.adapt(code, context);
}
return null;
};
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/pac4j/jax/rs/filters/JaxRsHttpActionAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.pac4j.jax.rs.filters;

import org.pac4j.core.http.HttpActionAdapter;
import org.pac4j.jax.rs.pac4j.JaxRsContext;

/**
*
* @author Victor Noel - Linagora
* @since 1.1.1
*
*/
public class JaxRsHttpActionAdapter implements HttpActionAdapter<Object, JaxRsContext> {

public static final JaxRsHttpActionAdapter INSTANCE = new JaxRsHttpActionAdapter();

@Override
public Object adapt(int code, JaxRsContext context) {
context.getRequestContext().abortWith(context.getAbortBuilder().build());
return null;
}

}

0 comments on commit 7ebf777

Please sign in to comment.