@ -17,6 +17,7 @@ import java.util.HashSet;
import java.util.List ;
import java.util.Map.Entry ;
import java.util.Set ;
import java.util.stream.Collectors ;
import javax.servlet.FilterRegistration ;
import javax.servlet.ServletContext ;
@ -71,20 +72,20 @@ public class ApplicationManager {
try {
context = provider ( ) . contextFor ( container , application ) ;
for ( Entry < String , ? extends ServletRegistration > servlet : application . getServletRegistrations ( ) . entrySet ( ) )
log . trace ( "servlet {} : {} {} " , application . getServletContextName ( ) , servlet . getKey ( ) , servlet . getValue ( ) . getMappings ( ) ) ;
context . configuration ( ) . validate ( ) ;
/ * if ( context . configuration ( ) . secure ( ) & &
/ * if ( context . configuration ( ) . secure ( ) & &
container . configuration ( ) . securePort ( ) = = null )
throw new IllegalStateException (
String . format ( "Application %s cannot be managed because is declared as secure without a secure connector port declared in the container" , context . application ( ) . getContextPath ( ) ) ) ;
* /
* /
context . configuration ( ) . startTokens ( generateTokensForApplication ( container ) );
context . configuration ( ) . startTokens ( generateTokensForApplication ( container ) .stream ( ) . collect ( Collectors . toSet ( ) ) );
saveApplicationState ( ) ;
@ -128,8 +129,8 @@ public class ApplicationManager {
return context ;
} catch ( RuntimeException e ) {
if ( context ! = null ) {
log . error ( "error starting application {}" , context . name ( ) , e ) ;
@ -142,13 +143,25 @@ public class ApplicationManager {
}
private Se t< String > generateTokensForApplication ( ContainerContext container ) {
private Lis t< String > generateTokensForApplication ( ContainerContext container ) {
log . info ( "generating token for app {}" , context . configuration ( ) . name ( ) ) ;
Set < String > tokens = new HashSet < String > ( ) ;
AuthorizationProxy authProxy = provider ( ) . authorizationProxy ( ) ;
for ( String containerToken : container . configuration ( ) . startTokens ( ) )
tokens . add ( generateApplicationToken ( containerToken , authProxy ) ) ;
return tokens ;
SecurityTokenProvider . instance . set ( container . configuration ( ) . startTokens ( ) . get ( 0 ) ) ;
try {
AuthorizationProxy authProxy = provider ( ) . authorizationProxy ( ) ;
try {
return authProxy . generateServiceToken ( Utils . getServiceInfo ( context ) , container . configuration ( ) . startTokens ( ) ) ;
} catch ( Exception e ) {
log . error ( "error generating service token" , e ) ;
throw new RuntimeException ( e ) ;
}
} catch ( Exception e ) {
throw new RuntimeException ( "error contacting authorization service" , e ) ;
} finally {
SecurityTokenProvider . instance . reset ( ) ;
}
}
private String generateApplicationToken ( String containerToken , AuthorizationProxy authProxy ) {
@ -161,7 +174,7 @@ public class ApplicationManager {
} finally {
SecurityTokenProvider . instance . reset ( ) ;
}
}
@ -243,12 +256,12 @@ public class ApplicationManager {
extension . init ( context ) ;
if ( context . configuration ( ) . includes ( ) . isEmpty ( ) ) {
//register excludes for extension in case of includes they are excluded by default
context . configuration ( ) . excludes ( ) . addAll ( extension . excludes ( ) ) ;
}
String mapping = extension . mapping ( ) ;
application . addServlet ( context . configuration ( ) . name ( ) + "-" + extension . name ( ) , extension )
@ -315,6 +328,7 @@ public class ApplicationManager {
log . trace ( "app token created : {} " , appToken ) ;
context . events ( ) . fire ( appToken , ProfileEvents . addToContext ) ;
context . events ( ) . fire ( appToken , Constants . token_registered ) ;
saveApplicationState ( ) ;
}
@Observes ( value = ContextEvents . REMOVE_TOKEN_FROM_APPLICATION , kind = critical )
@ -325,8 +339,9 @@ public class ApplicationManager {
log . trace ( "app token removed : {} " , appToken ) ;
context . events ( ) . fire ( appToken , ProfileEvents . removeFromContext ) ;
context . events ( ) . fire ( appToken , Constants . token_removed ) ;
saveApplicationState ( ) ;
}
} ;
context . container ( ) . events ( ) . subscribe ( observer ) ;