Last active
March 10, 2019 12:15
-
-
Save ezhov-da/039eb544cb61876c6e10485317be2829 to your computer and use it in GitHub Desktop.
базовая авторизация
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
def errorAuth(text) { | |
response.setHeader("WWW-Authenticate", "Basic") | |
response.setStatus(401) | |
println text | |
} | |
//Авторизация в сервлете ) | |
def auth(Closure callbackBad, Closure callbackGood, String checkUsername, String checkPassword) { | |
def logger = Logger.getLogger("random word") | |
String authHeader = request.getHeader("Authorization") | |
logger.info("authHeader: " + authHeader) | |
if (authHeader == null) { | |
callbackBad() | |
} else { | |
def afterClear = authHeader.replaceAll("Basic ", "") | |
logger.info("afterClear: " + afterClear) | |
def lpass = new String(afterClear.decodeBase64()) | |
logger.info("lpass: " + lpass) | |
def arr = lpass.split(":") | |
def login = arr[0] | |
def pass = arr[1] | |
logger.info("login: [" + login + "] pass:[" + pass + "]") | |
if (!checkUsername.equals(login) && !checkPassword.equals(pass)) { | |
callbackBad() | |
return | |
} else { | |
callbackGood() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment