Example usage for org.springframework.security.authentication AbstractAuthenticationToken isAuthenticated

List of usage examples for org.springframework.security.authentication AbstractAuthenticationToken isAuthenticated

Introduction

In this page you can find the example usage for org.springframework.security.authentication AbstractAuthenticationToken isAuthenticated.

Prototype

public boolean isAuthenticated() 

Source Link

Usage

From source file:com.katsu.springframework.security.authentication.HtmlAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    AbstractAuthenticationToken upat = (AbstractAuthenticationToken) authentication;
    if (!upat.isAuthenticated()) {
        try {// w w w.  j  a v a  2s .  c om
            Collection<? extends GrantedAuthority> roles = doLogin(upat);
            if (roles != null) {
                return createSuccessAuthentication(upat, roles);
            }
        } catch (Exception e) {
            throw new AuthenticationException("Can't authenticate", e) {
            };
        } finally {
        }
    }
    return null;
}

From source file:pt.webdetails.cda.push.CdaPushQueryMessageHandler.java

/**
 * This method executes the query sent by the client of this websocket.
 *
 * @param query The query to be executed, and sent over the websocket.
 *///from   w ww  .  j a  v a  2 s. co  m
@Override
public void onMessage(String query) {
    try {
        PentahoRequestContextHolder.setRequestContext(requestContext);

        AbstractAuthenticationToken principal = (AbstractAuthenticationToken) session.getUserPrincipal();
        if (principal.isAuthenticated()) {
            IPentahoSession pentahoSession = new StandaloneSession(principal.getName());
            PentahoSessionHolder.setSession(pentahoSession);
            SecurityHelper.getInstance().becomeUser(principal.getName());
        }

        this.websocketJsonQueryEndpoint.onMessage(query, outboundMessage -> {
            try {
                if (session.isOpen()) {
                    session.getBasicRemote().sendText(outboundMessage);
                }
            } catch (Exception e) {
                logger.error("Error sending message. Closing websocket...", e);
                try {
                    session.close();
                } catch (IOException ioException) {
                    logger.error("Error writing to websocket", ioException);
                }
            }
        });

    } catch (Exception e) {
        logger.error("Error processing message. Closing websocket...", e);
        try {
            session.close();
        } catch (IOException ioException) {
            logger.error("Error writing to websocket", ioException);
        }
    }
}