Example usage for javax.security.auth.login LoginException LoginException

List of usage examples for javax.security.auth.login LoginException LoginException

Introduction

In this page you can find the example usage for javax.security.auth.login LoginException LoginException.

Prototype

public LoginException() 

Source Link

Document

Constructs a LoginException with no detail message.

Usage

From source file:org.zanata.action.ValidateEmailAction.java

@Transactional
@CheckLoggedIn/* w  w  w.  j  ava  2s.c  om*/
public void validate() throws LoginException {
    String returnUrl = "/home.xhtml";

    if (activationKey != null && !activationKey.isEmpty()) {
        HPersonEmailValidationKey entry = emailChangeService.getActivationKey(activationKey);
        if (entry == null) {
            throw new KeyNotFoundException("activation key: " + activationKey);
        }

        String checkResult = checkExpiryDate(entry.getCreationDate());

        if (StringUtils.isEmpty(checkResult)) {
            HPerson person = entry.getPerson();
            HAccount account = person.getAccount();
            if (!account.getUsername().equals(identity.getCredentials().getUsername())) {
                throw new LoginException();
            }

            person.setEmail(entry.getEmail());
            account.setEnabled(true);
            personDAO.makePersistent(person);
            personDAO.flush();
            emailChangeService.removeEntry(entry);
            facesMessages.addGlobal("You have successfully changed your email account.");
            log.info("update email address to {}  successfully", entry.getEmail());
        } else {
            returnUrl = checkResult;
        }
    }
    urlUtil.redirectTo(returnUrl);
}

From source file:de.stkl.gbgvertretungsplan.sync.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//w  w  w  .ja v  a 2  s .c o m
    //android.os.Debug.waitForDebugger();
    reportStatus(Sync.SYNC_STATUS.START);

    String username = account.name;
    String password = mAccountManager.getPassword(account);

    AndroidHttpClient httpClient = AndroidHttpClient.newInstance(null);

    CookieStore cookies = new BasicCookieStore();
    HttpContext localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookies);

    boolean error = false;

    try {
        String dataTypeS = mAccountManager.getUserData(account,
                de.stkl.gbgvertretungsplan.values.Account.PROP_TYPE);
        int dataType = dataTypeS == null ? 0 : Integer.valueOf(dataTypeS);

        if (!mComInterface.login(httpClient, localContext, username, password, dataType))
            throw new LoginException();

        // 4. request and save pages (today + tomorrow)
        requestAndSaveDay(httpClient, localContext, 0, dataType); // today
        requestAndSaveDay(httpClient, localContext, 1, dataType); // and tomorrow

        if (!logout(httpClient, localContext))
            throw new CommunicationInterface.LogoutException();

    } catch (IOException e) {
        error = true;
    } catch (CommunicationInterface.CommunicationException e) {
        ErrorReporter.reportError(e, mContext);
        error = true;
    } catch (CommunicationInterface.ParsingException e) {
        ErrorReporter.reportError(e, mContext);
        error = true;
    } catch (LoginException e) {
        error = true;
    } catch (CommunicationInterface.LogoutException e) {
        ErrorReporter.reportError(e, mContext);
        error = true;
        // generic exceptions like NullPointerException should also indicate a failed Sync
    } catch (Exception e) {
        error = true;
    } finally {
        if (error)
            reportStatus(Sync.SYNC_STATUS.ERROR);
        else
            reportStatus(Sync.SYNC_STATUS.OK);
        httpClient.close();
    }
}

From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderPropertiesFileLoginModule.java

public boolean login() throws LoginException {
    Map<String, String> headerMap = null;
    loginSucceeded = false;/*from   ww w . java2 s . c o  m*/
    Callback[] callbacks = new Callback[1];
    callbacks[0] = new RequestCallback();
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException ioe) {
        throw (LoginException) new LoginException().initCause(ioe);
    } catch (UnsupportedCallbackException uce) {
        throw (LoginException) new LoginException().initCause(uce);
    }
    httpRequest = ((RequestCallback) callbacks[0]).getRequest();
    String[] headers = headerNames.split(",");
    try {
        headerMap = matchHeaders(httpRequest, headers);
    } catch (HeaderMismatchException e) {
        throw (LoginException) new LoginException("Header Mistmatch error").initCause(e);
    }

    if (headerMap.isEmpty()) {
        throw new FailedLoginException();
    }

    if (authenticationAuthority.equalsIgnoreCase("Siteminder")) {
        HeaderHandler headerHandler = new SiteminderHeaderHandler();
        username = headerHandler.getUser(headerMap);
    } else if (authenticationAuthority.equalsIgnoreCase("Datapower")) {
        /* To be Done */
    }
    if (username == null || username.equals("")) {
        username = null;
        throw new FailedLoginException();
    }

    if (username != null) {
        for (Map.Entry<String, Set<String>> entry : roleUsersMap.entrySet()) {
            String groupName = entry.getKey();
            Set<String> users = entry.getValue();
            for (String user : users) {
                if (username.equals(user)) {
                    groups.add(groupName);
                    break;
                }
            }
        }
    }

    if (groups.isEmpty()) {
        log.error("No roles associated with user " + username);
        loginSucceeded = false;
        throw new FailedLoginException();
    } else
        loginSucceeded = true;
    return loginSucceeded;
}

