tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/SSLCertificateService.java
private ResponseEntity<String> addSudoPermissionToCertificateOwner(SSLCertificateRequest sslCertificateRequest,
			UserDetails userDetails, CertResponse enrollResponse, boolean isPoliciesCreated,
			boolean sslMetaDataCreationStatus,String token,String operation) {
		CertificateUser certificateUser = new CertificateUser();
		ResponseEntity<String> addUserresponse;
		ResponseEntity<String> addReadPolicyResponse;
		certificateUser.setUsername(sslCertificateRequest.getCertOwnerNtid());
		certificateUser.setAccess(TVaultConstants.SUDO_POLICY);
		certificateUser.setCertificateName(sslCertificateRequest.getCertificateName());
		certificateUser.setCertType(sslCertificateRequest.getCertType());
		
		if(operation!=null && operation.equalsIgnoreCase(SSLCertificateConstants.ONBOARD)) {
			 addUserresponse = addUserToCertificateOnboard(certificateUser, userDetails, true);
		}
		
		else {
		 addUserresponse = addUserToCertificate(certificateUser, userDetails, true);
		}
		
		if(HttpStatus.OK.equals(addUserresponse.getStatusCode())){
			certificateUser.setAccess(TVaultConstants.WRITE_POLICY);
			if(operation!=null && operation.equalsIgnoreCase(SSLCertificateConstants.ONBOARD)) {
				addReadPolicyResponse = addUserToCertificateOnboard(certificateUser, userDetails, true);
			}else {
			 addReadPolicyResponse = addUserToCertificate(certificateUser, userDetails, true);
			}
			if(HttpStatus.OK.equals(addReadPolicyResponse.getStatusCode())){
			    if(sslCertificateRequest.getCertType().equals(SSLCertificateConstants.INTERNAL)) {
                    enrollResponse.setResponse(SSLCertificateConstants.SSL_CERT_SUCCESS);
                } else {
                    if(isMockingEnabled(sslCertificateRequest.getCertType())){
                        enrollResponse.setResponse(SSLCertificateConstants.SSL_CERT_SUCCESS);
                    } else {
                        enrollResponse.setResponse(SSLCertificateConstants.SSL_EXT_CERT_SUCCESS);
                    }
                }
				enrollResponse.setSuccess(Boolean.TRUE);
				log.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
						.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
						.put(LogMessage.ACTION, String.format("Metadata or Policies created for SSL certificate [%s] - metaDataStatus [%s] - policyStatus [%s]", sslCertificateRequest.getCertificateName(), sslMetaDataCreationStatus, isPoliciesCreated))
						.build()));
                //Send email only in case of creation
                if (operation != null && operation.equalsIgnoreCase("create")) {
                    sendCreationEmail(sslCertificateRequest, userDetails, token);

                    log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
                            .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
                            .put(LogMessage.ACTION, String.format("CERTIFICATE [%s] - CREATED SUCCESSFULLY - BY [%s] - " +
                                            "ON- [%s] AND TYPE [%s]",
                                    sslCertificateRequest.getCertificateName(), sslCertificateRequest.getCertOwnerEmailId(),
                                    LocalDateTime.now(), sslCertificateRequest.getCertType())).build()));
                }


			    return ResponseEntity.status(HttpStatus.OK).body(MESSAGES+enrollResponse.getResponse()+"\"]}");
			}else {
				enrollResponse.setResponse(SSLCertificateConstants.SSL_OWNER_PERMISSION_EXCEPTION);
	            enrollResponse.setSuccess(Boolean.FALSE);
				log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
			            put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
			            put(LogMessage.ACTION, "addUserToCertificate").
			            put(LogMessage.MESSAGE, "Adding sudo permission to certificate owner failed").
			            put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
			            build()));
				return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ERRORS+enrollResponse.getResponse()+"\"]}");
			}
		}else {
			enrollResponse.setResponse(SSLCertificateConstants.SSL_OWNER_PERMISSION_EXCEPTION);
            enrollResponse.setSuccess(Boolean.FALSE);
			log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
		            put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
		            put(LogMessage.ACTION, "addUserToCertificate").
		            put(LogMessage.MESSAGE, "Adding sudo permission to certificate owner failed").
		            put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
		            build()));
			return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ERRORS+enrollResponse.getResponse()+"\"]}");
		}
	}
/**
	 * Method to provide sudo permission to certificate owner
	 * 
	 * @param sslCertificateRequest
	 * @param userDetails
	 * @param token
	 * @param enrollResponse
	 * @param isPoliciesCreated
	 * @param sslMetaDataCreationStatus
	 * @return
	 */
