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(String msg) 

Source Link

Document

Constructs a LoginException with the specified detail message.

Usage

From source file:org.eclipse.ecr.runtime.api.login.SystemLoginModule.java

@Override
@SuppressWarnings("unchecked")
public boolean login() throws LoginException {
    if (trace) {//ww w . j  av a  2s .c o m
        log.trace("begin system login");
    }
    LoginService loginService = Framework.getLocalService(LoginService.class);
    if (loginService == null) {
        throw new LoginException("Nuxeo Login Service is not running - cannot do system login");
    }
    CredentialsCallback cb = new CredentialsCallback();
    try {
        callbackHandler.handle(new Callback[] { cb });
    } catch (Exception e) {
        throw new LoginException("System login failed - callback failed");
    }
    Object credential = cb.getCredentials();
    if (LoginComponent.isSystemLogin(credential)) {
        Principal principal = (Principal) credential;
        sharedState.put("javax.security.auth.login.name", principal);
        sharedState.put("javax.security.auth.login.password", null);
        if (trace) {
            log.trace("System Login Succeded");
        }
        return true;
    }
    if (trace) {
        log.trace("System Login Failed");
    }
    return false;
}

From source file:info.magnolia.jaas.sp.jcr.JCRAuthenticationModule.java

/**
 * Authenticate against magnolia/jcr user repository
 *///from w w  w.ja v a2  s . c om
public boolean login() throws LoginException {
    if (this.callbackHandler == null) {
        throw new LoginException("Error: no CallbackHandler available for JCRModule");
    }

    Callback[] callbacks = new Callback[2];
    callbacks[0] = new NameCallback("name");
    callbacks[1] = new PasswordCallback("pswd", false);

    this.success = false;
    try {
        this.callbackHandler.handle(callbacks);
        this.name = ((NameCallback) callbacks[0]).getName();
        this.pswd = ((PasswordCallback) callbacks[1]).getPassword();
        this.success = this.isValidUser();
    } catch (IOException ioe) {
        if (log.isDebugEnabled()) {
            log.debug("Exception caught", ioe);
        }
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException ce) {
        if (log.isDebugEnabled()) {
            log.debug(ce.getMessage(), ce);
        }
        throw new LoginException(ce.getCallback().toString() + " not available");
    }
    if (!this.success) {
        throw new LoginException("failed to authenticate " + this.name);
    }

    return this.success;
}

From source file:net.sourceforge.safr.sample.usermgnt.service.UserServiceImpl.java

public Set<Principal> authenticate(String username, char[] password) throws LoginException {
    User user = findUser(username);//from   w  w w . j av a2 s  .  c om
    if (user == null) {
        throw new LoginException("user " + username + " doesn't exist");
    }
    if (!user.getId().equals(String.valueOf(password))) {
        throw new LoginException("wrong password for user " + username);
    }
    Set<Principal> principals = new HashSet<Principal>();
    principals.add(new UserPrincipal(user.getId()));
    for (Role role : user.getRoles()) {
        principals.add(new RolePrincipal(role.getId()));
    }
    return principals;
}

From source file:be.fedict.eid.applet.beta.service.AuthorizationLoginModule.java

public boolean login() throws LoginException {
    NameCallback nameCallback = new NameCallback("Username");
    Callback[] callbacks = new Callback[] { nameCallback };
    try {/*from w  w  w.  j  ava 2 s . co m*/
        this.callbackHandler.handle(callbacks);
    } catch (Exception e) {
        throw new LoginException("JAAS callback error: " + e.getMessage());
    }
    String name = nameCallback.getName();
    this.principal = new NamePrincipal(name);
    LOG.debug("login: " + name);
    return true;
}

From source file:org.nuxeo.runtime.api.login.SystemLoginModule.java

