public void logInProgrammatically(String username, string password) { // ... WebAuthentication webA = new WebAuthentication(); webA.login(username, password); // ... }
/** * Log the user out * */ public void logout() { //Get the active request Request request = ActiveRequestResponseCacheValve.activeRequest.get(); if (request == null) throw new IllegalStateException("request is null"); unregister(request); }
session.removeNote(Constants.SESS_USERNAME_NOTE); if (password != null) session.setNote(Constants.SESS_PASSWORD_NOTE, getPasswordAsString(password)); else session.removeNote(Constants.SESS_PASSWORD_NOTE); SingleSignOn sso = this.getSingleSignOn(request); if (sso == null) return; ssoId = generateSessionId(); Cookie cookie = new Cookie(Constants.SINGLE_SIGN_ON_COOKIE, ssoId); cookie.setMaxAge(-1); sso.register(ssoId, principal, AUTH_TYPE, username, this.getPasswordAsString(password)); request.setNote(Constants.REQ_SSOID_NOTE, ssoId); sso.update(ssoId, principal, AUTH_TYPE, username, this.getPasswordAsString(password));
WebAuthentication webAuthentication = new WebAuthentication(); req.getSession().setAttribute("webAuthentication", webAuthentication);
/** * Login an user via the CLIENT-CERT method * @param certs X509 certificates * @return Authenticated User Principal */ public boolean login(X509Certificate[] certs) { //Get the active request Request request = ActiveRequestResponseCacheValve.activeRequest.get(); if (request == null) throw new IllegalStateException("request is null"); Principal p = request.getContext().getRealm().authenticate(certs); if (p != null) { register(request, p, null, null); } return p != null; }
/** * Log the user out * @param request */ protected void unregister(Request request) { request.setAuthType(null); request.setUserPrincipal(null); // Cache the authentication principal in the session. Session session = request.getSessionInternal(false); if (session != null) { session.setAuthType(null); session.setPrincipal(null); session.removeNote(Constants.SESS_USERNAME_NOTE); session.removeNote(Constants.SESS_PASSWORD_NOTE); } // Unregister the SSOID. SingleSignOn sso = this.getSingleSignOn(request); if (sso != null) { String ssoId = (String) request.getNote(Constants.REQ_SSOID_NOTE); sso.deregister(ssoId); } }
/** * Login an user via the BASIC, FORM, DIGEST methods * @param username * @param credential * @return * @throws NamingException */ public boolean login(String username, Object credential) { //Get the active request Request request = ActiveRequestResponseCacheValve.activeRequest.get(); if (request == null) throw new IllegalStateException("request is null"); Principal p = null; if (credential instanceof String) { p = request.getContext().getRealm().authenticate(username, (String) credential); } else if (credential instanceof byte[]) { p = request.getContext().getRealm().authenticate(username, (byte[]) credential); } if (p != null) { register(request, p, username, credential); } return p != null; }
WebAuthentication webAuthentication = new WebAuthentication(); boolean success = webAuthentication.login(username, password);
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { log.debug("------------------------"); log.debug("context: " + context); Identifier identifier = this.verifyResponse(req); log.debug("identifier: " + identifier); // if openid login succeded redirect to home page using our demo account if (identifier != null) { WebAuthentication pwl = new WebAuthentication(); pwl.login("guest", "guest");** resp.sendRedirect("/index.jsp"); } else { System.out.println("login with openid failed"); } }
final String service = constructServiceUrl(request, response); logger.debug("Attempting CAS ticket validation with service={} and ticket={}", service, ticket); if (!new WebAuthentication().login(service, ticket)) { logger.debug("JBoss Web authentication failed."); throw new GeneralSecurityException("JBoss Web authentication failed.");