Skip to content

Commit

Permalink
fix: implement missing methods (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuisathaverat authored Oct 27, 2024
1 parent 29ce887 commit c291fa0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
13 changes: 7 additions & 6 deletions src/main/java/org/jenkinsci/plugins/saml/SamlFileResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.NonNull;

import org.apache.commons.lang.NotImplementedException;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Class to manage the metadata files.
*/
Expand Down Expand Up @@ -82,14 +83,14 @@ public boolean isOpen() {

@NonNull
@Override
public URL getURL() {
throw new NotImplementedException();
public URL getURL() throws IOException {
return resource.getURL();
}

@NonNull
@Override
public URI getURI() {
throw new NotImplementedException();
public URI getURI() throws IOException {
return resource.getURI();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand All @@ -51,10 +53,12 @@ class SamlFileResourceCache implements WritableResource {
private final static Map<String,String> cache = new HashMap<>();

public SamlFileResourceCache(@NonNull String fileName) {
LOG.log(Level.FINER, "Creating Resource cache: %s", fileName );
this.fileName = fileName;
}

public SamlFileResourceCache(@NonNull String fileName, @NonNull String data) {
LOG.log(Level.FINER, "Creating Resource cache from data: %s", fileName );
this.fileName = fileName;
try {
save(fileName, data);
Expand All @@ -81,13 +85,13 @@ public boolean isOpen() {
}

@Override
public URL getURL() {
throw new NotImplementedException();
public URL getURL() throws MalformedURLException {
return getURI().toURL();
}

@Override
public URI getURI() {
throw new NotImplementedException();
return getFile().toURI();
}

@Override
Expand All @@ -102,26 +106,27 @@ public String getDescription() {

@Override
public InputStream getInputStream() throws IOException {
LOG.log(Level.FINER, "Get cache inputStream : %s", fileName );
if (cache.containsKey(fileName)){
return IOUtils.toInputStream(cache.get(fileName),"UTF-8");
} else {
return FileUtils.openInputStream(new File(fileName));
return FileUtils.openInputStream(getFile());
}
}

@Override
public File getFile() {
throw new NotImplementedException();
return new File(fileName);
}

@Override
public long contentLength() {
return new File(fileName).length();
return getFile().length();
}

@Override
public long lastModified() {
return new File(fileName).lastModified();
return getFile().lastModified();
}

@Override
Expand All @@ -136,6 +141,7 @@ public boolean isWritable() {

@Override
public OutputStream getOutputStream() throws IOException {
LOG.log(Level.FINER, "Creating cache outputStream: %s", fileName );
return new ByteArrayOutputStream(){
@Override
public void close() throws IOException {
Expand All @@ -153,6 +159,7 @@ private boolean isNew(String fileName, String data){

private void save(@NonNull String fileName, @NonNull String data) throws IOException {
if(isNew(fileName, data)) {
LOG.log(Level.FINER, "Save resource to disk : %s", fileName );
Files.write(new File(fileName).toPath(), data.getBytes("UTF-8"));
cache.put(fileName, data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.nio.file.Files;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.NotImplementedException;
import org.pac4j.core.exception.TechnicalException;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Class to manage the metadata files.
*/
Expand Down Expand Up @@ -73,14 +75,14 @@ public boolean isOpen() {

@NonNull
@Override
public URL getURL() {
throw new NotImplementedException();
public URL getURL() throws MalformedURLException {
return getURI().toURL();
}

@NonNull
@Override
public URI getURI() {
throw new NotImplementedException();
return getFile().toURI();
}

@Override
Expand Down

0 comments on commit c291fa0

Please sign in to comment.