List of usage examples for org.springframework.security.core Authentication getCredentials
Object getCredentials();
From source file:eu.cloud4soa.frontend.commons.server.security.C4sAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = (String) authentication.getPrincipal(); String password = (String) authentication.getCredentials(); UserInstance userInstance;//from ww w . jav a 2 s. c o m try { userInstance = userService.authenticateUser(username, password); } catch (Throwable e) { if (e.getMessage().contains("wrong username") || e.getMessage().contains("No user instance")) throw new BadCredentialsException("Bad username or password."); String msg = "An error occurred while authenticating user '" + Strings.defaultString(username) + "': " + e.getMessage(); logger.debug(msg, e); throw new BadCredentialsException(msg, e); } Authentication auth = new C4sUserAuthentication(loadUserByUsername(username).getAuthorities(), authentication, userInstance.getUriId()); auth.setAuthenticated(true); return auth; }
From source file:ph.fingra.statisticsweb.service.MemberServiceImpl.java
public void update(Member member) { if (!StringUtils.isEmpty(member.getPassword())) { member.setPassword(passwordEncoder.encode(member.getPassword())); }/*from w w w .ja va 2 s .c o m*/ memberDao.update(member); UserDetails newPrincipal = new FingraphUser(get(member.getMemberid())); Authentication currentAuth = SecurityContextHolder.getContext().getAuthentication(); UsernamePasswordAuthenticationToken newAuth = new UsernamePasswordAuthenticationToken(newPrincipal, currentAuth.getCredentials(), newPrincipal.getAuthorities()); newAuth.setDetails(currentAuth.getDetails()); SecurityContextHolder.getContext().setAuthentication(newAuth); }
From source file:fr.gael.dhus.spring.security.authentication.DefaultAuthenticationProvider.java
@Override @Transactional(propagation = Propagation.REQUIRED) public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = (String) authentication.getPrincipal(); String password = (String) authentication.getCredentials(); String ip = "unknown"; if (authentication.getDetails() instanceof WebAuthenticationDetails) { ip = ((WebAuthenticationDetails) authentication.getDetails()).getRemoteAddress(); }/*from w w w. j a va2 s .c o m*/ LOGGER.info("Connection attempted by '" + authentication.getName() + "' from " + ip); arwDao.loginStart(username); User user = userService.getUserNoCheck(username); if (user == null || user.isDeleted()) { throw new BadCredentialsException(errorMessage); } PasswordEncryption encryption = user.getPasswordEncryption(); if (!encryption.equals(PasswordEncryption.NONE)) { MessageDigest md; try { md = MessageDigest.getInstance(encryption.getAlgorithmKey()); password = new String(Hex.encode(md.digest(password.getBytes("UTF-8")))); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { arwDao.loginEnd(user, false); throw new BadCredentialsException("Authentication process failed", e); } } if (!user.getPassword().equals(password)) { LOGGER.warn(new Message(MessageType.USER, "Connection refused for '" + username + "' from " + ip + " : error in login/password combination")); arwDao.loginEnd(user, false); throw new BadCredentialsException(errorMessage); } for (AccessRestriction restriction : user.getRestrictions()) { LOGGER.warn("Connection refused for '" + username + "' from " + ip + " : account is locked (" + restriction.getBlockingReason() + ")"); arwDao.loginEnd(user, false); throw new LockedException(restriction.getBlockingReason()); } LOGGER.info("Connection success for '" + username + "' from " + ip); arwDao.loginEnd(user, true); return new ValidityAuthentication(user, user.getAuthorities()); }
From source file:oauth2.authentication.UserAuthenticationProvider.java
protected Authentication createSuccessAuthentication(Object principal, Authentication authentication, Collection<GrantedAuthority> authorities) { UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(principal, authentication.getCredentials(), authorities); result.setDetails(authentication.getDetails()); return result; }
From source file:ru.ttk.baloo.rest.security.oauth.CustomUserAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { LOG.info("Going to process authentication: " + authentication); if (authentication != null && authentication.getPrincipal() != null && authentication.getCredentials() != null) { LOG.info("authentication principal: " + authentication.getPrincipal()); LOG.info("authentication credentials: " + authentication.getCredentials()); /*/* w w w. j av a 2 s. co m*/ * authentication.getPrincipal() <=> userName * authentication.getCredentials() <=> password */ IRemoteUser remoteUser = remoteServiceFindUser.findUser(authentication.getPrincipal().toString(), authentication.getCredentials().toString()); if (remoteUser != null) { List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(); CustomUserPasswordAuthenticationToken auth = new CustomUserPasswordAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), grantedAuthorities); return auth; } } throw new BadCredentialsException(WRONG_USER_CREDENTIALS); }
From source file:com.sitewhere.security.SitewhereAuthenticationProvider.java
public Authentication authenticate(Authentication input) throws AuthenticationException { try {/*from www .jav a 2 s . co m*/ if (input instanceof UsernamePasswordAuthenticationToken) { String username = (String) input.getPrincipal(); String password = (String) input.getCredentials(); IUser user = SiteWhereServer.getInstance().getUserManagement().authenticate(username, password); List<IGrantedAuthority> auths = SiteWhereServer.getInstance().getUserManagement() .getGrantedAuthorities(user.getUsername()); SitewhereUserDetails details = new SitewhereUserDetails(user, auths); return new SitewhereAuthentication(details, password); } else if (input instanceof SitewhereAuthentication) { return input; } else { throw new AuthenticationServiceException("Unknown authentication: " + input.getClass().getName()); } } catch (SiteWhereException e) { throw new BadCredentialsException("Unable to authenticate.", e); } }
From source file:org.socialsignin.springsocial.security.userdetails.SpringSocialSecurityUserDetailsService.java
/** * Uses a <code>SignUpService</code> implementation to check if a local user account for this username is available * and if so, bases the user's authentication on the set of connections the user currently has to * 3rd party providers. Allows provider-specific roles to be set for each user - uses a <code>UsersConnectionRepository</code> * to obtain list of connections the user has and a <code>SpringSocialSecurityAuthenticationFactory</code> * to obtain an authentication based on those connections. * //www .j a va 2 s . c o m */ @Override public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException { ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(userName); SpringSocialProfile springSocialProfile = signUpService.getUserProfile(userName); List<Connection<?>> allConnections = getConnections(connectionRepository, userName); if (allConnections.size() > 0) { Authentication authentication = authenticationFactory.createAuthenticationForAllConnections(userName, springSocialProfile.getPassword(), allConnections); return new User(userName, authentication.getCredentials().toString(), true, true, true, true, authentication.getAuthorities()); } else { throw new UsernameNotFoundException(userName); } }
From source file:de.uni_koeln.spinfo.maalr.login.LoginManager.java
public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (authentication.isAuthenticated()) { return authentication; }//ww w. ja v a 2s . c om return login(authentication.getName(), (String) authentication.getCredentials()); }
From source file:com.kcs.core.actions.LoginAction.java
@Override public String success() throws Exception { try {/*from w w w .j a v a 2 s . co m*/ Authentication auth = SecurityContextHolder.getContext().getAuthentication(); logger.debug("auth : " + auth); setCurrentUser(authorizeService.authenticateUser(auth.getName(), convertPasswordBase64(auth.getCredentials().toString()))); if (null != getCurrentUser()) { logger.debug("login success!"); getCurrentUser().setMenuList(authorizeService.authorizeMenuUser(getCurrentUser().getEmpNo())); session.put(DmsConstant.SESSION.LOGIN_KEY, getCurrentUser()); session.put(DmsConstant.SESSION.LOGIN_ID, getCurrentUser().getEmpNo()); } else { logger.debug("login fail!"); return FAIL; } // UserData cur = new UserData(); // cur.setEmpNo("0000"); // setCurrentUser(cur); // session.put(DmsConstant.SESSION.LOGIN_KEY, getCurrentUser()); } catch (Exception e) { e.printStackTrace(); throw e; } return SUCCESS; }