RoleAuthority implements Authority, AuthorityKeyStore { boolean isWriteOperation(String httpMethod) { if (httpMethod == null) { return false; } return httpMethod.equalsIgnoreCase("PUT") || httpMethod.equalsIgnoreCase("POST") || httpMethod.equalsIgnoreCase("DELETE"); } RoleAuthority(); @Override String getID(); @Override void initialize(); @Override String getDomain(); @Override String getHeader(); @Override String getAuthenticateChallenge(); @Override Principal authenticate(String signedToken, String remoteAddr, String httpMethod, StringBuilder errMsg); @Override void setKeyStore(KeyStore keyStore); final static String SYS_AUTH_DOMAIN; final static String ZTS_SERVICE_NAME; static final String HTTP_HEADER; static final String ATHENZ_AUTH_CHALLENGE; static final String ATHENZ_PROP_ROLE_HEADER; }
@Test public void testIsWriteOperation() { PrincipalAuthority serviceAuthority = new PrincipalAuthority(); assertTrue(serviceAuthority.isWriteOperation("PUT")); assertTrue(serviceAuthority.isWriteOperation("put")); assertTrue(serviceAuthority.isWriteOperation("Post")); assertTrue(serviceAuthority.isWriteOperation("POST")); assertTrue(serviceAuthority.isWriteOperation("DeLete")); assertTrue(serviceAuthority.isWriteOperation("DELETE")); assertFalse(serviceAuthority.isWriteOperation("GET")); assertFalse(serviceAuthority.isWriteOperation("Get")); assertFalse(serviceAuthority.isWriteOperation("HEAD")); assertFalse(serviceAuthority.isWriteOperation(null)); assertFalse(serviceAuthority.isWriteOperation("Unknown")); assertFalse(serviceAuthority.isWriteOperation("")); }