Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting the Authorization class to allow for Bearer Auth #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 47 additions & 54 deletions src/main/java/org/kamranzafar/jddl/Authentication.java
Original file line number Diff line number Diff line change
@@ -1,61 +1,54 @@
/**
* Copyright 2012 Kamran Zafar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2012 Kamran Zafar
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kamranzafar.jddl;

import org.kamranzafar.jddl.util.Base64;

public class Authentication {
public static enum AuthType {
BASIC
}

private AuthType authType = AuthType.BASIC;
private String username;
private String password;

public Authentication() {
}

public Authentication(String username, String password) {
super();
this.username = username;
this.password = password;
}

public AuthType getAuthType() {
return authType;
}

public void setAuthType(AuthType authType) {
this.authType = authType;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public enum AuthType {
BASIC, BEARER
}

private AuthType authType = AuthType.BASIC;

private String token;

private Authentication() {
}

public static Authentication withBasicAuthentication(final String username, final String password) {
Authentication auth = new Authentication();
auth.authType = AuthType.BASIC;
auth.token = String.format("Basic %s", Base64.encodeBytes(String.format("%s:%s", username, password).getBytes()));

return auth;
}

public static Authentication withBearerAuthentication(final String token) {
Authentication auth = new Authentication();
auth.authType = AuthType.BEARER;
auth.token = String.format("Bearer %s", token);

return auth;
}

public String getRequestHeader() {
return this.token;
}

}
Loading