Example usage for org.apache.shiro.authc UsernamePasswordToken setHost

List of usage examples for org.apache.shiro.authc UsernamePasswordToken setHost

Introduction

In this page you can find the example usage for org.apache.shiro.authc UsernamePasswordToken setHost.

Prototype

public void setHost(String host) 

Source Link

Document

Sets the host name or IP string from where the authentication attempt occurs.

Usage

From source file:app.controllers.access.LoginController.java

License:Apache License

@POST
public void signin() {

    String pass = ZHelper.simpleSaltedHash(param("nameoremail"), param("password"));
    UsernamePasswordToken token = new UsernamePasswordToken(param("nameoremail"), pass);
    token.setHost(remoteAddress());

    token.setRememberMe(Boolean.parseBoolean(param("rememberme")));
    try {//from  www . j  a va 2  s .  c o  m

        // currentUser.login(token);
        ZHelperAuth auth = ZHelperAuth.getInstance();
        auth.AuthHelper(token);
        System.out.println(auth.isAuth());
        if (auth.isAuth()) {
            UsernamePasswordToken loginToken = (UsernamePasswordToken) auth.getAuthToken();
            ZHelper.logInfo(LoginController.class, loginToken.getHost() + " :: ==> getIpFrom Client ");
            session().put("authuser", auth);
            redirect(context());
            return;
        }
    } catch (UnknownAccountException uae) {
        ZHelper.logError(LoginController.class, uae.getMessage());
    } catch (IncorrectCredentialsException ice) {
        ZHelper.logError(LoginController.class, ice.getMessage());
    } catch (LockedAccountException lae) {
        ZHelper.logError(LoginController.class, lae.getMessage());
    } catch (Exception e) {
        if (Configuration.getEnv().equalsIgnoreCase("development")) {
            render("/system/error", Collections.map("e", e)).noLayout();
        }
    }
    view("msgbox",
            "Email Tidak ditemukan : " + param("nameoremail")
                    + "<br /> Untuk Bergabung dengan OTransmedia silakan <a  href=\"" + context()
                    + "/access/login\" ><strong>disini</strong></a>");
}

From source file:ch.bastiangardel.easypay.dto.CredentialDTO.java

License:Open Source License

public UsernamePasswordToken daoToModel(String host) {
    UsernamePasswordToken tmp = new UsernamePasswordToken();
    tmp.setHost(host);
    tmp.setRememberMe(false);//from ww w .  ja v a2 s .  com

    if (password != null)
        tmp.setPassword(password.toCharArray());
    else
        tmp.setPassword(null);

    tmp.setUsername(username);

    return tmp;
}

From source file:org.opendaylight.aaa.shiro.filters.AuthenticationListenerTest.java

License:Open Source License

@Test
public void testOnSuccess() throws Exception {
    // sets up a successful authentication attempt
    final AuthenticationListener authenticationListener = new AuthenticationListener();
    final UsernamePasswordToken authenticationToken = new UsernamePasswordToken();
    authenticationToken.setUsername("successfulUser1");
    authenticationToken.setHost("successfulHost1");
    final SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo();
    // the following call produces accounting output
    authenticationListener.onSuccess(authenticationToken, simpleAuthenticationInfo);

    // grab the latest log output and make sure it is in line with what is expected
    final List<LoggingEvent> loggingEvents = TestAppender.getCurrentInstance().getEvents();
    // the latest logging event is the one we need to inspect
    final int whichLoggingEvent = loggingEvents.size() - 1;
    final LoggingEvent latestLoggingEvent = loggingEvents.get(whichLoggingEvent);
    final String latestLogMessage = latestLoggingEvent.getMessage();
    assertEquals("Successful authentication attempt by successfulUser1 from successfulHost1", latestLogMessage);
}

From source file:org.opendaylight.aaa.shiro.filters.AuthenticationListenerTest.java

License:Open Source License

@Test
public void testOnFailure() throws Exception {
    // variables for an unsucessful authentication attempt
    final AuthenticationListener authenticationListener = new AuthenticationListener();
    final UsernamePasswordToken authenticationToken = new UsernamePasswordToken();
    authenticationToken.setUsername("unsuccessfulUser1");
    authenticationToken.setHost("unsuccessfulHost1");
    final AuthenticationException authenticationException = new AuthenticationException("test auth exception");
    // produces unsuccessful authentication attempt output
    authenticationListener.onFailure(authenticationToken, authenticationException);

    // grab the latest log output and ensure it is in line with what is expected
    final List<LoggingEvent> loggingEvents = TestAppender.getCurrentInstance().getEvents();
    final int whichLoggingEvent = loggingEvents.size() - 1;
    final LoggingEvent latestLoggingEvent = loggingEvents.get(whichLoggingEvent);
    final String latestLogMessage = latestLoggingEvent.getMessage();
    assertEquals("Unsuccessful authentication attempt by unsuccessfulUser1 from unsuccessfulHost1",
            latestLogMessage);/*from  w ww .j  a v a 2 s  .c  o  m*/
}

From source file:org.opendaylight.aaa.shiro.filters.AuthenticationTokenUtilsTest.java

License:Open Source License

@Test
public void testExtractHostname() throws Exception {
    // null test/*from  w  ww.  j  av  a2s .  c  o m*/
    final AuthenticationToken nullAuthenticationToken = null;
    assertEquals(AuthenticationTokenUtils.DEFAULT_HOSTNAME,
            AuthenticationTokenUtils.extractHostname(nullAuthenticationToken));

    // non-UsernamePasswordToken test
    final AuthenticationToken notUsernamePasswordToken = new NotUsernamePasswordToken();
    assertEquals(AuthenticationTokenUtils.DEFAULT_HOSTNAME,
            AuthenticationTokenUtils.extractHostname(notUsernamePasswordToken));

    // null hostname test
    final UsernamePasswordToken nullHostname = new UsernamePasswordToken();
    nullHostname.setHost(null);
    assertEquals(AuthenticationTokenUtils.DEFAULT_HOSTNAME,
            AuthenticationTokenUtils.extractHostname(nullHostname));

    // positive test
    final UsernamePasswordToken positiveUsernamePasswordToken = new UsernamePasswordToken();
    final String testUsername = "testHostname1";
    positiveUsernamePasswordToken.setHost(testUsername);
    assertEquals(testUsername, AuthenticationTokenUtils.extractHostname(positiveUsernamePasswordToken));
}

From source file:org.opendaylight.aaa.shiro.filters.AuthenticationTokenUtilsTest.java

License:Open Source License

@Test
public void testGenerateUnsuccessfulAuthenticationMessage() throws Exception {
    final UsernamePasswordToken unsuccessfulToken = new UsernamePasswordToken();
    unsuccessfulToken.setUsername("unsuccessfulUser1");
    unsuccessfulToken.setHost("unsuccessfulHost1");
    assertEquals("Unsuccessful authentication attempt by unsuccessfulUser1 from unsuccessfulHost1",
            AuthenticationTokenUtils.generateUnsuccessfulAuthenticationMessage(unsuccessfulToken));
}

From source file:org.opendaylight.aaa.shiro.filters.AuthenticationTokenUtilsTest.java

License:Open Source License

@Test
public void testGenerateSuccessfulAuthenticationMessage() throws Exception {
    final UsernamePasswordToken successfulToken = new UsernamePasswordToken();
    successfulToken.setUsername("successfulUser1");
    successfulToken.setHost("successfulHost1");
    assertEquals("Successful authentication attempt by successfulUser1 from successfulHost1",
            AuthenticationTokenUtils.generateSuccessfulAuthenticationMessage(successfulToken));
}