From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderSqlLoginmodule.java

public boolean login() throws LoginException {
    Map<String, String> headerMap = null;
    loginSucceeded = false;/* w ww. j  a va2  s .c  o m*/
    Connection conn = null;
    ResultSet result = null;
    PreparedStatement statement = null;
    Callback[] callbacks = new Callback[1];
    callbacks[0] = new RequestCallback();
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException ioe) {
        throw (LoginException) new LoginException().initCause(ioe);
    } catch (UnsupportedCallbackException uce) {
        throw (LoginException) new LoginException().initCause(uce);
    }
    httpRequest = ((RequestCallback) callbacks[0]).getRequest();
    String[] headers = headerNames.split(",");
    try {
        headerMap = matchHeaders(httpRequest, headers);
    } catch (HeaderMismatchException e) {
        throw (LoginException) new LoginException("Header Mistmatch error").initCause(e);
    }

    if (headerMap.isEmpty()) {
        throw new FailedLoginException();
    }

    if (authenticationAuthority.equalsIgnoreCase("Siteminder")) {
        HeaderHandler headerHandler = new SiteminderHeaderHandler();
        username = headerHandler.getUser(headerMap);
    } else if (authenticationAuthority.equalsIgnoreCase("Datapower")) {
        /* To be Done */
    }
    if (username == null || username.equals("")) {
        username = null;
        throw new FailedLoginException();
    }

    if (dataSource != null) {
        try {
            conn = dataSource.getConnection();
            try {
                statement = conn.prepareStatement(groupSelect);
                int count = countParameters(groupSelect);
                for (int i = 0; i < count; i++) {
                    statement.setObject(i + 1, username);
                }
                result = statement.executeQuery();
                while (result.next()) {
                    String userName = result.getString(1);
                    String groupName = result.getString(2);
                    if (userName.equals(username))
                        groups.add(groupName);
                }
                if (groups.isEmpty()) {
                    log.error("No roles associated with user " + username);
                    loginSucceeded = false;
                    throw new FailedLoginException();
                } else
                    loginSucceeded = true;
            } finally {
                result.close();
                statement.close();
                conn.close();
            }
        } catch (LoginException e) {
            // Clear out the private state
            username = null;
            groups.clear();
            throw e;
        } catch (SQLException sqle) {
            // Clear out the private state
            username = null;
            groups.clear();
            throw (LoginException) new LoginException("SQL error").initCause(sqle);
        } catch (Exception e) {
            // Clear out the private state
            username = null;
            groups.clear();
            throw (LoginException) new LoginException("Could not access datasource").initCause(e);
        }
    }

    return loginSucceeded;
}

From source file:fr.paris.lutece.portal.service.admin.AdminAuthenticationService.java

/**
 * Checks user's login with the Authentication service.
 * @param request The Http request/*www .j  av  a2  s.  com*/
 * @param strAccessCode The user's login
 * @param strPassword The user's password
 * @throws LoginException The LoginException
 */
public void loginUser(HttpServletRequest request, final String strAccessCode, final String strPassword)
        throws LoginException {
    AdminUser user = _authentication.login(strAccessCode, strPassword, request);

    try {
        registerUser(request, user);
    } catch (AccessDeniedException e) {
        throw new LoginException();
    } catch (UserNotSignedException e) {
        throw new LoginException();
    }

    AdminUserService.updateDateLastLogin(user.getUserId());
}

From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderLdapLoginModule.java

/**
 * This LoginModule is not to be ignored. So, this method should never return false.
 * /*from w ww.  j  a  va 2  s.co m*/
 * @return true if authentication succeeds, or throw a LoginException such as FailedLoginException if authentication
 *         fails
 */
