Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ezhov-da/039eb544cb61876c6e10485317be2829 to your computer and use it in GitHub Desktop.
Save ezhov-da/039eb544cb61876c6e10485317be2829 to your computer and use it in GitHub Desktop.
базовая авторизация
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