@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; }
@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; } }
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); } }
@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 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))); } }
@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)); }
@Override public TokenInfo verifyToken(Token token) throws TokenVerifyException { if(null == verifier) { if(Strings.isEmpty(config.getPublicKeyUrl())) { throw new AppConfigException("publicKeyUrl must be configured"); } refreshJwtVerifier(); } return verify(verifier, token.getToken()); }
protected void putProperty(AppPropertyContext context, Resource resource, String key, String value, boolean override) { if(!override && context.hasProperty(key)) { AppProperty prop = context.getProperty(key); if(null != prop) { if(prop.isOverride()) { log.debug("Skip {} at {}, a override one already exists", key, LogUtils.getUrl(resource)); return; } throw new AppConfigException("Found duplicate property '" + key + "' in resources : [" + prop.getSource() + "]" + ", " + LogUtils.getUrl(resource)); }else { throw new AppConfigException("Found duplicate property '" + key + "' in '" + LogUtils.getUrl(resource) + "', the array property with same name already exists!"); } } context.putProperty(resource, key, value, override); }
protected void readMessages(MessageContext context, Resource resource) { try { String localeName = Locales.extractFromFilename(resource.getFilename()); Locale locale = Strings.isEmpty(localeName) ? null : Locales.forName(localeName); Map<String, String> props; try (Reader reader = resource.getInputStreamReader(charset)) { Map map = YAML.decode(reader); if (null == map || map.isEmpty()) { return; } props = Maps.toProperties(map); } for (String key : props.keySet()) { readMessage(context, resource, locale, props, (String) key); } } catch (Exception e) { throw new AppConfigException("Error reading messages from properties resource [" + resource.getURLString() + "], " + e.getMessage(), e); } }
private boolean testIfElement(AppConfigContext context, XmlReader reader) { String expressionText = reader.getRequiredAttribute(EXPR_ATTRIBUTE); try { Expression expression = SPEL.createExpression(parseContext,expressionText); Map<String,Object> vars = New.hashMap("properties", context.getProperties()); return EL.test(expression.getValue(vars), true); } catch (Exception e) { throw new AppConfigException("Error testing if expression '" + expressionText + "' at " + reader.getCurrentLocation(), e); } } }
@Override public void startEndpoint(App app, Routes routes) throws Throwable { if(config.isEnabled() && config.isSingleLoginEnabled()) { sc.interceptors().add(this); if(!Strings.isEmpty(config.getLogoutView())) { this.defaultLogoutView = themeManager.getDefaultView(config.getLogoutView()); } if(null == defaultLogoutView) { throw new AppConfigException("The oauth2 logout view must be configured if logout endpoint enabled"); } } }
@Override public void startEndpoint(App app, Routes routes) throws Throwable { if(config.isEnabled() && config.isSingleLoginEnabled()) { sc.interceptors().add(this); if(!Strings.isEmpty(config.getLogoutView())) { this.defaultLogoutView = themeManager.getDefaultView(config.getLogoutView()); } if(null == defaultLogoutView) { throw new AppConfigException("The oauth2 logout view must be configured if logout endpoint enabled"); } } }
protected void readFunctions(AppConfigContext context, XmlReader reader, ElConfigFunctions funcs) { String prefix = reader.getAttribute(PREFIX_ATTRIBUTE); String className = reader.getRequiredAttribute(CLASS_ATTRIBUTE); while(true){ reader.next(); if(reader.isStartElement()){ if(reader.isStartElement(FUNCTION_ELEMENT)){ readFunction(context, reader, funcs, prefix, className); }else{ throw new AppConfigException("Unsupported el config element '" + reader.getElementName() + "' in xml '" + reader.getSource() + "'"); } }else if(reader.isEndElement(FUNCTIONS_ELEMENT)){ break; } } }