updated to get middleware working

This commit is contained in:
Derrick Johnson 2014-06-02 12:13:13 -04:00
parent 77d6f82ccd
commit 648bb38cd8
8 changed files with 36 additions and 3 deletions

BIN
etc/security/keystore.jks Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

9
etc/security/project Normal file

File diff suppressed because one or more lines are too long

BIN
etc/security/truststore.jks Normal file

Binary file not shown.

View File

@ -120,6 +120,8 @@ public class MonApiApplication extends Application<MonApiConfiguration> {
authInitParams.put("ConnPoolMinIdleTime", config.middleware.connPoolMinIdleTime);
authInitParams.put("ConnRetryTimes", config.middleware.connRetryTimes);
authInitParams.put("ConnRetryInterval", config.middleware.connRetryInterval);
authInitParams.put("AdminToken", config.middleware.adminToken);
Dynamic tokenAuthFilter = environment.servlets().addFilter("token-auth", new TokenAuth());
tokenAuthFilter.addMappingForUrlPatterns(null, true, "/");
@ -131,8 +133,10 @@ public class MonApiApplication extends Application<MonApiConfiguration> {
mockAuthenticationFilter.addMappingForUrlPatterns(null, true, "/");
mockAuthenticationFilter.addMappingForUrlPatterns(null, true, "/v2.0/*");
}
ArrayList<String> list = new ArrayList();
list.add("heat_stack_owner");
Dynamic postAuthenticationFilter = environment.servlets()
.addFilter("post-auth", new PostAuthenticationFilter(Collections.<String>singletonList("")));
.addFilter("post-auth", new PostAuthenticationFilter(list));//Collections.<String>singletonList("")));
postAuthenticationFilter.addMappingForUrlPatterns(null, true, "/");
postAuthenticationFilter.addMappingForUrlPatterns(null, true, "/v2.0/*");

View File

@ -45,5 +45,6 @@ public class MiddlewareConfiguration {
@NotEmpty @JsonProperty public String connPoolMinIdleTime;
@NotEmpty @JsonProperty public String connRetryTimes;
@NotEmpty @JsonProperty public String connRetryInterval;
@NotEmpty @JsonProperty public String adminToken;
@NotNull @JsonProperty public List<String> rolesToMatch;
}

View File

@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
import com.hpcloud.mon.resource.exception.Exceptions;
import com.hpcloud.mon.resource.exception.Exceptions.FaultType;
import com.hp.csbu.cc.middleware.ExceptionHandler.*;
/**
* Authenticates requests using header information from the CsMiddleware. Provides the X-TENANT-ID
@ -95,9 +96,27 @@ public class PreAuthenticationFilter implements Filter {
res.setContentType(MediaType.APPLICATION_JSON);
res.setStatus(responseWrapper.statusCode);
String output = Exceptions.buildLoggedErrorMessage(FaultType.UNAUTHORIZED,
responseWrapper.errorMessage, null, responseWrapper.exception);
responseWrapper.errorMessage, null, responseWrapper.exception);
out.print(output);
} catch (Exception e) {
}catch(IllegalArgumentException e) {
//CSMiddleware is throwing this error for invalid tokens.
//This problem appears to be fixed in other versions, but they are not approved yet.
try {
String output = Exceptions.buildLoggedErrorMessage(FaultType.UNAUTHORIZED,
"invalid authToken", null, responseWrapper.exception);
out.print(output);
}
catch (Exception x) {
LOG.error("Error while writing failed authentication HTTP response", x);
} finally {
if (out != null)
try {
out.close();
} catch (IOException ignore) {
}
}
}
catch (Exception e) {
LOG.error("Error while writing failed authentication HTTP response", e);
} finally {
if (out != null)