Package org.uberfire.security.server

Examples of org.uberfire.security.server.HttpSecurityContext


    public RememberMeCookieAuthScheme( final CookieStorage cookieStorage ) {
        this.cookieStorage = checkNotNull( "cookieStorage", cookieStorage );
    }

    public boolean isAuthenticationRequest( final SecurityContext context ) {
        final HttpSecurityContext httpSecurityContext = checkInstanceOf( "context", context, HttpSecurityContext.class );
        return cookieStorage.load( httpSecurityContext ) != null;
    }
View Full Code Here


    @Override
    public void challengeClient( final SecurityContext context ) {
    }

    public Credential buildCredential( final SecurityContext context ) {
        final HttpSecurityContext httpSecurityContext = checkInstanceOf( "context", context, HttpSecurityContext.class );
        final Principal principal = cookieStorage.load( httpSecurityContext );

        if ( principal == null ) {
            return null;
        }
View Full Code Here

public class HttpSessionStorage implements AuthenticatedStorageProvider {

    @Override
    public Principal load(final SecurityContext context) {
        final HttpSecurityContext httpContext = checkInstanceOf("context", context, HttpSecurityContext.class);

        return (Principal) httpContext.getRequest().getSession().getAttribute(SUBJECT_ON_SESSION_KEY);
    }
View Full Code Here

        return (Principal) httpContext.getRequest().getSession().getAttribute(SUBJECT_ON_SESSION_KEY);
    }

    @Override
    public void store(final SecurityContext context, final Subject subject) {
        final HttpSecurityContext httpContext = checkInstanceOf("context", context, HttpSecurityContext.class);

        final HttpSession session = httpContext.getRequest().getSession();
        session.setAttribute(SUBJECT_ON_SESSION_KEY, subject);
    }
View Full Code Here

        session.setAttribute(SUBJECT_ON_SESSION_KEY, subject);
    }

    @Override
    public void cleanup(final SecurityContext context) {
        final HttpSecurityContext httpContext = checkInstanceOf("context", context, HttpSecurityContext.class);
        httpContext.getRequest().getSession().removeAttribute(SUBJECT_ON_SESSION_KEY);
    }
View Full Code Here

import static org.uberfire.commons.validation.Preconditions.*;

public class HttpBasicAuthenticationScheme implements AuthenticationScheme {

    public boolean isAuthenticationRequest( final SecurityContext context ) {
        final HttpSecurityContext httpSecurityContext = checkInstanceOf( "context", context, HttpSecurityContext.class );

        return httpSecurityContext.getRequest().getHeader( "Authorization" ) != null;
    }
View Full Code Here

    @Override
    public void challengeClient( SecurityContext context ) {
    }

    public Credential buildCredential( final SecurityContext context ) {
        final HttpSecurityContext httpSecurityContext = checkInstanceOf( "context", context, HttpSecurityContext.class );

        final String auth = httpSecurityContext.getRequest().getHeader( "Authorization" );
        if ( auth != null ) {
            final int index = auth.indexOf( ' ' );
            if ( index > 0 ) {
                final String[] credentials = new String( Base64.decodeBase64( auth.substring( index ) ), Charsets.UTF_8 ).split( ":" );
View Full Code Here

    }

    @Override
    public Credential buildCredential( SecurityContext context) {

        final HttpSecurityContext httpSecurityContext = checkInstanceOf("context", context, HttpSecurityContext.class);

        final String userName = httpSecurityContext.getRequest().getUserPrincipal().getName();
        return new UserNameCredential(userName);
    }
View Full Code Here

        this.resourceManager = checkNotNull( "resourceManager", resourceManager );
    }

    @Override
    public Subject authenticate( final SecurityContext context ) throws AuthenticationException {
        final HttpSecurityContext httpContext = checkInstanceOf( "context", context, HttpSecurityContext.class );

        Principal principal = null;
        for ( final AuthenticatedStorageProvider storeProvider : authStorageProviders ) {
            principal = storeProvider.load( httpContext );
            if ( principal != null ) {
                break;
            }
        }

        if ( principal != null && principal instanceof Subject ) {
            return (Subject) principal;
        }

        boolean isRememberOp = principal != null;

        final boolean requiresAuthentication = resourceManager.requiresAuthentication( httpContext.getResource() );

        if ( principal == null ) {
            for ( final AuthenticationScheme authScheme : authSchemes ) {
                if ( authScheme.isAuthenticationRequest( httpContext ) ) {
                    break;
                } else if ( requiresAuthentication ) {
                    if ( !requestCache.containsKey( httpContext.getRequest().getSession().getId() ) ) {

                        String preservedQueryStr = httpContext.getRequest().getQueryString();

                        if ( preservedQueryStr == null ) {
                            preservedQueryStr = "";
                        } else {
                            preservedQueryStr = "?" + preservedQueryStr;
                        }

                        // this is for the benefit of dev mode logins: the uf_security_check form
                        // won't have the gwt.codeserver parameter on it, but the referer will
                        String referer = httpContext.getRequest().getHeader( "Referer" );
                        if ( preservedQueryStr.equals( "" ) && referer != null && referer.indexOf( '?' ) >= 0 ) {
                            preservedQueryStr = referer.substring( referer.indexOf( '?' ) );
                        }

                        if ( forceURL != null ) {

                            // prepend context path for context-relative forceURLs
                            String contextPrefix = "";
                            if ( forceURL.startsWith( "/" ) ) {
                                contextPrefix = httpContext.getRequest().getContextPath();
                            }

                            requestCache.put( httpContext.getRequest().getSession().getId(), contextPrefix + forceURL + preservedQueryStr );
                        } else {
                            requestCache.put( httpContext.getRequest().getSession().getId(), httpContext.getRequest().getRequestURI() + preservedQueryStr );
                        }
                    }
                    authScheme.challengeClient( httpContext );
                }
            }

            if ( !requiresAuthentication ) {
                return null;
            }

            all_auth:
            for ( final AuthenticationScheme authScheme : authSchemes ) {
                final Credential credential = authScheme.buildCredential( httpContext );

                if ( credential == null ) {
                    continue;
                }

                for ( final AuthenticationProvider authProvider : authProviders ) {
                    final AuthenticationResult result = authProvider.authenticate( credential, context );
                    if ( result.getStatus().equals( FAILED ) ) {
                        authScheme.challengeClient( httpContext );
                        throw new AuthenticationException( "Invalid credentials." );
                    } else if ( result.getStatus().equals( SUCCESS ) ) {
                        principal = result.getPrincipal();
                        break all_auth;
                    }
                }
            }
        }

        if ( principal == null ) {
            throw new AuthenticationException( "Invalid credentials." );
        }

        final List<Role> roles = new ArrayList<Role>();
        if ( isRememberOp ) {
            roles.add( new RoleImpl( ROLE_REMEMBER_ME ) );
        }

        for ( final RoleProvider roleProvider : roleProviders ) {
            roles.addAll( roleProvider.loadRoles( principal, context ) );
        }

        final Map<String, String> properties = new HashMap<String, String>();
        for ( final SubjectPropertiesProvider propertiesProvider : subjectPropertiesProviders ) {
            properties.putAll( propertiesProvider.loadProperties( principal ) );
        }

        final String name = principal.getName();
        final Subject result = new IdentityImpl( name, roles, properties );

        for ( final AuthenticatedStorageProvider storeProvider : authStorageProviders ) {
            storeProvider.store( httpContext, result );
        }

        final String originalRequest = requestCache.remove( httpContext.getRequest().getSession().getId() );
        if ( originalRequest != null && !originalRequest.isEmpty() && !httpContext.getResponse().isCommitted() ) {
            try {
                if ( useRedirect( originalRequest ) ) {
                    httpContext.getResponse().sendRedirect( originalRequest );
                } else {
                    // subject must be already set here since we forwarding
                    SecurityFactory.setSubject( result );
                    RequestDispatcher rd = httpContext.getRequest().getRequestDispatcher( originalRequest.replaceFirst( httpContext.getRequest().getContextPath(), "" ) );
                    // forward instead of sendRedirect as sendRedirect will always use GET method which
                    // means it can change http method if non GET was used for instance POST
                    rd.forward( httpContext.getRequest(), httpContext.getResponse() );
                }
            } catch ( Exception e ) {
                throw new RuntimeException( "Unable to redirect.", e );
            }
        }
View Full Code Here

    @Override
    public void logout( final SecurityContext context ) throws AuthenticationException {
        for ( final AuthenticatedStorageProvider storeProvider : authStorageProviders ) {
            storeProvider.cleanup( context );
        }
        final HttpSecurityContext httpContext = checkInstanceOf( "context", context, HttpSecurityContext.class );
        try {
            httpContext.getRequest().logout();
        } catch ( ServletException e ) {
            e.printStackTrace();
        } finally {
            httpContext.getRequest().getSession().invalidate();
        }
    }
View Full Code Here

TOP

Related Classes of org.uberfire.security.server.HttpSecurityContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.