List of usage examples for org.apache.shiro.authc UsernamePasswordToken getCredentials
public Object getCredentials()
From source file:au.org.theark.core.security.AAFRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { SimpleAuthenticationInfo sai = null; ArkUserVO userVO = null;//from www . ja va 2 s . c o m UsernamePasswordToken token = (UsernamePasswordToken) authcToken; //log.info("IN AAFRealm.doGetAuthenticationInfo"); //log.info("authToken: " + authcToken.getPrincipal().toString()); log.info("AAF token username: " + token.getUsername()); try { //log.info("checking user"); userVO = iArkCommonService.getUser(token.getUsername().trim()); if (userVO != null) { // Check if the user is in the Ark Database ArkUser arkUser = iArkCommonService.getArkUser(token.getUsername().trim()); // Also check if the Ark User is linked with any study and has roles. // If no roles found, stop the user from logging in until an administrator has set it up if (!iArkCommonService.isArkUserLinkedToStudies(arkUser)) { throw new UnknownAccountException(UNKNOWN_ACCOUNT); } final WebRequest webRequest = (WebRequest) RequestCycle.get().getRequest(); final HttpServletRequest httpReq = (HttpServletRequest) webRequest.getContainerRequest(); //log.info("checking shib headers"); String userName = httpReq.getHeader("AJP_mail"); String password = httpReq.getHeader("AJP_Shib-Session-ID"); if (userName != null && password != null) { //log.info("creating SimpleAuthenticationInfo"); sai = new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName()); } } } catch (ArkSystemException e) { log.error(e.getMessage()); } catch (EntityNotFoundException e) { throw new UnknownAccountException(UNKNOWN_ACCOUNT); } return sai; }
From source file:biz.neustar.nexus.plugins.gitlab.GitlabAuthenticatingRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { if (!(authenticationToken instanceof UsernamePasswordToken)) { throw new UnsupportedTokenException("Token of type " + authenticationToken.getClass().getName() + " is not supported. A " + UsernamePasswordToken.class.getName() + " is required."); }/*from ww w. jav a 2 s .c o m*/ UsernamePasswordToken userPass = (UsernamePasswordToken) authenticationToken; String token = new String(userPass.getPassword()); String username = userPass.getUsername(); if (token.isEmpty()) { LOGGER.debug(GITLAB_MSG + "token for {} is empty", username); return null; } try { LOGGER.debug(GITLAB_MSG + "authenticating {}", username); LOGGER.debug(GITLAB_MSG + "null? " + (gitlab == null)); LOGGER.debug(GITLAB_MSG + "null? " + (gitlab.getRestClient() == null)); GitlabUser gitlabUser = gitlab.getRestClient().getUser(username, token); User user = gitlabUser.toUser(); if (user.getStatus() != UserStatus.active) { LOGGER.debug(GITLAB_MSG + "authentication failed {}", user); throw new AuthenticationException(DISABLED_USER_MESSAGE + " for " + username); } if (user.getUserId() == null || user.getUserId().isEmpty()) { LOGGER.debug(GITLAB_MSG + "authentication failed {}", user); throw new AuthenticationException(DEFAULT_MESSAGE + " for " + username); } LOGGER.debug(GITLAB_MSG + "successfully authenticated {}", username); return new SimpleAuthenticationInfo(gitlabUser, userPass.getCredentials(), getName()); } catch (Exception e) { LOGGER.debug(GITLAB_MSG + "authentication failed {}", username); throw new AuthenticationException(DEFAULT_MESSAGE, e); } }
From source file:com.pingunaut.nexus3.crowd.plugin.CrowdAuthenticatingRealm.java
License:Open Source License
/** * Creates the simple auth info./*from w w w .ja v a 2 s.com*/ * * @param token * the token * @return the simple authentication info */ private SimpleAuthenticationInfo createSimpleAuthInfo(UsernamePasswordToken token) { return new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), NAME); }
From source file:com.webarch.common.shiro.DrCredentialsMatcher.java
License:Apache License
/** * ?MD5// w ww .j ava2s. com * @param token * @param info * @return */ @Override public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { UsernamePasswordToken loginToken = (UsernamePasswordToken) token; Object loginCredentials = loginToken.getCredentials(); String loginPwd = new String((char[]) loginCredentials); loginPwd = loginPwd.trim(); String md5LoginPwd = DigestUtils.md5Hex(loginPwd); String accountPwd = (String) info.getCredentials(); boolean access = loginPwd.equals(accountPwd); boolean md5Access = md5LoginPwd.endsWith(accountPwd); return access || md5Access; }
From source file:eu.forgestore.ws.util.ShiroUTAuthorizingRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken at) throws AuthenticationException { logger.info("AuthenticationToken at=" + at.toString()); UsernamePasswordToken token = (UsernamePasswordToken) at; logger.info("tokengetUsername at=" + token.getUsername()); //logger.info("tokengetPassword at=" + String.valueOf(token.getPassword())); //logger.info("tokengetPrincipal at=" + token.getPrincipal()); FStoreUser bu = fstoreRepositoryRef.getUserByUsername(token.getUsername()); if (bu == null) { throw new AuthenticationException("Sorry! No login for you."); }/*from w w w . j a v a 2s .c o m*/ String originalPass = bu.passwordValue(); String suppliedPass = EncryptionUtil.hash(String.valueOf(token.getPassword())); logger.info("originalPass =" + originalPass); logger.info("suppliedPass =" + suppliedPass); if (originalPass.equals(suppliedPass)) { logger.info("======= USER is AUTHENTICATED OK ======="); } else { throw new AuthenticationException("Sorry! No login for you."); } // try { // currentUser.login(token); // } catch (AuthenticationException ex) { // logger.info(ex.getMessage(), ex); // throw new AuthenticationException("Sorry! No login for you."); // } // // Perform authorization check // if (!requiredRoles.isEmpty() && !currentUser.hasAllRoles(requiredRoles)) { // logger.info("Authorization failed for authenticated user"); // throw new AuthenticationException("Sorry! No login for you."); // } SimpleAuthenticationInfo sa = new SimpleAuthenticationInfo(); sa.setCredentials(token.getCredentials()); SimplePrincipalCollection principals = new org.apache.shiro.subject.SimplePrincipalCollection(); principals.add(token.getPrincipal(), "bakerrealm"); sa.setPrincipals(principals); return sa; }
From source file:gr.upatras.ece.nam.baker.util.ShiroUTAuthorizingRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken at) throws AuthenticationException { logger.info("AuthenticationToken at=" + at.toString()); UsernamePasswordToken token = (UsernamePasswordToken) at; logger.info("tokengetUsername at=" + token.getUsername()); //logger.info("tokengetPassword at=" + String.valueOf(token.getPassword())); //logger.info("tokengetPrincipal at=" + token.getPrincipal()); BakerUser bu = bakerRepositoryRef.getUserByUsername(token.getUsername()); if (bu == null) { throw new AuthenticationException("Sorry! No login for you."); }//from ww w .j a va 2 s. c om String originalPass = bu.getPassword(); String suppliedPass = EncryptionUtil.hash(String.valueOf(token.getPassword())); logger.info("originalPass =" + originalPass); logger.info("suppliedPass =" + suppliedPass); if (originalPass.equals(suppliedPass)) { logger.info("======= USER is AUTHENTICATED OK ======="); } else { throw new AuthenticationException("Sorry! No login for you."); } // try { // currentUser.login(token); // } catch (AuthenticationException ex) { // logger.info(ex.getMessage(), ex); // throw new AuthenticationException("Sorry! No login for you."); // } // // Perform authorization check // if (!requiredRoles.isEmpty() && !currentUser.hasAllRoles(requiredRoles)) { // logger.info("Authorization failed for authenticated user"); // throw new AuthenticationException("Sorry! No login for you."); // } SimpleAuthenticationInfo sa = new SimpleAuthenticationInfo(); sa.setCredentials(token.getCredentials()); SimplePrincipalCollection principals = new org.apache.shiro.subject.SimplePrincipalCollection(); principals.add(token.getPrincipal(), "bakerrealm"); sa.setPrincipals(principals); return sa; }
From source file:org.apache.hadoop.gateway.shirorealm.KnoxPamRealmTest.java
License:Apache License
@Test public void testDoGetAuthenticationInfo() { KnoxPamRealm realm = new KnoxPamRealm(); realm.setService("sshd"); // pam settings being used: /etc/pam.d/sshd // use environment variables and skip the test if not set. String pamuser = System.getenv("PAMUSER"); String pampass = System.getenv("PAMPASS"); assumeTrue(pamuser != null);/*from ww w . jav a 2 s. c o m*/ assumeTrue(pampass != null); // mock shiro auth token UsernamePasswordToken authToken = createMock(UsernamePasswordToken.class); expect(authToken.getUsername()).andReturn(pamuser); expect(authToken.getPassword()).andReturn(pampass.toCharArray()); expect(authToken.getCredentials()).andReturn(pampass); replay(authToken); // login AuthenticationInfo authInfo = realm.doGetAuthenticationInfo(authToken); // verify success assertTrue(authInfo.getCredentials() != null); }
From source file:org.apache.zeppelin.realm.PamRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken userToken = (UsernamePasswordToken) token; UnixUser user;/*from w w w .j a v a 2 s . co m*/ try { user = (new PAM(this.getService())).authenticate(userToken.getUsername(), new String(userToken.getPassword())); } catch (PAMException e) { throw new AuthenticationException("Authentication failed for PAM.", e); } return new SimpleAuthenticationInfo(new UserPrincipal(user), userToken.getCredentials(), getName()); }
From source file:org.apache.zeppelin.realm.PamRealmTest.java
License:Apache License
@Test public void testDoGetAuthenticationInfo() { PamRealm realm = new PamRealm(); realm.setService("sshd"); String pamUser = System.getenv("PAM_USER"); String pamPass = System.getenv("PAM_PASS"); assumeTrue(pamUser != null);// w w w . jav a2 s . c o m assumeTrue(pamPass != null); // mock shiro auth token UsernamePasswordToken authToken = mock(UsernamePasswordToken.class); when(authToken.getUsername()).thenReturn(pamUser); when(authToken.getPassword()).thenReturn(pamPass.toCharArray()); when(authToken.getCredentials()).thenReturn(pamPass); AuthenticationInfo authInfo = realm.doGetAuthenticationInfo(authToken); assertTrue(authInfo.getCredentials() != null); }
From source file:org.i3xx.step.zero.security.impl.shiro.NaMyRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; return getAccount(upToken.getUsername(), upToken.getCredentials()); }