Created
May 21, 2017 08:49
-
-
Save fermopili/f56c53cbec868e807a8fd9d6c4768be5 to your computer and use it in GitHub Desktop.
com.javarush.task.task37.task3709 ________ Security Proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task37.task3709.connectors; | |
public interface Connector { | |
void connect(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task37.task3709.connectors; | |
import com.javarush.task.task37.task3709.security.SecurityChecker; | |
import com.javarush.task.task37.task3709.security.SecurityCheckerImpl; | |
/** | |
* Created by Administrator on 21.05.2017. | |
*/ | |
public class SecurityProxyConnector implements Connector | |
{ | |
private String resourceString; | |
SimpleConnector simpleConnector; | |
SecurityChecker securityChecker; | |
public SecurityProxyConnector(String resourceString) | |
{ | |
this.resourceString = resourceString; | |
this.simpleConnector = new SimpleConnector ( resourceString ); | |
this.securityChecker = new SecurityCheckerImpl ( ); | |
} | |
@Override | |
public void connect() | |
{ | |
if( securityChecker. performSecurityCheck()) | |
simpleConnector.connect (); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task37.task3709.connectors; | |
public class SimpleConnector implements Connector | |
{ | |
private String resourceString; | |
public SimpleConnector(String resourceString) | |
{ | |
this.resourceString = resourceString; | |
} | |
@Override | |
public void connect() | |
{ | |
System.out.println ( "Successfully connected to " + resourceString ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task37.task3709.security; | |
public interface SecurityChecker { | |
boolean performSecurityCheck(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task37.task3709.security; | |
public class SecurityCheckerImpl implements SecurityChecker { | |
@Override | |
public boolean performSecurityCheck() { | |
System.out.println("SECURITY OK!"); | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task37.task3709; | |
import com.javarush.task.task37.task3709.connectors.Connector; | |
import com.javarush.task.task37.task3709.connectors.SecurityProxyConnector; | |
import com.javarush.task.task37.task3709.connectors.SimpleConnector; | |
/* | |
Security Proxy | |
*/ | |
public class Solution { | |
public static void main(String[] args) { | |
Connector securityProxyConnector = new SecurityProxyConnector("google.com"); | |
Connector simpleConnector = new SimpleConnector("javarush.ru"); | |
System.out.println("Connecting with SimpleConnector..."); | |
simpleConnector.connect(); | |
System.out.println("----------------------------------------------------"); | |
System.out.println("Connecting with SecurityProxyConnector..."); | |
securityProxyConnector.connect(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
taskKey="com.javarush.task.task37.task3709" | |
Security Proxy | |
Необходимо создать класс SecurityProxyConnector в пакете connectors, который будет производить проверку | |
безопасности перед подключением. В случае, если проверка не пройдена, соединение не должно быть установлено. | |
Для клиента (в данном случае класс Solution) использование SecurityProxyConnector ничем не должно отличаться | |
от использования класса SimpleConnector. | |
P.S. Тебе понадобятся поля типов SecurityChecker и SimpleConnector в классе SecurityProxyConnector. | |
Требования: | |
1. В классе SecurityProxyConnector должно быть создано поле типа SimpleConnector. | |
2. В классе SecurityProxyConnector должно быть создано поле типа SecurityChecker. | |
3. Конструктор класса SecurityProxyConnector должен принимать один параметр типа String и инициализировать поле типа SimpleConnector. | |
4. Метод connect класса SecurityProxyConnector должен выполнять проверку безопасности с помощью вызова метода performSecurityCheck у объекта типа SecurityChecker. | |
5. Если проверка безопасности была пройдена, должно быть выполнено подключение. | |
6. Если проверка безопасности не была пройдена, подключение не должно быть выполнено. | |
7. Класс SecurityProxyConnector должен поддерживать интерфейс Connector. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment