casinthecloud / cas-overlay-demo

CAS server demo using the Maven overlay
https://www.casinthecloud.com
73 stars 36 forks source link

Demo not working #19

Closed LiHaoGit closed 7 years ago

LiHaoGit commented 7 years ago
CAS Version: 5.0.0
Build Date/Time: 2016-11-10T10:00:20.500Z
System Temp Directory: C:\Users\lihao\AppData\Local\Temp\
Java Home: C:\Program Files\Java\jre1.8.0_91
Java Vendor: Oracle Corporation
Java Version: 1.8.0_91
JCE Installed: no
OS Architecture: amd64
OS Name: Windows 10
OS Version: 10.0

2016-11-10 18:03:46,247 WARN [org.apereo.cas.config.CasSecurityContextConfiguration] - <>
2016-11-10 18:03:46,250 WARN [org.apereo.cas.config.CasSecurityContextConfiguration] - <

 ____   _____   ___   ____   _
/ ___| |_   _| / _ \ |  _ \ | |
\___ \   | |  | | | || |_) || |
 ___) |  | |  | |_| ||  __/ |_|
|____/   |_|   \___/ |_|    (_)

CAS is configured to accept a static list of credentials for authentication.
While this is generally useful for demo purposes, it is STRONGLY recommended
that you DISABLE this authentication method (by SETTING 'cas.authn.accept.users'
to a blank value) and switch to a mode that is more suitable for production.
>
2016-11-10 18:03:46,250 WARN [org.apereo.cas.config.CasSecurityContextConfiguration] - <>
2016-11-10 18:03:46,444 WARN [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] - <Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceRegistryInitializer' defined in class path resource [org/apereo/cas/config/CasCoreServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryInitializer]: Factory method 'serviceRegistryInitializer' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedJsonServiceRegistry' defined in class path resource [org/apereo/cas/config/CasCoreServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryDao]: Factory method 'embeddedJsonServiceRegistry' threw exception; nested exception is java.lang.RuntimeException: java.io.IOException: Unable to delete file: C:\Users\lihao\AppData\Local\Temp\cas\services\localhost-2.json>
2016-11-10 18:03:46,451 WARN [org.apereo.cas.services.ServiceRegistryConfigWatcher] - <Directory key is no longer valid. Quitting watcher service>
2016-11-10 18:03:46,452 INFO [org.apache.catalina.core.StandardService] - <Stopping service Tomcat>
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceRegistryInitializer' defined in class path resource [org/apereo/cas/config/CasCoreServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryInitializer]: Factory method 'serviceRegistryInitializer' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedJsonServiceRegistry' defined in class path resource [org/apereo/cas/config/CasCoreServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryDao]: Factory method 'embeddedJsonServiceRegistry' threw exception; nested exception is java.lang.RuntimeException: java.io.IOException: Unable to delete file: C:\Users\lihao\AppData\Local\Temp\cas\services\localhost-2.json
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1023)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
        at org.apereo.cas.web.CasWebApplication.main(CasWebApplication.java:61)
        ... 8 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryInitializer]: Factory method 'serviceRegistryInitializer' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedJsonServiceRegistry' defined in class path resource [org/apereo/cas/config/CasCoreServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryDao]: Factory method 'embeddedJsonServiceRegistry' threw exception; nested exception is java.lang.RuntimeException: java.io.IOException: Unable to delete file: C:\Users\lihao\AppData\Local\Temp\cas\services\localhost-2.json
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedJsonServiceRegistry' defined in class path resource [org/apereo/cas/config/CasCoreServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryDao]: Factory method 'embeddedJsonServiceRegistry' threw exception; nested exception is java.lang.RuntimeException: java.io.IOException: Unable to delete file: C:\Users\lihao\AppData\Local\Temp\cas\services\localhost-2.json
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1023)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:380)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$208eab0d.embeddedJsonServiceRegistry(<generated>)
        at org.apereo.cas.config.CasCoreServicesConfiguration.serviceRegistryInitializer(CasCoreServicesConfiguration.java:126)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$208eab0d.CGLIB$serviceRegistryInitializer$8(<generated>)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$208eab0d$$FastClassBySpringCGLIB$$4b324680.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$208eab0d.serviceRegistryInitializer(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
        ... 26 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryDao]: Factory method 'embeddedJsonServiceRegistry' threw exception; nested exception is java.lang.RuntimeException: java.io.IOException: Unable to delete file: C:\Users\lihao\AppData\Local\Temp\cas\services\localhost-2.json
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 47 more
Caused by: java.lang.RuntimeException: java.io.IOException: Unable to delete file: C:\Users\lihao\AppData\Local\Temp\cas\services\localhost-2.json
        at com.google.common.base.Throwables.propagate(Throwables.java:160)
        at org.apereo.cas.util.ResourceUtils.prepareClasspathResourceIfNeeded(ResourceUtils.java:146)
        at org.apereo.cas.services.AbstractResourceBasedServiceRegistryDao.<init>(AbstractResourceBasedServiceRegistryDao.java:87)
        at org.apereo.cas.config.CasCoreServicesConfiguration$EmbeddedServiceRegistryDao.<init>(CasCoreServicesConfiguration.java:156)
        at org.apereo.cas.config.CasCoreServicesConfiguration.embeddedJsonServiceRegistry(CasCoreServicesConfiguration.java:136)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$208eab0d.CGLIB$embeddedJsonServiceRegistry$7(<generated>)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$208eab0d$$FastClassBySpringCGLIB$$4b324680.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$208eab0d.embeddedJsonServiceRegistry(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
        ... 48 more
Caused by: java.io.IOException: Unable to delete file: C:\Users\lihao\AppData\Local\Temp\cas\services\localhost-2.json
        at org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:2381)
        at org.apache.commons.io.FileUtils.cleanDirectory(FileUtils.java:1679)
        at org.apereo.cas.util.ResourceUtils.prepareClasspathResourceIfNeeded(ResourceUtils.java:120)
        ... 61 more
wbsouza commented 7 years ago

I have the same problem running on Windows 7

leleuj commented 7 years ago

I'm on MacOS X now so I don't have Windows issues anymore ;-) I guess you already tried to clean the Temp directory before starting the webapp?

wbsouza commented 7 years ago

I have cleaned manually, restart the windows and the problem still persist. For while I have decided move back to the 4.1.8 CAS version (working on windows 7) because the version 5 seems not fully mature. Hopefully I can integrate with pac4j and spring-boot (next steps).

leleuj commented 7 years ago

I have successfully used the version 5 a couple of times (on MacOS X though). Did you report this problem on the CAS mailing list? @mmoayyed Have you ever heard about this problem on Windows?

wbsouza commented 7 years ago

I tested with Mac and Linux is working fine, the problem is specific with windows when the Management starts try to delete the service files (json) and the files is still being used. I believe those files is still opened by the cas webapp. The same problem happen even with the 5.0.4 version (supposedly stable)

cas-server-logs.zip

leleuj commented 7 years ago

Reading: https://github.com/apereo/cas/blob/5.0.x/core/cas-server-core-services/src/main/java/org/apereo/cas/services/AbstractResourceBasedServiceRegistryDao.java, I don't see anything which could explain your specific issue. I guess it's only because of Windows.

wbsouza commented 7 years ago

I found what is going on already, but I believe the people from CAS should change the approach to register the services.

Differently of *nix systems, the Windows lock a file when it is opened (even just for read). It seems there is one or more scheduled tasks reloading the directory "${java.io.tmpdir}/cas/services". I believe is a good idea to use a explicit lock file (opened for loading) in the temp directory and if the lock file exists do not try to delete because it's being used.

To verify that it was happening, first I executed the server and management using different temp directory

 java -jar -Djava.io.tmpdir=c:\temp\cas cas-overlay-server-demo\target\cas.war
 java -jar -Djava.io.tmpdir=c:\temp\mgr cas-overlay-management-demo\target\cas-management.war

And the errors was became less frequent (loading almost always with success the cas server).

To prove that has an process scheduled I made a couple changes: Created new classes under cas-overlay-server-demo using System.out.println to show when the file is being loaded. cas-overlay-server-demo.zip

After to see this, I believe the version 5.0.4 is still not tested on Windows systems.

I guess the best way to solve this problem is to create my own class implementing the ServiceRegistryDao interface. With this approach I can implement in a way that if the file is being used (lock files for example) don't try to delete it. What do you think?

mmoayyed commented 7 years ago

With this approach I can implement in a way that if the file is being used (lock files for example) don't try to delete it. What do you think?

No, that's a very very bad idea.

There is an inordinate amount of literature on the CAS docs asking you to stop writing code. What you're describing sounds like an issue with the project; not something you need to fix for you on your own. There is no such thing as the people from CAS. YOU are the people from CAS. YOU are part of the project as you soon as you start deploying the software. The responsibility is shared; not passed off to a bunch of other folks to fix issues for you. Work on the issue, provide a pull request/patch and solve the problem where it belongs once. Or, you'd be setting yourself up for a lot of surprises and disappointments.

wbsouza commented 7 years ago

Thanks @mmoayyed for your feedback, I would like to contribute with the CAS project, I thought Aspereo was a company and owner of the product. Maybe because I don't have much experience working on open source projects. I don't have much intimacy with the CAS internals, so I'm going to report this problem in the forum and contribute as much as I can to solve this problem. Done!

mmoayyed commented 7 years ago

Thanks very much! and excellent work. I would be more than glad to guide you along the internals as much as possible. Lets carry on the conversation on the list and aim towards your first contribution and patch, which is absolutely more than welcome any day and time :)