Skip to content

Commit

Permalink
Issue #774
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel.stastny committed Nov 1, 2020
1 parent b1063b2 commit f3477c3
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain filt
}
}

public void basicAuth(FilterChain arg2, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, NoSuchAlgorithmException, IOException, ServletException {
public void basicAuth(FilterChain arg2, HttpServletRequest request, HttpServletResponse response) throws NoSuchAlgorithmException, IOException, ServletException {
String header = request.getHeader("Authorization");
if (header!=null && header.trim().startsWith("Basic")) {
String uname = header.trim().substring("Basic".length()).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

public interface AuthenticatedUsers {

public String calculateUserName(HttpServletRequest request);
String calculateUserName(HttpServletRequest request);

public HttpServletRequest updateRequest(HttpServletRequest req);
HttpServletRequest updateRequest(HttpServletRequest req);

public String storeUserPropertiesToSession(HttpServletRequest req, String userName) throws Exception;
String storeUserPropertiesToSession(HttpServletRequest req, String userName) throws Exception;

public void disconnectUser(String userName);
void disconnectUser(String userName);

public String getUserPassword(String userName);
String getUserPassword(String userName);
}

Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public boolean match(Value val, HttpServletRequest request) {
String foreignVal = val.getValue(request);
if (thisVal != null && foreignVal != null) {
return thisVal.equals(foreignVal);
} else if (thisVal == null && foreignVal == null) {
return true;
} else return false;
} else return thisVal == null && foreignVal == null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public boolean match(Value val, HttpServletRequest request) {
String foreignVal = val.getValue(request);
if (thisVal != null && foreignVal != null) {
return thisVal.equals(foreignVal);
} else if (thisVal == null && foreignVal == null) {
return true;
} else return false;
} else return thisVal == null && foreignVal == null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

public interface ShibbolethContext {

public void associateFirstName(String firstName);
void associateFirstName(String firstName);

public void associateLastName(String lastName);
void associateLastName(String lastName);

public void associateSessionAttribute(String key, String value);
void associateSessionAttribute(String key, String value);

public void associateRole(String rname);
void associateRole(String rname);

public boolean isRoleAssociated(String rname);
boolean isRoleAssociated(String rname);

public HttpServletRequest getHttpServletRequest();
HttpServletRequest getHttpServletRequest();

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public interface Value {
* @param request HTTP Request
* @return
*/
public String getValue(HttpServletRequest request);
String getValue(HttpServletRequest request);

/**
* Returns true if given value is equals to this one
* @param val Other value
* @param request HTTP request
* @return
*/
public boolean match(Value val, HttpServletRequest request);
boolean match(Value val, HttpServletRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public String calculateUserName(HttpServletRequest request) {
}

@Override
public String updateExistingUser(String userName,OpenIdUserWrapper wrapper) throws Exception {
public String updateExistingUser(String userName,OpenIdUserWrapper wrapper) {
String password = GeneratePasswordUtils.generatePswd();
JSONArray users = RemoteUsersUtils.getUser(userName);
JSONObject jsonObject = users.getJSONObject(0);
Expand All @@ -51,22 +51,22 @@ public String updateExistingUser(String userName,OpenIdUserWrapper wrapper) thro
return password;
}

public boolean checkIfUserExists(String userName) throws Exception {
public boolean checkIfUserExists(String userName) {
JSONArray users = RemoteUsersUtils.getUser(userName);
return users.length() > 0 ;

}

@Override
protected String createNewUser(String user, OpenIdUserWrapper w) throws Exception {
protected String createNewUser(String user, OpenIdUserWrapper w) {
String password = GeneratePasswordUtils.generatePswd();
JSONObject json = w.toJSON(password);
RemoteUsersUtils.createUser( json);
return password;
}

@Override
protected OpenIdUserWrapper createUserWrapper(HttpServletRequest req, String userName) throws Exception {
protected OpenIdUserWrapper createUserWrapper(HttpServletRequest req, String userName) {
Profile profile = OpenIDFlag.flagFromRequest(req).profile(req);
return new OpenIdUserWrapper(userName,profile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public OpenIDFlag next(HttpServletRequest req) throws Exception {
},
LOGGED {
@Override
public OpenIDFlag next(HttpServletRequest req) throws Exception {
public OpenIDFlag next(HttpServletRequest req) {
req.getSession(true).setAttribute(STATE_KEY, STORED.name());
return OpenIDFlag.STORED;

Expand All @@ -72,20 +72,20 @@ public OpenIDFlag next(HttpServletRequest req) throws Exception {

STORED {
@Override
public OpenIDFlag next(HttpServletRequest req) throws Exception {
public OpenIDFlag next(HttpServletRequest req) {
req.getSession(true).setAttribute(STATE_KEY, STORED.name());
return OpenIDFlag.STORED;
}
};

public SocialAuthManager authManager(HttpServletRequest req) throws Exception {
public SocialAuthManager authManager(HttpServletRequest req) {
Object attribute = req.getSession(true).getAttribute(MANAGER_KEY);
return (SocialAuthManager) (attribute != null ? attribute : null);
return (SocialAuthManager) (attribute);
}

public Profile profile(HttpServletRequest req) throws Exception {
public Profile profile(HttpServletRequest req) {
Object attribute = req.getSession(true).getAttribute(PROFILE_KEY);
return (Profile) (attribute != null ? attribute : null);
return (Profile) (attribute);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import javax.ws.rs.core.MediaType;

import org.apache.commons.configuration.ConfigurationException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -23,7 +22,7 @@
public class RemoteUsersUtils {

public static JSONArray getUser(String userName)
throws ConfigurationException, JSONException {
throws JSONException {
Client c = Client.create();
String url = KConfiguration.getInstance().getConfiguration()
.getString("api.point")
Expand Down Expand Up @@ -80,7 +79,7 @@ public static void newPasswordUser( String userId,
}
}

public static String createUser(JSONObject jsonObject) throws Exception {
public static String createUser(JSONObject jsonObject) {
String url = KConfiguration.getInstance().getConfiguration()
.getString("api.point") + "/admin/users";
Client c = Client.create();
Expand All @@ -96,7 +95,7 @@ public static String createUser(JSONObject jsonObject) throws Exception {
return t;
}

public static String deleteUser(String usr) throws Exception {
public static String deleteUser(String usr) {
String url = KConfiguration.getInstance().getConfiguration()
.getString("api.point") + "/admin/users/"+usr;
Client c = Client.create();
Expand All @@ -111,19 +110,5 @@ public static String deleteUser(String usr) throws Exception {
return t;
}

public static void main(String[] args) throws JSONException, Exception {
String str = "_third_party_googleplus_114387057939312155006";
JSONArray user = getUser(str);
System.out.println(user);
System.out.println(user.length());


// String str = "{\"lname\":\"_tthird_party_googleplus_114387057939312155006\",\"firstname\":\"Pavel\",\"password\":\".dlPGvYJT4iW\",\"surname\":\"Stastny\"}";
//
// String createUser = createUser(new JSONObject(str));
// System.out.println(createUser);

}



}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void callExpectation(HttpServletRequest req, Enumeration<String> k
EasyMock.expect(req.getHeader(k)).andAnswer(new IAnswer<String>() {

@Override
public String answer() throws Throwable {
public String answer() {
return table.get(k);
}
}).anyTimes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void testFirstAndLastName() throws TokenStreamException, RecognitionExcep
HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(req.getHeaderNames()).andAnswer(new IAnswer<Enumeration>() {
@Override
public Enumeration answer() throws Throwable {
public Enumeration answer() {
return RequestSupportForTests.getLoggedShibLowerCaseTable().keys();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void testShibRules2() throws TokenStreamException, RecognitionException {
testShibRules(shibRules2);
}

private void testShibRules(String rules) throws RecognitionException, TokenStreamException {
private void testShibRules(String rules) throws TokenStreamException, RecognitionException {
HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(req.getHeaderNames()).andAnswer(new IAnswer<Enumeration>() {
@Override
public Enumeration answer() throws Throwable {
public Enumeration answer() {
return RequestSupportForTests.getLoggedShibLowerCaseTable().keys();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testIsUnderShibbolethSession_NotLogged() {
EasyMock.expect(req.getHeaderNames()).andAnswer(new IAnswer<Enumeration>() {

@Override
public Enumeration answer() throws Throwable {
public Enumeration answer() {
return RequestSupportForTests.getNotLoggedShibTable().keys();
}
});
Expand All @@ -62,7 +62,7 @@ public void testIsUnderShibbolethSession_Logged() {
EasyMock.expect(req.getHeaderNames()).andAnswer(new IAnswer<Enumeration>() {

@Override
public Enumeration answer() throws Throwable {
public Enumeration answer() {
return RequestSupportForTests.getLoggedShibTable().keys();
}
});
Expand All @@ -81,7 +81,7 @@ public void testIsUnderShibbolethSession2_Logged() {
EasyMock.expect(req.getHeaderNames()).andAnswer(new IAnswer<Enumeration>() {

@Override
public Enumeration answer() throws Throwable {
public Enumeration answer() {
return RequestSupportForTests.getLoggedShibLowerCaseTable().keys();
}
});
Expand All @@ -99,7 +99,7 @@ public void testShibbolethSessionId() {
EasyMock.expect(req.getHeaderNames()).andAnswer(new IAnswer<Enumeration>() {

@Override
public Enumeration answer() throws Throwable {
public Enumeration answer() {
return RequestSupportForTests.getLoggedShibTable().keys();
}
});
Expand All @@ -118,21 +118,21 @@ public void testValidateSessionId() {
HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(req.getHeaderNames()).andAnswer(new IAnswer<Enumeration>() {
@Override
public Enumeration answer() throws Throwable {
public Enumeration answer() {
return RequestSupportForTests.getLoggedShibTable().keys();
}
}).anyTimes();

EasyMock.expect(req.getSession(true)).andAnswer(new IAnswer<HttpSession>() {
@Override
public HttpSession answer() throws Throwable {
public HttpSession answer() {
return session;
}
}).anyTimes();

EasyMock.expect(session.getAttribute("Shib-Session-ID")).andAnswer(new IAnswer<String>() {
@Override
public String answer() throws Throwable {
public String answer() {
return "_8b58b975229f61df5d9389b8f2d0d8d8";
}
}).anyTimes();
Expand All @@ -149,21 +149,21 @@ public void testValidateSessionId2() {
HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(req.getHeaderNames()).andAnswer(new IAnswer<Enumeration>() {
@Override
public Enumeration answer() throws Throwable {
public Enumeration answer() {
return RequestSupportForTests.getLoggedShibTable().keys();
}
}).anyTimes();

EasyMock.expect(req.getSession(true)).andAnswer(new IAnswer<HttpSession>() {
@Override
public HttpSession answer() throws Throwable {
public HttpSession answer() {
return session;
}
}).anyTimes();

EasyMock.expect(session.getAttribute("Shib-Session-ID")).andAnswer(new IAnswer<String>() {
@Override
public String answer() throws Throwable {
public String answer() {
return "_abe8b975229f61df5d9389b8f2d0d8d8";
}
}).anyTimes();
Expand All @@ -180,21 +180,21 @@ public void testValidateSessionId3() {
HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(req.getHeaderNames()).andAnswer(new IAnswer<Enumeration>() {
@Override
public Enumeration answer() throws Throwable {
public Enumeration answer() {
return RequestSupportForTests.getLoggedShibLowerCaseTable().keys();
}
}).anyTimes();

EasyMock.expect(req.getSession(true)).andAnswer(new IAnswer<HttpSession>() {
@Override
public HttpSession answer() throws Throwable {
public HttpSession answer() {
return session;
}
}).anyTimes();

EasyMock.expect(session.getAttribute("Shib-Session-ID")).andAnswer(new IAnswer<String>() {
@Override
public String answer() throws Throwable {
public String answer() {
return "_abe8b975229f61df5d9389b8f2d0d8d8";
}
}).anyTimes();
Expand Down
Loading

0 comments on commit f3477c3

Please sign in to comment.