KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > security > auth > Base64CallbackHandler


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.security.auth;
14
15 import org.apache.commons.codec.binary.Base64;
16 import org.apache.commons.lang.StringUtils;
17
18
19 /**
20  * Base 64 callback handler supporting Basic authentication
21  * @author Sameer Charles $Id: Base64CallbackHandler.java 6341 2006-09-12 09:18:27Z philipp $
22  */

23 public class Base64CallbackHandler extends CredentialsCallbackHandler {
24
25     /**
26      * default
27      */

28     public Base64CallbackHandler() {
29         // do not instanciate with this constructor
30
}
31
32     /**
33      * @param credentials Base64 encoded string
34      */

35     public Base64CallbackHandler(String JavaDoc credentials) {
36         credentials = getDecodedCredentials(credentials.substring(6).trim());
37         this.name = StringUtils.substringBefore(credentials, ":");
38         this.pswd = StringUtils.substringAfter(credentials, ":").toCharArray();
39     }
40
41     /**
42      * @param credentials to be decoded
43      * @return String decoded credentials <b>name:password </b>
44      */

45     private static String JavaDoc getDecodedCredentials(String JavaDoc credentials) {
46         return (new String JavaDoc(Base64.decodeBase64(credentials.getBytes())));
47     }
48
49 }
50
Popular Tags