@Test public void testNoPasswordConfiguredContextAllows() { new AdminServerCredentialVerifier(new AdminServerConfig(), HTTP_SERVER_CONFIG) .authenticate(SECURITY_CONTEXT_ALLOW, null); }
public void authenticate(SecurityContext securityContext, String authHeader) { if (!httpsEnabled) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("HTTPS not enabled") .build()); } if (securityContext.isUserInRole("server.admin") && !"none".equals(securityContext.getAuthenticationScheme())) { return; } if (username == null || password == null) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("Administrator password not configured") .build()); } if (authHeader == null || !authHeader.startsWith("Basic ")) { unauthorized(); } String credentials = new String(decoder.decode(authHeader.substring("Basic ".length())), UTF_8); int index = credentials.indexOf(':'); if (index < 0 || !username.equals(credentials.substring(0, index)) || !password.equals(credentials.substring(index + 1))) { unauthorized(); } }
AdminServerCredentialVerifier { public void authenticate(SecurityContext securityContext, String authHeader) { if (!httpsEnabled) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("HTTPS not enabled") .build()); } if (securityContext.isUserInRole("server.admin") && !"none".equals(securityContext.getAuthenticationScheme())) { return; } if (username == null || password == null) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("Administrator password not configured") .build()); } if (authHeader == null || !authHeader.startsWith("Basic ")) { unauthorized(); } String credentials = new String(decoder.decode(authHeader.substring("Basic ".length())), UTF_8); int index = credentials.indexOf(':'); if (index < 0 || !username.equals(credentials.substring(0, index)) || !password.equals(credentials.substring(index + 1))) { unauthorized(); } } }
AdminServerCredentialVerifier { public void authenticate(SecurityContext securityContext, String authHeader) { if (!httpsEnabled) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("HTTPS not enabled") .build()); } if (securityContext.isUserInRole("server.admin") && !"none".equals(securityContext.getAuthenticationScheme())) { return; } if (username == null || password == null) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("Administrator password not configured") .build()); } if (authHeader == null || !authHeader.startsWith("Basic ")) { unauthorized(); } String credentials = new String(decoder.decode(authHeader.substring("Basic ".length())), UTF_8); int index = credentials.indexOf(':'); if (index < 0 || !username.equals(credentials.substring(0, index)) || !password.equals(credentials.substring(index + 1))) { unauthorized(); } } @Inject  AdminServerCredentialVerifier(AdminServerConfig adminServerConfig, HttpServerConfig httpServerConfig); }
AdminServerCredentialVerifier { public void authenticate(SecurityContext securityContext, String authHeader) { if (!httpsEnabled) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("HTTPS not enabled") .build()); } if (securityContext.isUserInRole("server.admin") && !"none".equals(securityContext.getAuthenticationScheme())) { return; } if (username == null || password == null) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("Administrator password not configured") .build()); } if (authHeader == null || !authHeader.startsWith("Basic ")) { unauthorized(); } String credentials = new String(decoder.decode(authHeader.substring("Basic ".length())), UTF_8); int index = credentials.indexOf(':'); if (index < 0 || !username.equals(credentials.substring(0, index)) || !password.equals(credentials.substring(index + 1))) { unauthorized(); } } @Inject  AdminServerCredentialVerifier(AdminServerConfig adminServerConfig, HttpServerConfig httpServerConfig); void authenticate(SecurityContext securityContext, String authHeader); }
AdminServerCredentialVerifier { public void authenticate(SecurityContext securityContext, String authHeader) { if (!httpsEnabled) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("HTTPS not enabled") .build()); } if (securityContext.isUserInRole("server.admin") && !"none".equals(securityContext.getAuthenticationScheme())) { return; } if (username == null || password == null) { throw new WebApplicationException(Response.status(FORBIDDEN) .header("Content-Type", "text/plain") .entity("Administrator password not configured") .build()); } if (authHeader == null || !authHeader.startsWith("Basic ")) { unauthorized(); } String credentials = new String(decoder.decode(authHeader.substring("Basic ".length())), UTF_8); int index = credentials.indexOf(':'); if (index < 0 || !username.equals(credentials.substring(0, index)) || !password.equals(credentials.substring(index + 1))) { unauthorized(); } } @Inject  AdminServerCredentialVerifier(AdminServerConfig adminServerConfig, HttpServerConfig httpServerConfig); void authenticate(SecurityContext securityContext, String authHeader);  }