@Override
public boolean login() throws LoginException {
    if (trace) {/*from   w  ww  . j a va2  s.  co m*/
        log.trace("begin system login");
    }
    LoginService loginService = Framework.getLocalService(LoginService.class);
    if (loginService == null) {
        throw new LoginException("Nuxeo Login Service is not running - cannot do system login");
    }
    CredentialsCallback cb = new CredentialsCallback();
    try {
        callbackHandler.handle(new Callback[] { cb });
    } catch (RuntimeException | IOException | UnsupportedCallbackException e) {
        LoginException ee = new LoginException("System login failed - callback failed");
        ee.initCause(e);
        throw ee;
    }
    Object credential = cb.getCredentials();
    if (LoginComponent.isSystemLogin(credential)) {
        Principal principal = (Principal) credential;
        sharedState.put("javax.security.auth.login.name", principal);
        sharedState.put("javax.security.auth.login.password", null);
        if (trace) {
            log.trace("System Login Succeded");
        }
        return true;
    }
    if (trace) {
        log.trace("System Login Failed");
    }
    return false;
}

From source file:be.fedict.hsm.model.security.AdministratorLoginModule.java

@Override
public boolean login() throws LoginException {
    LOG.debug("login");
    NameCallback nameCallback = new NameCallback("username");
    PasswordCallback passwordCallback = new PasswordCallback("password", false);
    Callback[] callbacks = new Callback[] { nameCallback, passwordCallback };
    try {/*www  . j  a  v a  2  s . c  o  m*/
        this.callbackHandler.handle(callbacks);
    } catch (Exception e) {
        throw new LoginException(e.getMessage());
    }
    String username = nameCallback.getName();
    String cardNumber = new String(passwordCallback.getPassword());
    String authenticatedAdministrator = this.administratorSecurityBean.getAuthenticatedAdministrator(username,
            cardNumber);
    if (null == authenticatedAdministrator) {
        throw new LoginException("invalid administrator: " + username);
    }
    this.authenticatedAdministrator = authenticatedAdministrator;
    return true;
}

From source file:org.apache.ranger.authentication.unix.jaas.PamLoginModule.java

private void initializePam() throws LoginException {
    String service = (String) _options.get(SERVICE_KEY);
    if (service == null) {
        throw new LoginException("Error: PAM service was not defined");
    }//  w w  w. ja  v a2s. c o m
    createPam(service);
}

From source file:be.fedict.hsm.model.security.ApplicationLoginModule.java

@Override
public boolean login() throws LoginException {
    LOG.debug("login");
    NameCallback nameCallback = new NameCallback("username");
    PasswordCallback passwordCallback = new PasswordCallback("password", false);
    Callback[] callbacks = new Callback[] { nameCallback, passwordCallback };
    try {// ww  w  . ja v  a  2s  .  com
        this.callbackHandler.handle(callbacks);
    } catch (Exception e) {
        throw new LoginException(e.getMessage());
    }
    String username = nameCallback.getName();
    char[] credential = passwordCallback.getPassword();
    String authenticatedApplication = this.applicationSecurityBean.getAuthenticatedApplication(username,
            credential);
    if (null == authenticatedApplication) {
        throw new LoginException("invalid application: " + username);
    }
    this.authenticatedApplication = authenticatedApplication;
    return true;
}

From source file:org.apache.ranger.authentication.unix.jaas.PamLoginModule.java

private void createPam(String service) throws LoginException {
    try {/*from  w w w.  j  av  a  2 s. c om*/
        _pam = new PAM(service);
    } catch (PAMException ex) {
        LoginException le = new LoginException("Error initializing PAM");
        le.initCause(ex);
        throw le;
    }
}

From source file:com.trailmagic.user.UserLoginModule.java

public boolean login() throws LoginException {
    s_log.debug("UserLoginModule.login called!!");
    if (m_handler == null) {
        throw new LoginException("Error: no CallbackHandler available");
    }//w w  w . ja  v  a 2  s . c om

    try {
        Callback[] callbacks = new Callback[] { new NameCallback("User: "),
                new PasswordCallback("Password: ", false) };

        m_handler.handle(callbacks);

        String username = ((NameCallback) callbacks[0]).getName();
        char[] password = ((PasswordCallback) callbacks[1]).getPassword();

        ((PasswordCallback) callbacks[1]).clearPassword();

        // do app-specific validation
        m_success = validate(username, password);

        callbacks[0] = null;
        callbacks[1] = null;

        return m_success;
    } catch (Exception e) {
        s_log.error("Error processing login", e);
        throw new LoginException(e.getMessage());
    }
}