Skip to content
This repository was archived by the owner on Jun 29, 2018. It is now read-only.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cz.metacentrum.perun.oidc.client;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.activation.UnsupportedDataTypeException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Facility Manager from Perun system.
*
* @author Jiri Mauritz
*/
public class FacilitiesManager extends Manager {

private static FacilitiesManager manager;

private FacilitiesManager() {
}

public static synchronized FacilitiesManager getInstance() {
if (manager == null) {
manager = new FacilitiesManager();
}
return manager;
}

public List<PerunFacility> getFacilitiesByAttribute(String attributeName, String attributeValue) {
try {
Map<String, Object> params = new HashMap<>();
params.put("attributeName", attributeName);
params.put("attributeValue", attributeValue);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(get("getFacilitiesByAttribute", params), new TypeReference<List<PerunFacility>>(){});
} catch (UnsupportedDataTypeException e) {
return null;
} catch (IOException e) {
throw new IllegalStateException("IO Error while calling getFacilitiesByAttribute", e);
}
}

public List<PerunResource> getAssignedResources(int facilityId) {
try {
Map<String, Object> params = new HashMap<>();
params.put("facility", facilityId);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(get("getAssignedResources", params), new TypeReference<List<PerunResource>>(){});
} catch (UnsupportedDataTypeException e) {
return null;
} catch (IOException e) {
throw new IllegalStateException("IO Error while calling getAssignedResources", e);
}
}

@Override
protected String getManagerName() {
return "facilitiesManager";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.codec.binary.Base64;
import org.springframework.stereotype.Service;

import javax.activation.UnsupportedDataTypeException;
import javax.annotation.Resource;
import java.io.*;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -99,8 +100,8 @@ private String getString(HttpURLConnection c) throws IOException {
br.close();
String response = sb.toString();

throw new IOException("UnsupportedDataTypeException: Fail while reading error response from Perun. Response data: " + response);
}
throw new UnsupportedDataTypeException("Fail while reading error response from Perun. Response data: " + response);
}

} finally {
if (c != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package cz.metacentrum.perun.oidc.client;

/**
* Class represents facility from Perun system.
*
* @author Jiri Mauritz
*/
public class PerunFacility extends PerunBean {

private int id;
private String name;
private String description;

public PerunFacility() {
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@Override
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Override
public String toString() {
StringBuilder str = new StringBuilder();

return str.append(getClass().getSimpleName()).append( ":[id='").append(getId()).append("', name='").append(name).append(
"', description='").append(description).append("']").toString();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;

PerunFacility facility = (PerunFacility) o;

return id == facility.id;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + id;
return result;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package cz.metacentrum.perun.oidc.client;

/**
* Represents resource from Perun system.
*
* @author Jiri Mauritz
*/
public class PerunResource extends PerunBean {

private int id;
private int facilityId;
private int voId;
private String name;
private String description;

/**
* Constructs a new instance.
*/
public PerunResource() {
}

/**
* Gets the name for this instance.
*
* @return The name.
*/
public String getName() {
return this.name;
}

/**
* Sets the name for this instance.
*
* @param name The name.
*/
public void setName(String name) {
this.name = name;
}

/**
* Gets the description for this instance.
*
* @return The description.
*/
public String getDescription() {
return this.description;
}

/**
* Sets the description for this instance.
*
* @param description The description.
*/
public void setDescription(String description) {
this.description = description;
}

public int getFacilityId() {
return facilityId;
}

public void setFacilityId(int facilityId) {
this.facilityId = facilityId;
}

public int getVoId() {
return voId;
}

public void setVoId(int voId) {
this.voId = voId;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Override
public String toString() {
StringBuilder str = new StringBuilder();

return str.append(getClass().getSimpleName()).append(":[id='").append(getId()
).append("', voId='").append(voId
).append("', facilityId='").append(facilityId
).append("', name='").append(name
).append("', description='").append(description).append("']").toString();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;

PerunResource that = (PerunResource) o;

return id == that.id;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + id;
return result;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,12 @@ else if (extLogin == null && req.getAttribute("SSL_CLIENT_VERIFY") != null && ((

}

public static String getClientId(HttpServletRequest req) {
return req.getParameter("client_id");
}

public static boolean isWrapperType(Class<?> clazz) {
public static boolean isWrapperType(Class<?> clazz)
{
Set<Class<?>> ret = new HashSet<Class<?>>();
ret.add(Boolean.class);
ret.add(Character.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,75 @@
package cz.metacentrum.perun.oidc.client;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.activation.UnsupportedDataTypeException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Ondrej Velisek <ondrejvelisek@gmail.com>
*/
public class UsersManager extends Manager {

private static UsersManager manager;

private UsersManager() {
}

public static synchronized UsersManager getInstance() {
if (manager == null) {
manager = new UsersManager();
}
return manager;
}

public PerunUser getUserById(Integer id) {

try {
Map<String, Object> params = new HashMap<>();
params.put("id", id);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(get("getUserById", params), PerunUser.class);
} catch (IOException e) {
throw new IllegalStateException("IO Error while getting user from perun", e);
}

}

public PerunUser getUserByExtSourceNameAndExtLogin(String extSourceName, String extLogin) {

try {
Map<String, Object> params = new HashMap<>();
params.put("extSourceName", extSourceName);
params.put("extLogin", extLogin);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(get("getUserByExtSourceNameAndExtLogin", params), PerunUser.class);
} catch (IOException e) {
throw new IllegalStateException("IO Error while getting user from perun", e);
}

}

@Override
protected String getManagerName() {
return "usersManager";
}
private static UsersManager manager;

private UsersManager() {
}

public static synchronized UsersManager getInstance() {
if (manager == null) {
manager = new UsersManager();
}
return manager;
}

public PerunUser getUserById(Integer id) {

try {
Map<String, Object> params = new HashMap<>();
params.put("id", id);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(get("getUserById", params), PerunUser.class);
} catch (IOException e) {
throw new IllegalStateException("IO Error while getting user from perun", e);
}

}

public PerunUser getUserByExtSourceNameAndExtLogin(String extSourceName, String extLogin) {

try {
Map<String, Object> params = new HashMap<>();
params.put("extSourceName", extSourceName);
params.put("extLogin", extLogin);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(get("getUserByExtSourceNameAndExtLogin", params), PerunUser.class);
} catch (UnsupportedDataTypeException e) {
return null;
} catch (IOException e) {
throw new IllegalStateException("IO Error while getting user from perun", e);
}

}

public List<PerunResource> getAllowedResourcesIds(int userId) {
try {
Map<String, Object> params = new HashMap<>();
params.put("user", userId);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(get("getAllowedResources", params), new TypeReference<List<PerunResource>>(){});
} catch (UnsupportedDataTypeException e) {
return null;
} catch (IOException e) {
throw new IllegalStateException("IO Error while calling getAllowedResourcesIds", e);
}
}

@Override
protected String getManagerName() {
return "usersManager";
}
}
Loading