@Override public void postCreate(BeanFactory factory) throws Throwable { String tokenType = securityConfig.getAuthenticationTokenType(); if(Strings.isEmpty(tokenType)) { throw new AppConfigException("Default token type must be configured for token based authentication"); } this.tokenAuthenticator = factory.tryGetBean(TokenAuthenticator.class, tokenType); if(null == this.tokenAuthenticator) { throw new AppConfigException("Bean of type '" + TokenAuthenticator.class.getSimpleName() + "' and named '" + tokenType + "' does not exists"); } }
public static ModelContext getModelContext(String className) { ModelContext mc = modelContexts.get(className); if (null == mc) { if (!Orm.hasContexts()) { throw new AppConfigException("DataSource(s) must be configured!"); } else { throw new ObjectNotFoundException("Model '" + className + "' not found in registry"); } } return mc; }
@Override public OAuth2AuthzServerConfigurator useRsaJwtVerifier() { if(this.publicKey == null){ throw new NullPointerException("public key is null! please use setPublicKeyStr(String publicKey) " + "or setPublicKey to set the public key."); } if(this.publicKey instanceof RSAPublicKey){ this.jwtVerifier = new RsaVerifier((RSAPublicKey)this.getPublicKey()); }else{ throw new AppConfigException("this public key is not a rsa public key!"); } return this; }
void resolve() { Class<?> cls = Classes.tryForName(className); if(null == cls) { throw new AppConfigException("Class '" + className + "' not found, check xml '" + source + "'"); } Method m = null; try { m = Reflection.getMethodByNameOrDesc(cls, methodDesc); } catch (Exception e) { throw new AppConfigException("Method name '" + methodDesc + "', check xml '" + source + "'", e); } if(Strings.isEmpty(funcName)){ funcName = m.getName(); } if(!Modifier.isPublic(m.getModifiers()) || !Modifier.isStatic(m.getModifiers())){ throw new AppConfigException("Function method '" + methodDesc + "' must be 'public static', check xml '" + source + "'"); } function = new ElStaticMethod(m); }
@Override public OAuth2AuthzServerConfigurator useRsaJwtVerifier() { if(this.publicKey == null){ throw new NullPointerException("public key is null! please use setPublicKeyStr(String publicKey) " + "or setPublicKey to set the public key."); } if(this.publicKey instanceof RSAPublicKey){ this.jwtVerifier = new RsaVerifier((RSAPublicKey)this.getPublicKey()); }else{ throw new AppConfigException("this public key is not a rsa public key!"); } return this; }
private static Resource checkDir(Resource dir, String name) { if(!dir.exists()) { throw new AppConfigException("The " + name + " dir '" + dir.getFilepath() + "' does not exists!"); } if(!dir.isDirectory()) { throw new AppConfigException("The " + name + " dir '" + dir.getFilepath() + "' must be a directory!"); } return dir; } }
public void checkConfiguration() throws AppConfigException { if(enabled) { if(Strings.isEmpty(clientId)) { throw new AppConfigException("clientId must not be empty."); throw new AppConfigException("clientSecret must not be empty."); throw new AppConfigException("clientRedirectUri must not be empty."); throw new AppConfigException("serverAuthorizationEndpointUrl must not be empty."); throw new AppConfigException("serverTokenEndpointUrl must not be empty."); throw new AppConfigException("serverLogoutEndpointUrl must not be empty.");
protected void checkDuplicateProperty(AppPropertyContext context, Resource resource, String name) { if(!context.isDefaultOverride() && context.hasProperty(name)) { throw new AppConfigException("Found duplicated property '" + name + "', check config : " + resource); } }
protected String resolveProperty(String name) { if(resolvingProperties.contains(name)) { throw new AppConfigException("Found cyclic reference property '" + name + "'"); } resolvingProperties.add(name); AppProperty p = properties.get(name); if(null == p) { p = initProperties.get(name); } String value = null == p ? null : p.getValue(); if(resolver.hasPlaceholder(value)) { String newValue = resolver.resolveString(value); if(!newValue.equals(value)) { value = newValue; p.updateResolvedValue(newValue); } } resolvingProperties.remove(name); return value; }
@Override public void postCreate(BeanFactory factory) throws Throwable { tableNamingStyle = NamingStyles.get(ormConfig.getTableNamingStyle(), factory); columnNamingStyle = NamingStyles.get(ormConfig.getColumnNamingStyle(), factory); if(null == tableNamingStyle) { throw new AppConfigException("Table naming style '" + ormConfig.getTableNamingStyle() + "' not found"); } if(null == columnNamingStyle) { throw new AppConfigException("Column naming style '" + ormConfig.getColumnNamingStyle() + "' not found"); } }
protected void addPermission(SysPermissionDef permission, boolean override){ Map<String,SysPermissionDef> typesPermissionsMap = typedPermissions.get(permission.getPermType()); SysPermissionDef exists = null; if(null == typesPermissionsMap){ typesPermissionsMap = new HashMap<>(); }else{ exists = typesPermissionsMap.get(permission.getPermObject().getName()); } if(!override && null != exists){ throw new AppConfigException("Found duplicated permission '" + permission.toString() + "', source : " + permission.getSource() + "," + exists.getSource()); } if(null != exists){ permissions.remove(exists); } typesPermissionsMap.put(permission.getPermObject().getName(), permission); permissions.add(permission); } }
protected void readMessages(MessageContext context,Resource resource) { Properties props = new Properties(); try { String localeName = null; if (null == localeName) { localeName = Locales.extractFromFilename(resource.getFilename()); } Locale locale = Strings.isEmpty(localeName) ? null : Locales.forName(localeName); try (Reader reader = resource.getInputStreamReader(charset)) { props.load(reader); } for (Object key : props.keySet()) { readMessage(context, resource, locale, props, (String) key); } } catch (AppConfigException e) { throw e; } catch (Exception e) { throw new AppConfigException("Error reading messages from properties resource [" + resource.getURLString() + "], " + e.getMessage(), e); } }
@Override public boolean handleXmlElement(AppConfigContext context, XmlReader reader, String defaultNsURI) { if(!reader.isStartElement()) { return false; } String nsURI = reader.getElementName().getNamespaceURI(); if(Strings.isEmpty(nsURI) || nsURI.equals(defaultNsURI)) { return false; } for(AppConfigProcessor processor : processors){ if(nsURI.equals(processor.getNamespaceURI())){ processor.processElement(context,reader); return true; } } if(null != defaultNsURI && !nsURI.equals(defaultNsURI)) { throw new AppConfigException("Namespace uri '" + nsURI + "' not supported at '" + reader.getCurrentLocation() + "', check your config : " + reader.getSource()); } return false; }
throw new AppConfigException("Permission class '" + className + "' not found, source : " + reader.getSource()); throw new AppConfigException("Permission class '" + className + "' must be instanceof '" + SysPermission.class.getName() + "', source : " + reader.getSource()); permType = (Class<? extends SysPermission>)Classes.tryForName(typeName); if(null == permType){ throw new AppConfigException("Permission type class '" + typeName + "' not found, source : " + reader.getSource()); throw new AppConfigException("Permission class '" + className + "' must define the constructor(String.class,String.class), source : " + reader.getSource()); } catch (Exception e){ throw new AppConfigException("Error creating permission instance of class '" + className + ", source : " + reader.getSource(),e);
protected void readMessage(MessageContext context, Resource resource, Locale locale, Map<String, String> props, String name) { Message message = context.tryGetMessage(locale, name); if (null != message) { throw new AppConfigException("Message key '" + name + "' in locale '" + locale + "' aleady exists in '" + message.getSource() + "', check the file : " + resource.getURLString()); } context.addMessage(locale, name, createMessage(resource.getURLString(), props.get(name))); } }
protected void complete() { //Apply all the properties to config object. config.loadProperties(getPropertiesMap()); config.loadArrayProperties(this.arrayProperties); log.info("\n\n *** {} : {} ***\n",INIT_PROPERTY_BASE_PACKAGE,config.basePackage); log.info("Load {} properties (includes system)",config.properties.size()); printProperties(); //resources try { Map<String,Resource> urlResourceMap = new HashMap<>(); loadBasePackageResources(urlResourceMap,config.basePackage); for(String basePackage : config.getAdditionalPackages()) { loadBasePackageResources(urlResourceMap, basePackage); } loadResources(urlResourceMap); config.resources = new SimpleResourceSet(urlResourceMap.values().toArray(new Resource[]{})); } catch (IOException e) { throw new AppConfigException("Unexpected IOException : " + e.getMessage(), e); } //permissions config.permissions.addAll(permissions); properties.clear(); arrayProperties.clear(); }
@Override public DataSource tryCreateDataSource(DataSourceProps conf) throws NestedClassNotFoundException { String jndiName = conf.getDataSourceJndiName(); if(Strings.isEmpty(jndiName)) { return null; } boolean resourceRef = null == conf.getDataSourceJndiResourceRef() ? false : conf.getDataSourceJndiResourceRef(); try { return new JndiLocator(resourceRef).lookup(jndiName, DataSource.class); } catch (NamingException e) { throw new AppConfigException("Cannot loolup jndi DataSource '" + jndiName + "', " + e.getMessage(), e); } }
protected void readMessage(MessageContext context,Resource resource,Locale locale,Properties props,String name) { Message message = context.tryGetMessage(locale, name); if(null != message && !context.isDefaultOverride()){ throw new AppConfigException("Message key '" + name + "' in locale '" + locale + "' already exists in '" + message.getSource() + "', check the file : " + resource.getURLString()); } context.addMessage(locale, name, createMessage(resource.getURLString(), props.getProperty(name))); } }
@Override public void processElement(AppConfigContext context, XmlReader reader) throws AppConfigException { ElConfigFunctions funcs = context.getOrCreateExtension(ElConfigFunctions.class); if(reader.isStartElement(FUNCTIONS_ELEMENT)){ readFunctions(context, reader, funcs); }else{ throw new AppConfigException("Unsupported el config element '" + reader.getElementLocalName() + "' in xml '" + reader.getSource() + "'"); } }
private void readAnnotationMatcher(XmlReader reader, DefaultMethodInterceptionConfig interception) { String typeName = reader.resolveRequiredAttribute(TYPE_ATTRIBUTE); Class<? extends Annotation> type = (Class<? extends Annotation>)Classes.tryForName(typeName); if(null == type) { throw new AppConfigException("The annotation type '" + typeName + "' not found at : " + reader.getCurrentLocation()); } interception.addMatcher(new AnnotationMethodMatcher(type)); }