Package nl.nuggit.swaf.model

Examples of nl.nuggit.swaf.model.Context


    private ContextStore contextStore;
    @Autowired
    private InteractionFactory interactionFactory;

    public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Context context = getContext(request);
        Interaction interaction = interactionFactory.create(context, request.getPathInfo());
        if (interaction != null) {
            ViewData view = interaction.execute(request, response);
            forwardToView(request, response, view);
        }
View Full Code Here


        }
    }

    private Context getContext(HttpServletRequest request) {
        String token = LoginTokenManager.getToken(request);
        Context context = contextStore.read(token);
        request.setAttribute(Context.NAME, context);
        return context;
    }
View Full Code Here

    private final Map<String, Context> contexts = new HashMap<String, Context>();
    @Autowired
    private AuthenticationService authenticationService;

    public Context authenticate(String... credentials) {
        Context context;
        String principal = credentials[0];
        context = findPrincipal(principal);
        if (context == null) {
            boolean isAuthenticated = authenticationService.authenticate(principal, credentials[1]);
            if (isAuthenticated) {
                String token = UUID.randomUUID().toString();
                context = new Context(token, principal);
                context.grant(Permission.ACCESS);
                contexts.put(token, context);
                LOG.debug(String.format("Added principal %s to context store", principal));
            }
        }
        else {
View Full Code Here

        }
        return null;
    }

    public Context read(String token) {
        Context context = contexts.get(token);
        LOG.debug(String.format("Found context %s for token %s", context, token));
        return context;
    }
View Full Code Here

    public Login(String name) {
        super(name);
    }

    public ViewData execute(HttpServletRequest request, HttpServletResponse response) {
        Context context = (Context) request.getAttribute(Context.NAME);
        if (context == null) {
            String username = request.getParameter(USERNAME);
            String password = request.getParameter(PASSWORD);
            if (username == null || password == null) {
                return new ViewData(loginPage);
            }
            context = contextStore.authenticate(username, password);
            LoginTokenManager.setToken(context.getToken(), response);
            request.setAttribute(Context.NAME, context);
        }
        return new ViewData(homePage);
    }
View Full Code Here

TOP

Related Classes of nl.nuggit.swaf.model.Context

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.