Method to provide sudo permission to certificate owner


Method to provide sudo permission to certificate owner
private ResponseEntity<String> addSudoPermissionToCertificateOwner(SSLCertificateRequest sslCertificateRequest,
			UserDetails userDetails, CertResponse enrollResponse, boolean isPoliciesCreated,
			boolean sslMetaDataCreationStatus,String token,String operation) {
		CertificateUser certificateUser = new CertificateUser();
		ResponseEntity<String> addUserresponse;
		ResponseEntity<String> addReadPolicyResponse;
		certificateUser.setUsername(sslCertificateRequest.getCertOwnerNtid());
		certificateUser.setAccess(TVaultConstants.SUDO_POLICY);
		certificateUser.setCertificateName(sslCertificateRequest.getCertificateName());
		certificateUser.setCertType(sslCertificateRequest.getCertType());
		if(operation!=null && operation.equalsIgnoreCase(SSLCertificateConstants.ONBOARD)) {
			 addUserresponse = addUserToCertificateOnboard(certificateUser, userDetails, true);
		}
		else {
		 addUserresponse = addUserToCertificate(certificateUser, userDetails, true);
		}
		if(HttpStatus.OK.equals(addUserresponse.getStatusCode())){
			certificateUser.setAccess(TVaultConstants.WRITE_POLICY);
			if(operation!=null && operation.equalsIgnoreCase(SSLCertificateConstants.ONBOARD)) {
				addReadPolicyResponse = addUserToCertificateOnboard(certificateUser, userDetails, true);
			}else {
			 addReadPolicyResponse = addUserToCertificate(certificateUser, userDetails, true);
			}
			if(HttpStatus.OK.equals(addReadPolicyResponse.getStatusCode())){
			    if(sslCertificateRequest.getCertType().equals(SSLCertificateConstants.INTERNAL)) {
                    enrollResponse.setResponse(SSLCertificateConstants.SSL_CERT_SUCCESS);
                } else {
                    if(isMockingEnabled(sslCertificateRequest.getCertType())){
                        enrollResponse.setResponse(SSLCertificateConstants.SSL_CERT_SUCCESS);
                    } else {
                        enrollResponse.setResponse(SSLCertificateConstants.SSL_EXT_CERT_SUCCESS);
                    }
                }
				enrollResponse.setSuccess(Boolean.TRUE);
				log.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
						.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
						.put(LogMessage.ACTION, String.format("Metadata or Policies created for SSL certificate [%s] - metaDataStatus [%s] - policyStatus [%s]", sslCertificateRequest.getCertificateName(), sslMetaDataCreationStatus, isPoliciesCreated))
						.build()));
                if (operation != null && operation.equalsIgnoreCase("create")) {
                    sendCreationEmail(sslCertificateRequest, userDetails, token);
                    log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
                            .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
                            .put(LogMessage.ACTION, String.format("CERTIFICATE [%s] - CREATED SUCCESSFULLY - BY [%s] - " +
                                            "ON- [%s] AND TYPE [%s]",
                                    sslCertificateRequest.getCertificateName(), sslCertificateRequest.getCertOwnerEmailId(),
                                    LocalDateTime.now(), sslCertificateRequest.getCertType())).build()));
                }
			    return ResponseEntity.status(HttpStatus.OK).body(MESSAGES+enrollResponse.getResponse()+"\"]}");
			}else {
				enrollResponse.setResponse(SSLCertificateConstants.SSL_OWNER_PERMISSION_EXCEPTION);
	            enrollResponse.setSuccess(Boolean.FALSE);
				log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
			            put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
			            put(LogMessage.ACTION, "addUserToCertificate").
			            put(LogMessage.MESSAGE, "Adding sudo permission to certificate owner failed").
			            put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
			            build()));
				return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ERRORS+enrollResponse.getResponse()+"\"]}");
			}
		}else {
			enrollResponse.setResponse(SSLCertificateConstants.SSL_OWNER_PERMISSION_EXCEPTION);
            enrollResponse.setSuccess(Boolean.FALSE);
			log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
		            put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
		            put(LogMessage.ACTION, "addUserToCertificate").
		            put(LogMessage.MESSAGE, "Adding sudo permission to certificate owner failed").
		            put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
		            build()));
			return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ERRORS+enrollResponse.getResponse()+"\"]}");
		}
	}
