@Test public void testCreateKerberosSecurityWithoutDescriptor() throws Exception { Map<String, Object> reuqestMap = new HashMap<>(); Map<String, Object> security = new HashMap<>(); security.put(SecurityConfigurationFactory.TYPE_PROPERTY_ID, SecurityType.KERBEROS.toString()); reuqestMap.put(SecurityConfigurationFactory.SECURITY_PROPERTY_ID, security); SecurityConfiguration securityConfiguration = testSubject.createSecurityConfigurationFromRequest(reuqestMap, false); assertTrue(securityConfiguration.getType() == SecurityType.KERBEROS); }
public SecurityConfiguration createSecurityConfigurationFromRequest(Map<String, Object> properties, boolean persistEmbeddedDescriptor) { SecurityConfiguration securityConfiguration = null; LOGGER.debug("Creating security configuration from properties: {}", properties); Map<String, Object> securityProperties = (Map<String, Object>) properties.get(SECURITY_PROPERTY_ID); if (securityProperties == null) { LOGGER.debug("No security information properties provided, returning null"); return securityConfiguration; } String securityTypeString = Strings.emptyToNull((String) securityProperties.get(TYPE_PROPERTY_ID)); if (securityTypeString == null) { LOGGER.error("Type is missing from security block."); throw new IllegalArgumentException("Type missing from security block."); } SecurityType securityType = Enums.getIfPresent(SecurityType.class, securityTypeString).orNull(); if (securityType == null) { LOGGER.error("Unsupported security type specified: {}", securityType); throw new IllegalArgumentException("Invalid security type specified: " + securityTypeString); } if (securityType == SecurityType.KERBEROS) { String descriptorReference = Strings.emptyToNull((String) securityProperties.get(KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID)); Object descriptorJsonMap = securityProperties.get(KERBEROS_DESCRIPTOR_PROPERTY_ID); if (descriptorReference != null && descriptorJsonMap != null) { LOGGER.error("Both kerberos descriptor and kerberos descriptor reference are set in the security configuration!"); throw new IllegalArgumentException("Usage of properties : " + KERBEROS_DESCRIPTOR_PROPERTY_ID + " and " + KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID + " at the same time, is not allowed."); } String descriptorText = null; if (descriptorJsonMap != null) { LOGGER.debug("Found embedded descriptor: {}", descriptorJsonMap); descriptorText = jsonSerializer.<Map<String, Object>>toJson(descriptorJsonMap, Map.class); if (persistEmbeddedDescriptor) { descriptorReference = persistKerberosDescriptor(descriptorText); } securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS, descriptorReference, descriptorText); } else if (descriptorReference != null) { LOGGER.debug("Found descriptor reference: {}", descriptorReference); securityConfiguration = loadSecurityConfigurationByReference(descriptorReference); } else { LOGGER.debug("There is no security descriptor found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS); } } else { LOGGER.debug("There is no security configuration found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.NONE); } return securityConfiguration; }
SecurityConfigurationFactory { public SecurityConfiguration createSecurityConfigurationFromRequest(Map<String, Object> properties, boolean persistEmbeddedDescriptor) { SecurityConfiguration securityConfiguration = null; LOGGER.debug("Creating security configuration from properties: {}", properties); Map<String, Object> securityProperties = (Map<String, Object>) properties.get(SECURITY_PROPERTY_ID); if (securityProperties == null) { LOGGER.debug("No security information properties provided, returning null"); return securityConfiguration; } String securityTypeString = Strings.emptyToNull((String) securityProperties.get(TYPE_PROPERTY_ID)); if (securityTypeString == null) { LOGGER.error("Type is missing from security block."); throw new IllegalArgumentException("Type missing from security block."); } SecurityType securityType = Enums.getIfPresent(SecurityType.class, securityTypeString).orNull(); if (securityType == null) { LOGGER.error("Unsupported security type specified: {}", securityType); throw new IllegalArgumentException("Invalid security type specified: " + securityTypeString); } if (securityType == SecurityType.KERBEROS) { String descriptorReference = Strings.emptyToNull((String) securityProperties.get(KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID)); Object descriptorJsonMap = securityProperties.get(KERBEROS_DESCRIPTOR_PROPERTY_ID); if (descriptorReference != null && descriptorJsonMap != null) { LOGGER.error("Both kerberos descriptor and kerberos descriptor reference are set in the security configuration!"); throw new IllegalArgumentException("Usage of properties : " + KERBEROS_DESCRIPTOR_PROPERTY_ID + " and " + KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID + " at the same time, is not allowed."); } String descriptorText = null; if (descriptorJsonMap != null) { LOGGER.debug("Found embedded descriptor: {}", descriptorJsonMap); descriptorText = jsonSerializer.<Map<String, Object>>toJson(descriptorJsonMap, Map.class); if (persistEmbeddedDescriptor) { descriptorReference = persistKerberosDescriptor(descriptorText); } securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS, descriptorReference, descriptorText); } else if (descriptorReference != null) { LOGGER.debug("Found descriptor reference: {}", descriptorReference); securityConfiguration = loadSecurityConfigurationByReference(descriptorReference); } else { LOGGER.debug("There is no security descriptor found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS); } } else { LOGGER.debug("There is no security configuration found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.NONE); } return securityConfiguration; } }
SecurityConfigurationFactory { public SecurityConfiguration createSecurityConfigurationFromRequest(Map<String, Object> properties, boolean persistEmbeddedDescriptor) { SecurityConfiguration securityConfiguration = null; LOGGER.debug("Creating security configuration from properties: {}", properties); Map<String, Object> securityProperties = (Map<String, Object>) properties.get(SECURITY_PROPERTY_ID); if (securityProperties == null) { LOGGER.debug("No security information properties provided, returning null"); return securityConfiguration; } String securityTypeString = Strings.emptyToNull((String) securityProperties.get(TYPE_PROPERTY_ID)); if (securityTypeString == null) { LOGGER.error("Type is missing from security block."); throw new IllegalArgumentException("Type missing from security block."); } SecurityType securityType = Enums.getIfPresent(SecurityType.class, securityTypeString).orNull(); if (securityType == null) { LOGGER.error("Unsupported security type specified: {}", securityType); throw new IllegalArgumentException("Invalid security type specified: " + securityTypeString); } if (securityType == SecurityType.KERBEROS) { String descriptorReference = Strings.emptyToNull((String) securityProperties.get(KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID)); Object descriptorJsonMap = securityProperties.get(KERBEROS_DESCRIPTOR_PROPERTY_ID); if (descriptorReference != null && descriptorJsonMap != null) { LOGGER.error("Both kerberos descriptor and kerberos descriptor reference are set in the security configuration!"); throw new IllegalArgumentException("Usage of properties : " + KERBEROS_DESCRIPTOR_PROPERTY_ID + " and " + KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID + " at the same time, is not allowed."); } String descriptorText = null; if (descriptorJsonMap != null) { LOGGER.debug("Found embedded descriptor: {}", descriptorJsonMap); descriptorText = jsonSerializer.<Map<String, Object>>toJson(descriptorJsonMap, Map.class); if (persistEmbeddedDescriptor) { descriptorReference = persistKerberosDescriptor(descriptorText); } securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS, descriptorReference, descriptorText); } else if (descriptorReference != null) { LOGGER.debug("Found descriptor reference: {}", descriptorReference); securityConfiguration = loadSecurityConfigurationByReference(descriptorReference); } else { LOGGER.debug("There is no security descriptor found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS); } } else { LOGGER.debug("There is no security configuration found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.NONE); } return securityConfiguration; } SecurityConfigurationFactory(); protected  SecurityConfigurationFactory(Gson jsonSerializer, KerberosDescriptorDAO kerberosDescriptorDAO, KerberosDescriptorFactory kerberosDescriptorFactory); }
SecurityConfigurationFactory { public SecurityConfiguration createSecurityConfigurationFromRequest(Map<String, Object> properties, boolean persistEmbeddedDescriptor) { SecurityConfiguration securityConfiguration = null; LOGGER.debug("Creating security configuration from properties: {}", properties); Map<String, Object> securityProperties = (Map<String, Object>) properties.get(SECURITY_PROPERTY_ID); if (securityProperties == null) { LOGGER.debug("No security information properties provided, returning null"); return securityConfiguration; } String securityTypeString = Strings.emptyToNull((String) securityProperties.get(TYPE_PROPERTY_ID)); if (securityTypeString == null) { LOGGER.error("Type is missing from security block."); throw new IllegalArgumentException("Type missing from security block."); } SecurityType securityType = Enums.getIfPresent(SecurityType.class, securityTypeString).orNull(); if (securityType == null) { LOGGER.error("Unsupported security type specified: {}", securityType); throw new IllegalArgumentException("Invalid security type specified: " + securityTypeString); } if (securityType == SecurityType.KERBEROS) { String descriptorReference = Strings.emptyToNull((String) securityProperties.get(KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID)); Object descriptorJsonMap = securityProperties.get(KERBEROS_DESCRIPTOR_PROPERTY_ID); if (descriptorReference != null && descriptorJsonMap != null) { LOGGER.error("Both kerberos descriptor and kerberos descriptor reference are set in the security configuration!"); throw new IllegalArgumentException("Usage of properties : " + KERBEROS_DESCRIPTOR_PROPERTY_ID + " and " + KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID + " at the same time, is not allowed."); } String descriptorText = null; if (descriptorJsonMap != null) { LOGGER.debug("Found embedded descriptor: {}", descriptorJsonMap); descriptorText = jsonSerializer.<Map<String, Object>>toJson(descriptorJsonMap, Map.class); if (persistEmbeddedDescriptor) { descriptorReference = persistKerberosDescriptor(descriptorText); } securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS, descriptorReference, descriptorText); } else if (descriptorReference != null) { LOGGER.debug("Found descriptor reference: {}", descriptorReference); securityConfiguration = loadSecurityConfigurationByReference(descriptorReference); } else { LOGGER.debug("There is no security descriptor found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS); } } else { LOGGER.debug("There is no security configuration found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.NONE); } return securityConfiguration; } SecurityConfigurationFactory(); protected  SecurityConfigurationFactory(Gson jsonSerializer, KerberosDescriptorDAO kerberosDescriptorDAO, KerberosDescriptorFactory kerberosDescriptorFactory); SecurityConfiguration createSecurityConfigurationFromRequest(Map<String, Object> properties, boolean
    persistEmbeddedDescriptor); SecurityConfiguration loadSecurityConfigurationByReference(String reference); }
SecurityConfigurationFactory { public SecurityConfiguration createSecurityConfigurationFromRequest(Map<String, Object> properties, boolean persistEmbeddedDescriptor) { SecurityConfiguration securityConfiguration = null; LOGGER.debug("Creating security configuration from properties: {}", properties); Map<String, Object> securityProperties = (Map<String, Object>) properties.get(SECURITY_PROPERTY_ID); if (securityProperties == null) { LOGGER.debug("No security information properties provided, returning null"); return securityConfiguration; } String securityTypeString = Strings.emptyToNull((String) securityProperties.get(TYPE_PROPERTY_ID)); if (securityTypeString == null) { LOGGER.error("Type is missing from security block."); throw new IllegalArgumentException("Type missing from security block."); } SecurityType securityType = Enums.getIfPresent(SecurityType.class, securityTypeString).orNull(); if (securityType == null) { LOGGER.error("Unsupported security type specified: {}", securityType); throw new IllegalArgumentException("Invalid security type specified: " + securityTypeString); } if (securityType == SecurityType.KERBEROS) { String descriptorReference = Strings.emptyToNull((String) securityProperties.get(KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID)); Object descriptorJsonMap = securityProperties.get(KERBEROS_DESCRIPTOR_PROPERTY_ID); if (descriptorReference != null && descriptorJsonMap != null) { LOGGER.error("Both kerberos descriptor and kerberos descriptor reference are set in the security configuration!"); throw new IllegalArgumentException("Usage of properties : " + KERBEROS_DESCRIPTOR_PROPERTY_ID + " and " + KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID + " at the same time, is not allowed."); } String descriptorText = null; if (descriptorJsonMap != null) { LOGGER.debug("Found embedded descriptor: {}", descriptorJsonMap); descriptorText = jsonSerializer.<Map<String, Object>>toJson(descriptorJsonMap, Map.class); if (persistEmbeddedDescriptor) { descriptorReference = persistKerberosDescriptor(descriptorText); } securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS, descriptorReference, descriptorText); } else if (descriptorReference != null) { LOGGER.debug("Found descriptor reference: {}", descriptorReference); securityConfiguration = loadSecurityConfigurationByReference(descriptorReference); } else { LOGGER.debug("There is no security descriptor found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS); } } else { LOGGER.debug("There is no security configuration found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.NONE); } return securityConfiguration; } SecurityConfigurationFactory(); protected  SecurityConfigurationFactory(Gson jsonSerializer, KerberosDescriptorDAO kerberosDescriptorDAO, KerberosDescriptorFactory kerberosDescriptorFactory); SecurityConfiguration createSecurityConfigurationFromRequest(Map<String, Object> properties, boolean
    persistEmbeddedDescriptor); SecurityConfiguration loadSecurityConfigurationByReference(String reference); static final String SECURITY_PROPERTY_ID; static final String TYPE_PROPERTY_ID; static final String KERBEROS_DESCRIPTOR_PROPERTY_ID; static final String KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID; }