diff --git a/coffee-req/src/main/java/com/ohadr/dictionary/gae/GAEAuthenticationAccountRepositoryImpl.java b/coffee-req/src/main/java/com/ohadr/dictionary/gae/GAEAuthenticationAccountRepositoryImpl.java deleted file mode 100644 index 3115c11..0000000 --- a/coffee-req/src/main/java/com/ohadr/dictionary/gae/GAEAuthenticationAccountRepositoryImpl.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.ohadr.dictionary.gae; - -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.NoSuchElementException; - -import org.apache.log4j.Logger; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UsernameNotFoundException; - -import com.google.appengine.api.datastore.*; -import com.ohadr.auth_flows.core.AbstractAuthenticationAccountRepository; -import com.ohadr.auth_flows.interfaces.AuthenticationUser; -import com.ohadr.auth_flows.mocks.InMemoryAuthenticationUserImpl; - - -public class GAEAuthenticationAccountRepositoryImpl extends - AbstractAuthenticationAccountRepository -{ - private static final String PASSWORD_PROP_NAME = "password"; - private static final String LOGIN_ATTEMPTS_LEFT_PROP_NAME = "loginAttemptsLeft"; - private static final String ENABLED_PROP_NAME = "enabled"; - private static final String LAST_PSWD_CHANGE_DATE_PROP_NAME = "lastPasswordChangeDate"; - private static final String AUTHORITIES_PROP_NAME = "authorities"; - - private static final String USER_DB_KIND = "User"; - - - private static Logger log = Logger.getLogger(GAEAuthenticationAccountRepositoryImpl.class); - - private DatastoreService datastore; - - public GAEAuthenticationAccountRepositoryImpl() - { - datastore = DatastoreServiceFactory.getDatastoreService(); - } - - @Override - public void setDisabled(String email) - { - setEnabledFlag(email, false); - } - - @Override - public void setEnabled(String email) - { - setEnabledFlag(email, true); - } - - @Override - public void setPassword(String username, String newEncodedPassword) - { - changePassword(username, newEncodedPassword); - } - - @Override - public void createUser(UserDetails user) - { - AuthenticationUser authUser = (AuthenticationUser) user; - - Entity dbUser = new Entity(USER_DB_KIND, user.getUsername()); //the username is the key - - dbUser.setProperty("username", user.getUsername()); - dbUser.setProperty(PASSWORD_PROP_NAME, user.getPassword()); - dbUser.setProperty(ENABLED_PROP_NAME, user.isEnabled()); - dbUser.setProperty(LOGIN_ATTEMPTS_LEFT_PROP_NAME, authUser.getLoginAttemptsLeft()); - dbUser.setProperty(LAST_PSWD_CHANGE_DATE_PROP_NAME, new Date( System.currentTimeMillis()) ); - dbUser.setProperty(AUTHORITIES_PROP_NAME, "ROLE_USER" ); - - datastore.put(dbUser); - } - - @Override - public void updateUser(UserDetails user) { - // TODO Auto-generated method stub - - } - - @Override - public void deleteUser(String username) - { - Key userKey = KeyFactory.createKey(USER_DB_KIND, username); - datastore.delete(userKey); - - } - - - @Override - public boolean userExists(String username) { - // TODO Auto-generated method stub - return false; - } - - - @Override - public UserDetails loadUserByUsername(String username) - throws UsernameNotFoundException - { - Key userKey = KeyFactory.createKey(USER_DB_KIND, username); - Entity entity; - try - { - entity = datastore.get(userKey); - log.debug("got entity of " + username + ": " + entity); - } - catch (EntityNotFoundException e) - { - log.error("entity of " + username + " not found"); - throw new UsernameNotFoundException(username, e); - } - - boolean isEnabled = false; - Object isEnabledObj = entity.getProperty(ENABLED_PROP_NAME); - if( null != isEnabledObj ) - { - isEnabled = (Boolean)isEnabledObj; - } - int loginAttemptsLeft = 0; - Object loginAttemptsLeftObj = entity.getProperty(LOGIN_ATTEMPTS_LEFT_PROP_NAME); - if( null != loginAttemptsLeftObj ) - { - //"hack" convert Object to int: - loginAttemptsLeft = new Integer(loginAttemptsLeftObj.toString()); - } - - String roleName = (String)entity.getProperty(AUTHORITIES_PROP_NAME); - GrantedAuthority userAuth = new SimpleGrantedAuthority(roleName); - Collection authSet = new HashSet(); - authSet.add(userAuth); - - return new InMemoryAuthenticationUserImpl( - username, - (String)entity.getProperty(PASSWORD_PROP_NAME), - isEnabled, - loginAttemptsLeft, - (Date)entity.getProperty(LAST_PSWD_CHANGE_DATE_PROP_NAME), - authSet); - - } - - - @Override - protected void setEnabledFlag(String username, boolean flag) throws NoSuchElementException - { - Key userKey = KeyFactory.createKey(USER_DB_KIND, username); - Entity entity; - try - { - entity = datastore.get(userKey); - log.debug("got entity of " + username + ": " + entity); - } - catch (EntityNotFoundException e) - { - log.error("entity of " + username + " not found"); - throw new NoSuchElementException(e.getMessage()); - } - - entity.setProperty(ENABLED_PROP_NAME, flag); - datastore.put(entity); - } - - @Override - protected void updateLoginAttemptsCounter(String username, int attempts) throws NoSuchElementException - { -// FlowsUtil.logStackTrace( log ); - - Key userKey = KeyFactory.createKey(USER_DB_KIND, username); - Entity entity; - try - { - entity = datastore.get(userKey); - log.debug("got entity of " + username + ": " + entity); - } - catch (EntityNotFoundException e) - { - log.error("entity of " + username + " not found"); - throw new NoSuchElementException(e.getMessage()); - } - - entity.setProperty(LOGIN_ATTEMPTS_LEFT_PROP_NAME, attempts); - datastore.put(entity); - } - - @Override - public void changePassword(String username, String newEncodedPassword) - { - Key userKey = KeyFactory.createKey(USER_DB_KIND, username); - Entity entity; - try - { - entity = datastore.get(userKey); - log.debug("got entity of " + username + ": " + entity); - } - catch (EntityNotFoundException e) - { - log.error("entity of " + username + " not found"); - throw new NoSuchElementException(e.getMessage()); - } - - entity.setProperty(LAST_PSWD_CHANGE_DATE_PROP_NAME, new Date( System.currentTimeMillis())); - entity.setProperty(PASSWORD_PROP_NAME, newEncodedPassword); - datastore.put(entity); - } - -} diff --git a/coffee-req/src/main/java/com/ohadr/dictionary/gae/GAEMailSenderImpl.java b/coffee-req/src/main/java/com/ohadr/dictionary/gae/GAEMailSenderImpl.java deleted file mode 100644 index 093d569..0000000 --- a/coffee-req/src/main/java/com/ohadr/dictionary/gae/GAEMailSenderImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.ohadr.dictionary.gae; - - -import java.io.UnsupportedEncodingException; -import java.util.Properties; - -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.PasswordAuthentication; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; - -import org.apache.log4j.Logger; -import org.springframework.mail.MailException; -import org.springframework.mail.MailSender; -import org.springframework.mail.SimpleMailMessage; - - -/** - * this implementation uses pure javax.mail to send mail. - * Deprecated because newer version uses Spring @link:JavaMailSenderImpl - * @author OhadR - * - */ - -public class GAEMailSenderImpl implements MailSender -{ - private static Logger log = Logger.getLogger(GAEMailSenderImpl.class); - - private Session session; - - - public GAEMailSenderImpl() - { - final String username = "bmc.incubator@gmail.com"; - final String password = "theheatison"; - - Properties props = new Properties(); - props.put("mail.smtp.starttls.enable", "true"); - props.put("mail.smtp.auth", "true"); - props.put("mail.smtp.host", "smtp.gmail.com"); - props.put("mail.smtp.starttls.enable", "true"); - props.put("mail.smtp.port", "587"); - // props.put("mail.smtp.port", "465"); - -// session = Session.getDefaultInstance(props, null); - session = Session.getInstance(props, - new javax.mail.Authenticator() { - protected PasswordAuthentication getPasswordAuthentication() - { - return new PasswordAuthentication(username, password); - } - }); - - } - - - @Override - public void send(SimpleMailMessage msg) throws MailException - { - log.info(msg.toString()); - - try - { - Message message = new MimeMessage(session); - message.setFrom(new InternetAddress("ohadr.developer@gmail.com", "ohadr.com Admin")); - message.addRecipient(Message.RecipientType.TO, - new InternetAddress( msg.getTo()[0] )); //Spring's getTo returns String[] - -/* message.setRecipients(Message.RecipientType.TO, - InternetAddress.parse( msg.getTo().toString() )); - -*/ message.setSubject( msg.getSubject() ); - message.setText( msg.getText() ); - - Transport.send(message); - } - catch (MessagingException e) - { - log.error("MessagingException: ", e); - throw new RuntimeException(e); - } - catch (UnsupportedEncodingException e) - { - log.error("UnsupportedEncodingException: ", e); - e.printStackTrace(); - } - } - - @Override - public void send(SimpleMailMessage[] simpleMessages) throws MailException - { - // TODO Auto-generated method stub - - } - -} \ No newline at end of file diff --git a/coffee-req/src/main/webapp/WEB-INF/spring-servlet.xml b/coffee-req/src/main/webapp/WEB-INF/spring-servlet.xml index 6cde559..23e9e07 100644 --- a/coffee-req/src/main/webapp/WEB-INF/spring-servlet.xml +++ b/coffee-req/src/main/webapp/WEB-INF/spring-servlet.xml @@ -67,7 +67,7 @@ + class="com.ohadr.auth_flows.core.gae.gae.GAEAuthenticationAccountRepositoryImpl" /> + \ No newline at end of file diff --git a/coffee-req/src/main/webapp/index.html b/coffee-req/src/main/webapp/secure/index.html similarity index 100% rename from coffee-req/src/main/webapp/index.html rename to coffee-req/src/main/webapp/secure/index.html diff --git a/coffee-req/src/main/webapp/nespresso.js b/coffee-req/src/main/webapp/secure/nespresso.js similarity index 100% rename from coffee-req/src/main/webapp/nespresso.js rename to coffee-req/src/main/webapp/secure/nespresso.js diff --git a/coffee-req/src/main/webapp/style.css b/coffee-req/src/main/webapp/secure/style.css similarity index 100% rename from coffee-req/src/main/webapp/style.css rename to coffee-req/src/main/webapp/secure/style.css