public boolean login() throws LoginException {
    Map<String, String> headerMap = null;
    loginSucceeded = false;
    Callback[] callbacks = new Callback[1];
    callbacks[0] = new RequestCallback();
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException ioe) {
        throw (LoginException) new LoginException().initCause(ioe);
    } catch (UnsupportedCallbackException uce) {
        throw (LoginException) new LoginException().initCause(uce);
    }
    httpRequest = ((RequestCallback) callbacks[0]).getRequest();
    String[] headers = headerNames.split(",");
    try {
        headerMap = matchHeaders(httpRequest, headers);
    } catch (HeaderMismatchException e) {
        throw (LoginException) new LoginException("Header Mistmatch error").initCause(e);
    }

    if (headerMap.isEmpty()) {
        throw new FailedLoginException();
    }

    if (authenticationAuthority.equalsIgnoreCase("Siteminder")) {
        HeaderHandler headerHandler = new SiteminderHeaderHandler();
        username = headerHandler.getUser(headerMap);
    } else if (authenticationAuthority.equalsIgnoreCase("Datapower")) {
        /* To be Done */
    }
    if (username == null || username.equals("")) {
        username = null;
        throw new FailedLoginException();
    }

    try {
        boolean result = authenticate(username);
        if (!result) {
            throw new FailedLoginException();
        }
    } catch (LoginException e) {
        // Clear out the private state
        username = null;
        groups.clear();
        throw e;
    } catch (Exception e) {
        // Clear out the private state
        username = null;
        groups.clear();
        throw (LoginException) new LoginException("LDAP Error").initCause(e);
    }

    loginSucceeded = true;
    return loginSucceeded;
}

From source file:org.apache.lens.server.auth.SpnegoAuthenticationFilter.java

private Subject loginAndGetSubject() throws LoginException {

    // The login without a callback can work if
    // - Kerberos keytabs are used with a principal name set in the JAAS config
    // - Kerberos is integrated into the OS logon process
    //   meaning that a process which runs this code has the
    //   user identity

    LoginContext lc = null;/*from   ww  w .  j a  v  a  2 s.com*/
    if (loginConfig != null) {
        lc = new LoginContext("", null, null, loginConfig);
    } else {
        log.info("LoginContext can not be initialized");
        throw new LoginException();
    }
    lc.login();
    return lc.getSubject();
}

From source file:com.sonymobile.jenkins.plugins.kerberossso.KerberosFilterTest.java

private void rejectAuthentication() throws LoginException, IOException, ServletException {
    KerberosAuthenticator mockAuthenticator = mock(KerberosAuthenticator.class);
    when(mockAuthenticator.authenticate(any(HttpServletRequest.class), any(HttpServletResponse.class)))
            .thenThrow(new LoginException());
    registerFilter(mockAuthenticator);/*from  w w w  .j av  a 2  s  .  co m*/
}

From source file:org.energy_home.jemma.ah.webui.energyathome.EnergyAtHome.java

private Authorization login(HttpServletRequest request, final String username, final String password)
        throws LoginException {
    Authorization a = (Authorization) request.getAttribute(HttpContext.AUTHORIZATION);
    if (a != null) {
        return a;
    }//  ww  w.  j av  a 2s  .co m

    if (userAdmin != null) {
        User user = userAdmin.getUser("org.energy_home.jemma.username", username);
        if (user == null) {
            throw new LoginException();
        }
        if (!user.hasCredential("org.energy_home.jemma.password", password)) {
            throw new LoginException();
        }

        return userAdmin.getAuthorization(user);
    }

    throw new LoginException();
}

From source file:org.energy_home.jemma.ah.webui.energyathome.ekitchen.EnergyAtHome.java

private Authorization login(HttpServletRequest request, final String username, final String password)
        throws LoginException {
    Authorization a = (Authorization) request.getAttribute(HttpContext.AUTHORIZATION);
    if (a != null) {
        return a;
    }// ww  w  .  j  ava2  s.c o m

    if (userAdmin != null) {
        User user = userAdmin.getUser("it.telecomitalia.username", username);
        if (user == null) {
            throw new LoginException();
        }
        if (!user.hasCredential("it.telecomitalia.password", password)) {
            throw new LoginException();
        }

        return userAdmin.getAuthorization(user);
    }

    throw new LoginException();
}