@SuppressWarnings("unchecked") IdentityConfiguration(String name, List<? extends IdentityStoreConfiguration> identityStores, RelationshipPolicy relationshipPolicy) { if (name == null) { throw new SecurityConfigurationException("You must specify a name for the IdentityConfiguration."); } this.name = name; this.storeConfiguration = unmodifiableList(identityStores); this.relationshipPolicy = relationshipPolicy; }
@Override public final SecurityConfigurationException idmJpaStartFailed(final Throwable e) { final SecurityConfigurationException result = new SecurityConfigurationException(String.format(getLoggingLocale(), idmJpaStartFailed$str()), e); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String idmJpaEMFLookupFailed = "WFLYPL0052: Could not lookup EntityManagerFactory [%s].";
@Override protected void validate() { if (this.supportedTypes.isEmpty()) { throw new SecurityConfigurationException("The store configuration must have at least one supported type."); } }
@Override public final SecurityConfigurationException idmJpaFailedCreateTransactionEntityManager(final Exception e) { final SecurityConfigurationException result = new SecurityConfigurationException(String.format(getLoggingLocale(), idmJpaFailedCreateTransactionEntityManager$str()), e); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String idmNoIdentityConfigurationProvided = "WFLYPL0054: You must provide at least one identity configuration.";
@SuppressWarnings("unchecked") IdentityConfiguration(String name, List<? extends IdentityStoreConfiguration> identityStores, RelationshipPolicy relationshipPolicy) { if (name == null) { throw new SecurityConfigurationException("You must specify a name for the IdentityConfiguration."); } this.name = name; this.storeConfiguration = unmodifiableList(identityStores); this.relationshipPolicy = relationshipPolicy; }
@Override public final SecurityConfigurationException idmJpaEntityModuleNotFound(final String entityModuleName) { final SecurityConfigurationException result = new SecurityConfigurationException(String.format(getLoggingLocale(), idmJpaEntityModuleNotFound$str(), entityModuleName)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String idmJpaStartFailed = "WFLYPL0051: Could not configure JPA store.";
@Override protected void validate() { if (this.supportedTypes.isEmpty()) { throw new SecurityConfigurationException("The store configuration must have at least one supported type."); } }
@Override public final SecurityConfigurationException idmJpaEMFLookupFailed(final String entityManagerFactoryJndiName) { final SecurityConfigurationException result = new SecurityConfigurationException(String.format(getLoggingLocale(), idmJpaEMFLookupFailed$str(), entityManagerFactoryJndiName)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String idmJpaFailedCreateTransactionEntityManager = "WFLYPL0053: Could not create transactional EntityManager.";
private EntityManagerFactory lookupEntityManagerFactory() { try { return (EntityManagerFactory) new InitialContext().lookup(this.entityManagerFactoryJndiName); } catch (NamingException e) { throw new SecurityConfigurationException("Could not lookup EntityManagerFactory [" + this.entityManagerFactoryJndiName + "]."); } }
@Override public final SecurityConfigurationException idmJpaEntityModuleNotFound(final String entityModuleName) { final SecurityConfigurationException result = new SecurityConfigurationException(String.format(getLoggingLocale(), idmJpaEntityModuleNotFound$str(), entityModuleName)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String idmJpaStartFailed = "WFLYPL0051: Could not configure JPA store.";
@Override protected void validate() { super.validate(); if (this.asyncWriteThreadPool <= 0) { throw new SecurityConfigurationException("The thread pool size must be greater than zero."); } }
@Override public final SecurityConfigurationException idmJpaStartFailed(final Throwable e) { final SecurityConfigurationException result = new SecurityConfigurationException(String.format(getLoggingLocale(), idmJpaStartFailed$str()), e); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String idmJpaEMFLookupFailed = "WFLYPL0052: Could not lookup EntityManagerFactory [%s].";
@Override protected void validate() { super.validate(); if (this.asyncWriteThreadPool <= 0) { throw new SecurityConfigurationException("The thread pool size must be greater than zero."); } }
@Override public final SecurityConfigurationException idmJpaFailedCreateTransactionEntityManager(final Exception e) { final SecurityConfigurationException result = new SecurityConfigurationException(String.format(getLoggingLocale(), idmJpaFailedCreateTransactionEntityManager$str()), e); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String idmNoIdentityConfigurationProvided = "WFLYPL0054: You must provide at least one identity configuration.";
/** * {@inheritDoc} */ @Override public V resolveProperty(Object propertyValueFromConfiguration, Class<V> propertyClass) { if (propertyValueFromConfiguration instanceof String) { String stringValue = (String)propertyValueFromConfiguration; // Handle null cases if ("null".equals(stringValue)) { return null; } return resolvePropertyFromString(stringValue, propertyClass); } else { throw new SecurityConfigurationException("Unknown type of propertyValue: " + propertyValueFromConfiguration); } }
@Override public final SecurityConfigurationException idmJpaEMFLookupFailed(final String entityManagerFactoryJndiName) { final SecurityConfigurationException result = new SecurityConfigurationException(String.format(getLoggingLocale(), idmJpaEMFLookupFailed$str(), entityManagerFactoryJndiName)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String idmJpaFailedCreateTransactionEntityManager = "WFLYPL0053: Could not create transactional EntityManager.";
@Override public void setup(S store) { super.setup(store); Object configuredTokenConsumers = store.getConfig().getCredentialHandlerProperties().get(TOKEN_CONSUMER); if (configuredTokenConsumers != null) { try { if (Consumer.class.isInstance(configuredTokenConsumers)) { this.tokenConsumers.add((Consumer) configuredTokenConsumers); } else if (configuredTokenConsumers.getClass().isArray()) { this.tokenConsumers.addAll(Arrays.asList((Consumer[]) configuredTokenConsumers)); } else if (List.class.isInstance(configuredTokenConsumers)) { this.tokenConsumers.addAll((List<Consumer>) configuredTokenConsumers); } } catch (ClassCastException cce) { throw new SecurityConfigurationException("Token consumer is not a " + Consumer.class.getName() + " instance. You provided " + configuredTokenConsumers); } } }
@Override public void setup(S store) { super.setup(store); Object configuredTokenConsumers = store.getConfig().getCredentialHandlerProperties().get(TOKEN_CONSUMER); if (configuredTokenConsumers != null) { try { if (Consumer.class.isInstance(configuredTokenConsumers)) { this.tokenConsumers.add((Consumer) configuredTokenConsumers); } else if (configuredTokenConsumers.getClass().isArray()) { this.tokenConsumers.addAll(Arrays.asList((Consumer[]) configuredTokenConsumers)); } else if (List.class.isInstance(configuredTokenConsumers)) { this.tokenConsumers.addAll((List<Consumer>) configuredTokenConsumers); } } catch (ClassCastException cce) { throw new SecurityConfigurationException("Token consumer is not a " + Consumer.class.getName() + " instance. You provided " + configuredTokenConsumers); } } }
@Override protected void validate() { if (this.mappedClass == null) { throw new SecurityConfigurationException("Mapped class not provided."); } if (this.hierarchySearchDepth < 0) { throw new SecurityConfigurationException("The hierarchy search depth can not be negative."); } if (!Relationship.class.isAssignableFrom(this.mappedClass)) { if (isNullOrEmpty(this.idPropertyName)) { throw new SecurityConfigurationException("No attribute provided as the identifier for mapped class [" + this.mappedClass + "]."); } } for (String propertyName : this.mappedProperties.keySet()) { Property<String> property = PropertyQueries.<String>createQuery(this.mappedClass).addCriteria(new NamedPropertyCriteria(propertyName)).getFirstResult(); if (property != null && !property.isAnnotationPresent(AttributeProperty.class) && !Relationship.class.isAssignableFrom(this.mappedClass)) { throw new SecurityConfigurationException("Mapped properties must be annotated with @AttributeProperty. Property [" + this.mappedClass + "." + propertyName + "]."); } } }
@Override protected void validate() { if (this.mappedClass == null) { throw new SecurityConfigurationException("Mapped class not provided."); } if (this.hierarchySearchDepth < 0) { throw new SecurityConfigurationException("The hierarchy search depth can not be negative."); } if (!Relationship.class.isAssignableFrom(this.mappedClass)) { if (isNullOrEmpty(this.idPropertyName)) { throw new SecurityConfigurationException("No attribute provided as the identifier for mapped class [" + this.mappedClass + "]."); } } for (String propertyName : this.mappedProperties.keySet()) { Property<String> property = PropertyQueries.<String>createQuery(this.mappedClass).addCriteria(new NamedPropertyCriteria(propertyName)).getFirstResult(); if (property != null && !property.isAnnotationPresent(AttributeProperty.class) && !Relationship.class.isAssignableFrom(this.mappedClass)) { throw new SecurityConfigurationException("Mapped properties must be annotated with @AttributeProperty. Property [" + this.mappedClass + "." + propertyName + "]."); } } }