Skip to content

Commit

Permalink
Fixed some Sonar warnings on VOMS AA code
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaceccanti committed Nov 24, 2021
1 parent 7d7ef32 commit 0088566
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ public void setUseGridTrustAnchors(boolean useGridTrustAnchors) {

private boolean hideTokens = true;

public IamClientApplicationProperties() {
}

public String getIssuer() { return issuer; }

public void setIssuer(String issuer) { this.issuer = issuer; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,21 +457,7 @@ private void validateClaims(HttpSession session, JWT idToken, JWTClaimsSet idCla
}
}

// @Override
// protected void handleError(HttpServletRequest request,
// HttpServletResponse response) throws IOException {
//
// String error = request.getParameter("error");
// String errorDescription = request.getParameter("error_description");
// String errorURI = request.getParameter("error_uri");
//
// RequestDispatcher dispatcher = request.getRequestDispatcher("/error");
// try{
// dispatcher.forward(request, response);
// }catch(ServletException e){
// throw new RuntimeException("Foward failed");
// }
// }

public ClientHttpRequestFactory getHttpRequestFactory() {

return httpRequestFactory;
Expand All @@ -482,11 +468,13 @@ public void setHttpRequestFactory(ClientHttpRequestFactory httpRequestFactory) {
this.httpRequestFactory = httpRequestFactory;
}

@Override
public int getTimeSkewAllowance() {

return timeSkewAllowance;
}

@Override
public void setTimeSkewAllowance(int timeSkewAllowance) {

this.timeSkewAllowance = timeSkewAllowance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ private VOMSWarningMessage(VOMSWarning warning, String vo) {
this.message = null;
}

private VOMSWarningMessage(VOMSWarning warning, String vo, String message) {

this.warning = warning;
this.vo = vo;
this.message = message;
}

/**
* @return the vo
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public class ThreadLocalACGenerator implements ACGenerator {

@Override
public void configure(PEMCredential aaCredential) {
acGenerator = ThreadLocal.withInitial(() -> {
return new VOMSACGenerator(aaCredential);
});
acGenerator = ThreadLocal.withInitial(() -> new VOMSACGenerator(aaCredential));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ private VOMSResponseBuilderImpl() {
docBuilder = factory.newDocumentBuilder();

} catch (ParserConfigurationException e) {
log.error("Error configuring DOM document builder: " + e.getMessage(), e);
throw new VOMSException(e);
}

Expand All @@ -77,10 +76,7 @@ protected String xmlDocAsString(Document doc) {
try {
transformer = transformerFactory.newTransformer();
} catch (TransformerConfigurationException e) {

log.error("Error creating XML transformer:" + e.getMessage(), e);
throw new VOMSException(e);

}

StringWriter writer = new StringWriter();
Expand All @@ -94,11 +90,6 @@ protected String xmlDocAsString(Document doc) {
writer.flush();

} catch (TransformerException e) {

log.error("Error caught serializing XML {}", e.getMessage());
if (log.isDebugEnabled())
log.error(e.getMessage(), e);

throw new VOMSException("Error caugh serializing XML", e);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@
public class IamVOMSAttributeResolver implements AttributeResolver {
public static final Logger LOG = LoggerFactory.getLogger(IamVOMSAttributeResolver.class);

private final IamLabel VOMS_ROLE_LABEL;
private final IamLabel vomsRoleLabel;
private final FQANEncoding fqanEncoding;

public IamVOMSAttributeResolver(VomsProperties properties, FQANEncoding fqanEncoding) {
VOMS_ROLE_LABEL = IamLabel.builder().name(properties.getAa().getOptionalGroupLabel()).build();
vomsRoleLabel = IamLabel.builder().name(properties.getAa().getOptionalGroupLabel()).build();
this.fqanEncoding = fqanEncoding;
}

protected boolean iamGroupIsVomsGroup(VOMSRequestContext context, IamGroup g) {
final String voName = context.getVOName();
final boolean nameMatches = g.getName().equals(voName) || g.getName().startsWith(voName + "/");

return nameMatches && !g.getLabels().contains(VOMS_ROLE_LABEL);
return nameMatches && !g.getLabels().contains(vomsRoleLabel);
}

protected void noSuchUserError(VOMSRequestContext context) {
Expand All @@ -71,14 +71,14 @@ protected void noSuchAttributeError(VOMSRequestContext context, VOMSFqan fqan) {


protected boolean iamGroupIsVomsRole(IamGroup g) {
return g.getLabels().contains(VOMS_ROLE_LABEL);
return g.getLabels().contains(vomsRoleLabel);
}

protected boolean groupMatchesFqan(IamGroup g, VOMSFqan fqan) {
final String name = fqan.asIamGroupName();
final boolean nameMatches = name.equals(g.getName());
if (fqan.isRoleFqan()) {
return nameMatches && g.getLabels().contains(VOMS_ROLE_LABEL);
return nameMatches && g.getLabels().contains(vomsRoleLabel);
} else {
return nameMatches;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ protected void checkMembershipValidity(VOMSRequestContext context) {
failResponse(context,
VOMSErrorMessage.suspendedUser(r.getHolderSubject(), r.getHolderIssuer()));
context.setHandled(true);
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

public class VOMSGAImpl implements VOMSGenericAttribute {

public VOMSGAImpl() {

}

@Override
public String getName() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import it.infn.mw.iam.authn.x509.IamX509AuthenticationCredential;
Expand Down Expand Up @@ -80,8 +79,8 @@ protected VOMSRequestContext initVomsRequestContext(IamX509AuthenticationCredent
return context;
}

@RequestMapping(value = "/generate-ac", method = RequestMethod.GET,
produces = "text/xml; charset=utf-8")

@GetMapping(value = "/generate-ac", produces = "text/xml; charset=utf-8")
@PreAuthorize("hasRole('USER') and hasRole('X509')")
public String generateAC(@Validated VOMSRequestDTO request,
@RequestHeader(name = "User-Agent", required = false) String userAgent,
Expand Down
10 changes: 7 additions & 3 deletions iam-voms-aa/src/main/java/it/infn/mw/voms/config/VomsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ InactiveAccountAuthenticationHander noOpInactiveAccountHandler() {
@Bean
PEMCredential aaCredential(VomsProperties properties)
throws KeyStoreException, CertificateException, IOException {
return new PEMCredential(new FileInputStream(properties.getTls().getPrivateKeyPath()),
new FileInputStream(properties.getTls().getCertificatePath()), (char[]) null);

try (FileInputStream privateKey = new FileInputStream(properties.getTls().getPrivateKeyPath());
FileInputStream certificate =
new FileInputStream(properties.getTls().getCertificatePath())) {
return new PEMCredential(privateKey, certificate, (char[]) null);
}
}

@Bean
Expand Down Expand Up @@ -123,7 +127,7 @@ Clock clock() {

@Bean
FQANEncoding fqanEncoding(VomsProperties properties) {
if (properties.getAa().getUseLegacyFqanEncoding()) {
if (Boolean.TRUE.equals(properties.getAa().getUseLegacyFqanEncoding())) {
return new LegacyFQANEncoding();
} else {
return new NullFQANEncoding();
Expand Down

0 comments on commit 0088566

Please sign in to comment.