25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 14 ■ Using Dynamic Languages<br />

}<br />

public String getPassword() {<br />

return password;<br />

}<br />

public void setPassword(String password) {<br />

this.password = password;<br />

}<br />

public boolean isAuthorized(String email, String pass){<br />

if(username.equals(email) && password.equals(pass))<br />

return true;<br />

return false;<br />

}<br />

Listing 14-2 shows the LoginService implementation of the Login interface. It shows the isAuthorized method<br />

implementation, and it only verifies if the e-mail and password are equal to the ones set in the LoginService class.<br />

For this chapter you are going to create a new class, a SecurityServiceFacade that will use the Login<br />

implementation. It will help you interact with the dynamic languages. Listing 14-3 shows the<br />

SecurityServiceFacade class.<br />

Listing 14-3. SecurityServiceFacade.java<br />

package com.apress.isf.spring.service;<br />

import org.slf4j.Logger;<br />

import org.slf4j.LoggerFactory;<br />

import com.apress.isf.java.service.Login;<br />

public class SecurityServiceFacade {<br />

private Logger log = LoggerFactory.getLogger(SecurityServiceFacade.class);<br />

private Login login;<br />

public void setLogin(Login login) {<br />

this.login = login;<br />

}<br />

}<br />

public boolean areCredentialsValid(String email, String pass){<br />

log.debug("Validating Credentials > email:" + email + ", pass:" + pass);<br />

return this.login.isAuthorized(email, pass);<br />

}<br />

As you can see, Listing 14-3 has the Login interface ready to be injected by the <strong>Spring</strong> container.<br />

196

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!