Skip to content
Permalink
Browse files
o new interceptor to set the HTTP status code based on the FortRespon…
…se (FC-258)

o set the HTTP sttus code while creating the error response
o updated the version of realm
o added new interceptor to the application context
  • Loading branch information
kayyagari committed Mar 3, 2019
1 parent 8369a81 commit c06b53c7fb546eab0120cd79f629a6f6456808b6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
@@ -93,7 +93,7 @@
<title>${project.name} ${project.version}</title>

<!-- Dependencies version -->
<fortress.realm.version>2.0.3</fortress.realm.version>
<fortress.realm.version>2.0.4-SNAPSHOT</fortress.realm.version>
<cxf.version>3.2.6</cxf.version>
<httpclient.version>3.1</httpclient.version>
<java.version>1.8</java.version>
@@ -44,6 +44,7 @@ protected void createError( FortResponse response, Logger LOG, SecurityException
LOG.info( "Caught " + se );
response.setErrorCode( se.getErrorId() );
response.setErrorMessage( se.getMessage() );
response.setHttpStatus(se.getHttpStatus());
}


@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.directory.fortress.rest;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageContentsList;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.directory.fortress.core.model.FortResponse;

/**
* Interceptor to set the HTTP Status code based on the value present in FortResponse.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class FortressResponseInterceptor extends AbstractPhaseInterceptor<Message>
{
public FortressResponseInterceptor()
{
super(Phase.MARSHAL);
addBefore(JAXRSOutInterceptor.class.getName());
}

@Override
public void handleMessage(Message message) throws Fault
{
boolean isOutbound = false;
if( ( message == message.getExchange().getOutMessage() ) || ( message == message.getExchange().getOutFaultMessage() ) )
{
isOutbound = true;
}

if( isOutbound )
{
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs != null && !objs.isEmpty())
{
Object o = objs.get(0);
if( o instanceof FortResponse )
{
message.getExchange().put( Message.RESPONSE_CODE, ((FortResponse)o).getHttpStatus() );
}
}
}
}
}
@@ -45,6 +45,8 @@ under the License.
<constructor-arg ref="customMapper"/>
</bean>

<bean id="fortressResponseInterceptor" class="org.apache.directory.fortress.rest.FortressResponseInterceptor"/>

<jaxrs:server id="restContainer" address="/">
<jaxrs:serviceBeans>
<ref bean="fortressService"/>
@@ -54,6 +56,10 @@ under the License.
<ref bean="annotationsInterceptor"/>
</jaxrs:inInterceptors>

<jaxrs:outInterceptors>
<ref bean="fortressResponseInterceptor"/>
</jaxrs:outInterceptors>

<jaxrs:outFaultInterceptors>
<bean class="org.apache.directory.fortress.rest.SecurityOutFaultInterceptor"/>
</jaxrs:outFaultInterceptors>

0 comments on commit c06b53c

Please sign in to comment.