List of usage examples for org.apache.shiro.authc UsernamePasswordToken setPassword
public void setPassword(char[] password)
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);// w w w . j a va 2 s . c o m tmp.setRememberMe(false); if (password != null) tmp.setPassword(password.toCharArray()); else tmp.setPassword(null); tmp.setUsername(username); return tmp; }
From source file:com.glaf.shiro.ShiroSecurity.java
License:Apache License
public static void login(String actorId, String password) { logger.info("login user:" + actorId); Subject currentUser = SecurityUtils.getSubject(); try {/*from w w w . j av a2 s. com*/ UsernamePasswordToken token = new UsernamePasswordToken(); token.setUsername(actorId); token.setPassword(actorId.toCharArray()); token.setRememberMe(false); Session session = currentUser.getSession(); session.setAttribute(Constants.LOGIN_ACTORID, actorId); currentUser.login(token); logger.info("User [" + currentUser.getPrincipal() + "] logged in successfully."); } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } }
From source file:com.yiguang.payment.rbac.controller.ShiroDbRealm.java
License:Apache License
/** * ??//ww w .j a va2s.co m */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; String userName = token.getUsername(); String pwd = null; if (!StringUtil.isNullOrEmpty(userName)) { User user = userService.queryUserByName(userName); if (user != null) { if (CommonConstant.CommonStatus.CLOSE == user.getStatus()) { throw new LockedAccountException("?????"); } String loginPwd = user.getPassword(); pwd = String.valueOf(token.getPassword()); String md5Password = securityKeystoreService.getEncryptKeyByJSRSAKey(pwd, user.getId()); if (!md5Password.equals(loginPwd)) { throw new IncorrectCredentialsException("????"); } token.setPassword(md5Password.toCharArray()); SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(user, loginPwd, getName()); return simpleAuthenticationInfo; } else { throw new UnknownAccountException("???!"); } } else { throw new AuthenticationException("????"); } }
From source file:org.pepstock.jem.gwt.server.services.LoginManager.java
License:Open Source License
/** * Performs LOGIN in to JEM, by a userid and password.<br> * After login, loads the profile with all authorizations * based on roles of user.<br>// w w w .jav a 2 s . c om * If is in first installation, checks the right token. * * @param userid user id of client * @param password password of client * @return logged user with all authorizations * @throws ServiceMessageException if any exception occurs */ public LoggedUser login(String userid, String password) throws ServiceMessageException { // gets first installation manager FirstInstallationManager fManager = FirstInstallationManager.getInstance(); // get the currently executing user Subject currentUser = SecurityUtils.getSubject(); UsernamePasswordToken token = null; // is FIRST Installation? if (fManager.isFirstInstallationPhase()) { // checks the token, if the userid is the same // used for the first installation phase // this first installation user is set in SHIRO configuration. token = fManager.getToken(); if (!userid.equalsIgnoreCase(token.getUsername())) { // is not the first installation user, throws an exception LogAppl.getInstance().emit(UserInterfaceMessage.JEMG010E, userid); throw new ServiceMessageException(UserInterfaceMessage.JEMG010E, userid); } // sets password token.setPassword(password.toCharArray()); } else { // this is normal token creation, not first installation token = new UsernamePasswordToken(userid, password); token.setRememberMe(true); } // checks authentication try { currentUser.login(token); } catch (UnknownAccountException uae) { LogAppl.getInstance().emit(UserInterfaceMessage.JEMG011E, token.getPrincipal().toString()); throw new ServiceMessageException(UserInterfaceMessage.JEMG012E, uae); } catch (IncorrectCredentialsException ice) { LogAppl.getInstance().emit(UserInterfaceMessage.JEMG013E, token.getPrincipal().toString()); throw new ServiceMessageException(UserInterfaceMessage.JEMG012E, ice); } catch (LockedAccountException lae) { LogAppl.getInstance().emit(UserInterfaceMessage.JEMG014E, token.getPrincipal().toString()); throw new ServiceMessageException(UserInterfaceMessage.JEMG012E, lae); } catch (AuthenticationException ae) { // ... catch more exceptions here (maybe custom ones specific to your // application? LogAppl.getInstance().emit(UserInterfaceMessage.JEMG015E, ae, token.getPrincipal().toString(), ae.getMessage()); throw new ServiceMessageException(UserInterfaceMessage.JEMG012E, ae); } // gets proncipal, load by authentication engine of Shiro // extracts userid, user name, organizational unit and name User userPrincipal = (User) currentUser.getPrincipal(); String userId = userPrincipal.getId(); String userName = userPrincipal.getName(); String ouId = userPrincipal.getOrgUnitId(); String ouName = userPrincipal.getOrgUnitName(); // sets user and org unit attributes LoggedUser user = new LoggedUser(); user.setId(userId); if (userName != null) { user.setName(userName); } else { user.setName(userId); } OrganizationalUnit ou = new OrganizationalUnit(); ou.setId(ouId); if (ouName != null) { ou.setName(ouName); } else { ou.setName(ouId); } user.setOrganizationalUnit(ou); // stores logged user in HTTP session Session shiroSession = currentUser.getSession(); shiroSession.setAttribute(USER_KEY, user); // load all permission based on user roles loadAllAuthorizations(user); // for administrator role, there is a specific call // to add if is administrator or not user.addAuthorized(Roles.ADMINISTRATOR, currentUser.hasRole(Roles.ADMINISTRATOR)); user.setPreferences(getUserPreferences(userId)); LogAppl.getInstance().emit(UserInterfaceMessage.JEMG016I, user.toString()); return user; }