private ResponseEntity < String > addSudoPermissionToCertificateOwner ( SSLCertificateRequest sslCertificateRequest , UserDetails userDetails , CertResponse enrollResponse , boolean isPoliciesCreated , boolean sslMetaDataCreationStatus , String token , String operation ) { CertificateUser certificateUser = new CertificateUser ( ) ; ResponseEntity < String > addUserresponse ; ResponseEntity < String > addReadPolicyResponse ; certificateUser . setUsername ( sslCertificateRequest . getCertOwnerNtid ( ) ) ; certificateUser . setAccess ( TVaultConstants . SUDO_POLICY ) ; certificateUser . setCertificateName ( sslCertificateRequest . getCertificateName ( ) ) ; certificateUser . setCertType ( sslCertificateRequest . getCertType ( ) ) ; if ( operation != null && operation . equalsIgnoreCase ( SSLCertificateConstants . ONBOARD ) ) { addUserresponse = addUserToCertificateOnboard ( certificateUser , userDetails , true ) ; } else { addUserresponse = addUserToCertificate ( certificateUser , userDetails , true ) ; } if ( HttpStatus . OK . equals ( addUserresponse . getStatusCode ( ) ) ) { certificateUser . setAccess ( TVaultConstants . WRITE_POLICY ) ; if ( operation != null && operation . equalsIgnoreCase ( SSLCertificateConstants . ONBOARD ) ) { addReadPolicyResponse = addUserToCertificateOnboard ( certificateUser , userDetails , true ) ; } else { addReadPolicyResponse = addUserToCertificate ( certificateUser , userDetails , true ) ; } if ( HttpStatus . OK . equals ( addReadPolicyResponse . getStatusCode ( ) ) ) { if ( sslCertificateRequest . getCertType ( ) . equals ( SSLCertificateConstants . INTERNAL ) ) { enrollResponse . setResponse ( SSLCertificateConstants . SSL_CERT_SUCCESS ) ; } else { if ( isMockingEnabled ( sslCertificateRequest . getCertType ( ) ) ) { enrollResponse . setResponse ( SSLCertificateConstants . SSL_CERT_SUCCESS ) ; } else { enrollResponse . setResponse ( SSLCertificateConstants . SSL_EXT_CERT_SUCCESS ) ; } } enrollResponse . setSuccess ( Boolean . TRUE ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , String . format ( "Metadata or Policies created for SSL certificate [%s] - metaDataStatus [%s] - policyStatus [%s]" , sslCertificateRequest . getCertificateName ( ) , sslMetaDataCreationStatus , isPoliciesCreated ) ) . build ( ) ) ) ; if ( operation != null && operation . equalsIgnoreCase ( "create" ) ) { sendCreationEmail ( sslCertificateRequest , userDetails , token ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , String . format ( "CERTIFICATE [%s] - CREATED SUCCESSFULLY - BY [%s] - " + "ON- [%s] AND TYPE [%s]" , sslCertificateRequest . getCertificateName ( ) , sslCertificateRequest . getCertOwnerEmailId ( ) , LocalDateTime . now ( ) , sslCertificateRequest . getCertType ( ) ) ) . build ( ) ) ) ; } return ResponseEntity . status ( HttpStatus . OK ) . body ( MESSAGES + enrollResponse . getResponse ( ) + "\"]}" ) ; } else { enrollResponse . setResponse ( SSLCertificateConstants . SSL_OWNER_PERMISSION_EXCEPTION ) ; enrollResponse . setSuccess ( Boolean . FALSE ) ; log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "addUserToCertificate" ) . put ( LogMessage . MESSAGE , "Adding sudo permission to certificate owner failed" ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return ResponseEntity . status ( HttpStatus . INTERNAL_SERVER_ERROR ) . body ( ERRORS + enrollResponse . getResponse ( ) + "\"]}" ) ; } } else { enrollResponse . setResponse ( SSLCertificateConstants . SSL_OWNER_PERMISSION_EXCEPTION ) ; enrollResponse . setSuccess ( Boolean . FALSE ) ; log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "addUserToCertificate" ) . put ( LogMessage . MESSAGE , "Adding sudo permission to certificate owner failed" ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return ResponseEntity . status ( HttpStatus . INTERNAL_SERVER_ERROR ) . body ( ERRORS + enrollResponse . getResponse ( ) + "\"]}" ) ; } }
Method to provide sudo permission to certificate owner
Method to provide sudo permission to certificate owner
//Send email only in case of creation